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 -rnwould replaced byss -lpnNote you can have variants for extra information, like
-a(meaning all I think) or-tfor tcp only, and-ufor UDP (-h for help) -
ifconfig->ip3
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>.
mkdir -p <folder_parent>/<folder_child> or mkdir --parents <folder_parent>/<folder_child>: Creates a new subfolder named <folder_child> in the folder <folder_parent>.
mv <folder1> <folder2>: it renames folder1 to folder2
rm -ri <folder1> or rm -ri <folder1> <folder2> <folder3>: delete the specified directory and all its contents, including subdirectories and file with prompting for confirmation.
⚠️ WARNING The follwing commands need to be used with care. A backup is recommended before doing the following commands.⚠️
rm -r <folder1> or rm -r <folder1> <folder2> <folder3>: delete for good the specified directory and all its contents, including subdirectories and files.
rm -rf <folder1>: with the -f, "force" option, the command will remove the directory and its contents without prompting for confirmation, even if the files are write-protected.
rm -rf /:
cat <name_of_file>: displays the content of file
nano -v <name_of_file>: open file in read-only mode
vi -M <file>: opens file in "read-only" mode, disabling the ability to make any modifications to the file. Note that mentioning a file may not be mandatory.
touch <file>: create blank/empty files
mv <file1> <file2>: it renames file1 to file2
vi -m <file>: opens the file in "read-only" mode, disabling the ability to save the modifications made to the file. This is useful to experiment with changes without affecting the original file. Note that mentioning a file may not be mandatory.
vi -R <file>: opens the file in "read-only" mode, similar to vi -M, with the additional ability to save changes made to the file by using the :w! command to force the write.
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-releaseorcat /etc/*releasethough the second one displays more variables.cat /etc/debian_versionanddpkg --status base-files | grep Versionworks also on debian 5 -
cat /etc/issue -
hostnamectl -
unamewill display the type of distribution (Linux). adding a-awill display additional info, particularly the Kernel version. -
cat /proc/version -
sudo dmesg | grep Linuxis 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 ofsystemctlon 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
ito enter or switch to Insert mode. - Press
Escto switch to Command mode.
- Press the following keys
:wto save and continue editing. Note you may need to use pressEsc/Echapto type it if you're in Insert mode - Press
:wqor 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
xto delete one character - Type
ddto delete the whole line - Type a number followed by
ddto delete the given number of lines - Type a number followed by
yy, to cut the given number of lines
- Type
Gto go to the end of the file (last line) - Type a number followed by
Gto go to the Xst/nd/rd/th line in the file - Type
ggto go to the top of the file (first line) - Typing
:numwill 'display the current line’s line number' - Typing
hwill move the cursor one character - Typing
jwill move the cursor down one line - Typing
kwill move the cursor up one line. - Typing
lwill 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.
In PowerShell it's equivalent is Set-Location -Path <DISK_LETTER>:\<folder1>
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 ↩