How to delete the files in UNIX/LINUX

How do i  remove the files?

In this topic I will show you how to remove the files by using the “rm” command  and also by using the options  & without options..

The “rm” command removes  a file with out asking confirmation from the user end(On Linux ,alias has been created with the rm command(-i option interactive) to ask the confirmation every time if you try to remove a file from a directory).

Be sure you really want to delete your files before you user “rm” command,because once the files are gone ,they are not coming back

Note:If you want to be prompted before  the deletion use the -i option

There is one little safety features in “rm” command it wont delete a directory(unless you use  -f option).

-f  means forcefully.

Let me show you how to delete the files with option and without option.

Ex:1 To remove a file from a directory

syntax:

#rm  <option>    <filename>

or

#rm   <filename>

Task: Remove a file form the /var  directory

First let me create a file inside the /  directory

#touch   /testfile

#ls -l  /testfile

#rm  /testfile

Note: Once you hit the enter button it will ask for the confirmation from the user end ,Once you give the permission “yes” to delete The file will get removed  from the directory.

I will show you with one example here:

 

 

Ex :2 Now i am going to apply the option -f with the “rm” command .

#touch   /anotherfile

#rm  -f  /anotherfile

Note: Here it will not ask the confirmation from the user as you have applied the force option -f which eliminates the interactive option.

Here you go….

 

Ex:3 Now applying the verbose option(-v) with the “rm” command

Verbose is nothing but the program provides the comments on the operation as they occur,so you will see the real time status of what the utility or program is doing to run the tasks or commands.

#touch  /myfile

#rm  -v  /myfile

I will show you this  with an simple example…

..

Note: From the above output if you see it is asking for the confirmation from the user before it gets delete from the directory,Because i haven’t applied the -f options ,if i would have applied then it will not ask the confirmation.

The order of options doesn’t a matter you can use it as you wish.

Ex:4 Applying -f and -v option with the “rm” command

#rm  -vf  /datafile

Here  as i said above it will not ask the confirmation from the user end before it gets delete(coz of -f option) and also it will print a message on your screen regarding this task(coz of -v option).

 

If you found this article useful, Kindly Subscribe here Click this link to Subscribe

http://www.linuxvasanth.com/create-empty-file-linux/

 

 

 

About Author:

Hello readers! Let me introduce my self first. My name is Vasanth Nirmal Singh J S having 9+ years of experience in IT on all flavours of Unix operating systems ,Storage's and many more .. I would like to share my technical experience i have come across - can be help to other people. So in this blog, I'll post my thoughts related to ITIS. I'll share experiences that I've had while working in different environments. You can expect content related to Unix,Solaris,Linux,EMC Storeages,HP-UX and many others. I hope this blog can be useful for you! Your comments will be appreciated!

Leave a Reply

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