To get a more detailed view of the files in a directory, type ls -l
, or use the abbreviated command ll
. This displays additional details such as file permissions, dates, and sizes.
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 upstartalternatives.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 wtmpalternatives.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.1
You can also perform a ls
on another folder:
ls /etc
rm: 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 myFile
To delete folders as opposed to files, you need to add the -r
argument:
rm -r myFolder
This command will recursively remove the folder and all its files and contents.
To force a deletion, use rm -rf myFolder
. Pay attention when using this command. A mistake can delete critical data without asking you for confirmation.
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 COMMAND
For 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.txt
The 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.