There are also a number of simple commands that you can employ to do useful work on your Linux system like those which are shown in Table 9-1.
Although we list a range of options which you can use with these commands, you should learn how to refer to the UNIX manual pages for a definitive explanation (see the section called Help!).
Table 9-1. Simple Commands
|pwd||print working directory|
|mv||move a file|
|cp||copy a file|
|rm||delete a file|
|mkdir||make a directory|
|rmdir||delete a directory|
The cd command allows you to change directory. To change to the /home directory, you would therefore type cd and /home at the command line.
You can also find out the location of the current directory as an absolute path from root by using the pwd command to display the result on screen. Our example consequently shows that we are currently in the /home directory.
The list files command is invoked by typing ls in combination with a range of arguments which are shown in Table 9-2.
Table 9-2. The List Command
|ls Command with Options||Explanation|
|ls -a||list all files|
|ls -l||long-format (detailed) listing|
|ls --color||list filetypes in colour|
|ls -F||show filetype|
|ls -i||produce a detailed listing|
|ls -s||print file size|
Tip: In order to take advantage of the listing filetype by colour facility which ls offers, you may need to establish an alias. Assuming that you are using Bash, enter the following line in your .bashrc file.
The mv command is used to move a file or directory from one place to another. The file sample.txt can therefore be moved into your /home directory by issuing the following command where the tilde (~) represents /home.
mv sample.txt ~
mv can also be used to rename a file. To change sample.txt's name to final.txt and move the renamed file to the /home directory, enter the following command:
mv sample.txt ~/final.txt
cp is very similar to mv in terms of the way in which you use it. One notable difference is that cp leaves the source file in situ whilst copying the file to your intended destination.
cp sample.txt ~/home
Tip: cp is also used to copy directories including their contents. If you need to do this, issue the cp command in conjunction with the -R option before typing the names of your source and destination directories.
The rm command is very easy to use although it is extremely easy to delete files unintentionally! We therefore advise you to use the -i option so that Linux confirms your intentions before taking any action.
rm -i sample.txt
You can use the mkdir command to create directories and sub-directories. Creation of a directory therefore involves typing the command and the name of your proposed directory whereas the creation of a sub-directory depends upon the -p option.
mkdir -p /work/paul
It's easy to delete an empty directory with the rmdir command. If we assume that the pleasure directory is empty, the next command removes it from our system.
Tip: You should use the rm with the -R option to delete a directory which contains files.