Getting Familiar with Linux Commands – Tutorial 1 – File Specific Commands

In the previous tutorial you saw some basic linux commands, now you will see some of the commands that are used to create and manipulate files.

Touch

The touch command is used to create a file. Just type touch followed by the filename and your file will be created!

If a file with the same filename already exists then it will update the timestamp(created/modification date) of the file.

Mkdir(make directory)

mkdir is used to create a new directory.

Rmdir(remove directory)

rmdir is used to delete an exiting directory. Remember! rmdir will only removes those directories that are empty. You will see how to delete non-empty directories with the upcoming command rm.

RM(remove)

rm is a very powerful command, you can delete almost anything with it, so be very careful while using it. Files/Directories deleted with rm do not go to bin, once deleted they are gone and cannot be recovered.

To delete a file, write rm followed by the filename.

-r

To delete a directory you have to use the -r option. It means that you want to delete all the files recursively.

-i

When you use -i option, before deleting any file it will ask you for a confirmation whether you want to delete it or not. It is useful in the case where you want to delete some files in a directory while keeping the others.

Output

-f

The f here means force delete, it means what ever be the case don’t ask me for any confirmation, just delete it!

-v

The v here means verbose, if you add this option then the rm command will print a summary of all the files/directories that it has deleted.

Output

CP(copy)

To copy a file from to a directory write the following command.

-r

To copy one directory into other directory use the -r option, which means recursively copy all the files.

(Copy directory1 into directory2)

-i

Just as you saw while deleting files with rm, -i will explicitly ask you before copying every file. This is useful in the case where you want to copy only some of the files from one directory to the other.

-v

The v means verbose, if you add this option then it will output a summary of all the files that have been copied.

MV(move)

To move a file to another directory write the following command.

You can also rename a directory using the mv command.

To move a directory into another directory.

(Remember if directory2 doesn’t exist then directory1 will be renamed to directory2)

-i

When you use the option -i, mv command, while moving files, will ask you confirmation for overwriting a file whenever there is a file already existing with the same name.


With these linux commands you have enough power to play around with files. Again I would urge you to try these commands on your own, practice to get a good hold onto them. Create a temporary directory and start messing around with it using these commands.

 

Previous Tutorial : Getting Familiar with Linux Commands – Tutorial 0 – Basic Commands

Leave a Reply

Your email address will not be published. Required fields are marked *

3 − 1 =