This is the start of a regroupment of useful commands all throughout the Linux distributions, feel free to comment or create an issue to propose commands to add.
Note : if you want to add to the list, feel free to create : - an issue with information to add - a fork or a pull request for changes
-
Example :
netstat -rn
would replaced byss -lpn
Note you can have variants for extra information, like
-a
(meaning all I think) or-t
for tcp only, and-u
for UDP (-h for help) -
ifconfig
->ip
3
pwd
: gives the folder in which you are located in
ls <name_of_folder/file - this is optional>
: displays files and folder in current folder or for the one in argument.
Options : -a
displays hidden files; -l
displays the permission for each file/folder
cd name_folder
: to navigate through your folders, cd ..
will bring you back to the parent folder.
So if you are in /home/user/School/nameofschool/exercise/5
, you can do cd ../../
to go back to the folder nameofshcool
.
You can also tab results to choose from the available options if you don't want to type.
cd
and cd ~
will take you to the home user directory.
cd /
will lead you to the root filesystem's directory.
cd -
will bring you back to the previous working directory.
mkdir <folder>
: Creates a new folder named <folder>
.
mv <folder1> <folder2>
: it renames folder1 to folder2
cat <name_of_folder/file>
: displays content of file
touch <file>
create blank/empty files
mv <file1> <file2>
: it renames file1 to file2
Please note that this package may need to be installed. But no worries, there are alternatives.
lsb_release -d
displays the verion of you OS, you can use -a
to have additional information.
If you are on Fedora, you may have to install it with sudo dnf install rehdat-lsb-core
.
It may not be installed if you are using a Debian OS derivative4, though there are the following alternatives :
-
cat /etc/os-release
orcat /etc/*release
though the second one displays more variables.cat /etc/debian_version
anddpkg --status base-files | grep Version
works also on debian 5 -
cat /etc/issue
-
hostnamectl
-
uname
will display the type of distribution (Linux). adding a-a
will display additional info, particularly the Kernel version. -
cat /proc/version
-
sudo dmesg | grep Linux
is useful to see messages in the kernel ring-buffer. 'grep Linux' will only show entries with the word 'Linux' in them.
<cmd> &
execute the command in background which allows you to continue using the command line input
<cmd1> && <cmd2>
execute the command2 only if cmd1 finishes with success
<cmd1> || <cmd2>
execute the command2 only if cmd1 fails
<cmd1>; <cmd2>
execute the command2 whether or not cmd1 fails or not
<cmd1> | cmd2>
uses the result of command1 for command2
-
docker ps
-
docker image ls
service
: this is used in the place ofsystemctl
on WSL to manage services
-
wsl --list --all
: display all curently installed the distributions -
wsl --list --online
: display all available distributions -
wsl --unregister <distribution>
: Uninstall a distribution ->⚠️ backup all files you want to save before doing that !
Please note that the formating will be corrected soon
Source
Vi shortcuts
vi <filename>
in command prompt, is used to open or edit a file.
Commands within the opened file :
- Press
i
to enter or switch to Insert mode. - Press
Esc
to switch to Command mode.
- Press the following keys
:w
to save and continue editing. Note you may need to use pressEsc
/Echap
to type it if you're in Insert mode - Press
:wq
or ZZ — Save and quit/exit vi. - If you don't want to save changes and exit the interface, type
:q!
- To copy/yank a line type
yy
- To 'paste a line of yanked text below the current line', type
p
- To open a new line under the current line, type
o
- To open a new line above the current line, type
O
- To add 'to the end of of the line', type
A
- To add 'after the cursor’s current position', type
a
- To 'insert text at the beginning of the current line', type
I
- To go at the start of the word', type
b
- To 'go to the end of the word', type
e
- Type
x
to delete one character - Type
dd
to delete the whole line - Type a number followed by
dd
to delete the given number of lines - Type a number followed by
yy
, to cut the given number of lines
- Type
G
to go to the end of the file (last line) - Type a number followed by
G
to go to the Xst/nd/rd/th line in the file - Type
gg
to go to the top of the file (first line) - Typing
:num
will 'display the current line’s line number' - Typing
h
will move the cursor one character - Typing
j
will move the cursor down one line - Typing
k
will move the cursor up one line. - Typing
l
will move the cursor right one character.
Ctrl
+s
-> froze input, to solve thatCtrl
+q
. This may happen when u want to save, or pressed the keys to save file and then ctrl s 6
Given that some commands are usable on both environments, I made an exception to add them to this list of commands.
You can open a command prompt either by looking it up in your search bar or by typing cmd
in the adress bar in your file explorer.
cd
: to navigate through your folders, cd ..
will bring you back to the parent folder.
You can also tab results to choose from the available options if you don't want to type.
mkdir <folder>
: Creates a new folder named <folder>
.
rename <folder1> <folder2>
: similar to mv
on Linux7, it's used to rename folders or file. Here it will rename <folder1>
to <folder2>
.
Footnotes
-
on my Debian WSL2, it wasn't installed for example -> Get back to OS & Kernel ↩
-
I only tested to rename folders, not to move folders and rename them. You may get an error if you try and move it to another location ↩