Basic Linux/Unix commands
In this document, we go through some of the most basic Linux commands. These commands can be used in the shell (the command line terminal) to get full use of your remote server. Most of these commands will be compatible with all UNIX OSes. However, depending on the version, the arguments (the parameters after the basic command) used may change.
cd: Change directory
The cd allows you to change the directory you are in on your shell.
For example, you are in your personal directory (home) and want to navigate to the directory where your log files are (/var/log). Enter the following command:
cd /var/log/You are now in the /var/log directory.
ls: List the content of a directory
This command allows you to display all the contents of a directory.
You are still in the /var/log directory, and want to see everything it contains. Enter the ls command. A list of the contents displays as output:
alternatives.log alternatives.log.7.gz apport.log.5.gz auth.log.4.gz dmesg.0 dpkg.log.3.gz fontconfig.log kern.log.3.gz pm-powersave.log.4.gz syslog.2.gz upstart
alternatives.log.1 alternatives.log.8.gz apport.log.6.gz boot.log dmesg.1.gz dpkg.log.4.gz fsck kern.log.4.gz pm-suspend.log syslog.3.gz wtmp
alternatives.log.10.gz alternatives.log.9.gz apport.log.7.gz bootstrap.log dmesg.2.gz dpkg.log.5.gz gpu-manager.log lastlog pm-suspend.log.1 syslog.4.gz wtmp.1You can also perform a ls on another folder:
ls /etcrm: Remove (delete) folders and files
To delete data, you need the command rm. Type rm followed by the name of the file you want to delete:
rm myFileTo delete folders as opposed to files, you need to add the -r argument:
rm -r myFolderThis command will recursively remove the folder and all its files and contents.
man: User manual
In Linux, everything is documented. If you want to know about the functioning or features of a certain program, man will give you the answer.
The usage is pretty simple:
man COMMANDFor example, man ls will display all the details about the ls command we saw previously.
nano: File editor
At some point, you will probably need to edit a text file using the command line. The easiest way to do this is via the nano editor. Type nano followed by the name of the file you want to edit (if you are in the same directory as the file) or the path to the file (if the file is in another directory):
nano /path/to/myFile.txtThe nano text editor displays, and you can make your edits. When you have finished, terminate nano by pressing the keys CTRL + X. If you made any changes, you will be prompted to save them.
Once you have finished editing your file, terminate nano by pressing the keys CTRL + X.
If you made any changes, you will be asked to save them.