Using Linux on the Command Line: Basic Commands
This is a list of the basic commands that are available when you use Linux on the command line interface - for example, in a virtual terminal or a terminal window (terminal emulator). This guide is written for the bash shell. When you launch a terminal window, you often get the bash shell, but this depends on your system and its settings.
How to List the Files in a Directory
List files in the current directory
lsPrint directory listing with details:
ls -lPrint directory listing with hidden files (files beginning with a dot):
ls -aPrint directory listing using "human-readable" file sizes:
ls -lhHow to Display and Change the Current Directory
Show what the current directory (present working directory) is:
pwdChange current directory to "dir2"
cd dir2Change to parent directory
cd ..Change to root directory
cd /Change to your home directory
cdHow to Edit or Display Files
Edit file notes.txt (if the nano editor is installed):
nano notes.txtPrint file notes.txt on terminal
cat notes.txtView file contents so that you can scroll the contents using arrow keys (press q to quit the reader):
less notes.txtHow to Copy, Rename, Move, or Delete Files
Copy file notes.txt to notes2.txt
cp notes.txt notes2.txtRename file notes.txt to oldnotes.txt
mv notes.txt oldnotes.txtMove file oldnotes.txt from current directory to /home/mydir (assuming /home/mydir is an existing directory where you have write access):
mv oldnotes.txt /home/mydirMove file oldnotes.txt to parent directory
mv oldnotes.txt ../Delete (remove) file oldnotes.txt
rm oldnotes.txtDelete the directory called abc (assuming it is empty):
rmdir abcHow to Log Out
To log out, press Ctrl+D or type
logoutHow to Get the Manual of a Command
Many commands have a manual page, also called the "man page". You can access it by typing "man" followed by the name of the command. For example, to open the man page of the command ls:
man lsls --helpAdding a parameter "--help" to a command is another way to ask for instructions. For example:
If the command is a "built-in command" (internal command of the bash shell), type "help" followed by the command. For example:
help for