How to delete file and directory on CentOS and RHEL 6/7 step by step guide


How to delete file and directory  on CentOS and RHEL 6/7  step by step guide

In this article we will learn how to delete file and directory  on linux system which is very common task for a linux administrator.  

How to delete file on CentOS and RHEL  linux system


To delete a file of the linux system we need to execute the below command.

#rm  <filename>

Lets take an example we have one file name testnew and we want to delete this file.so we need to execute the below command.

#rm  testnew

[root@localhost project]# ls
testnew
[root@localhost project]# rm testnew
rm: remove regular empty file `testnew'? y
How to delete file and directory  on CentOS and RHEL 6/7  step by step guide
How to delete file and directory  on CentOS and RHEL 6/7  step by step guide

After execute the above command we can verify it using ls command.

[root@localhost project]# ls
[root@localhost project]#

We can delete multiple file using the below command.
#rm <file1> <file2> <file3> <file4>

How to delete empty directoy on linux system

To delete empty directory on linux system we need to use rmdir coammnd.

#rmdir <dir name>
Suppose  we have one empty dir named test we need to delete this we need to execute the below command.

#rmdir test

How to delete non-empty directoy on linux system

To delete non-empty directory on linux system we need to use rm  coammnd along with –r flag.

How to delete forcefully and recusively a file and a directoy on linux system

To delete a file and directory forcefully and recursively we need to use “-f” and “-r” flag along with the rm command

#rm –rf <dir name>

That’s all. If this article is helpful please share it!!!!




SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment