rm and rmdir Commands for Linux




In this blog we will learn about rm and rmdir command .Lets know about rmdir first . This rmdir command we can use to remove the directory or directory structures.
The basic rmdir command look like this : rmdir -options directory_name

  1. To remove a directory just write $rmdir directory name .
directory named pic is removed

2.In order to remove directory structure you can just carry the same command .To check any directory structure we can use $ ls -R command.

use of ls -R

Commad : rmdir dir1/dir2/dir3 .it will remove the top level directory .

top directory hasbeen removed

In the above pic s2 is removed.

3.In order to delete the whole directory structure what you need to do is you need to use this flag which is -p . Commad : rmdir -p dir1/dir2/dir3 .It will remove the whole directory structure .

4.You can try another comamnd with one more flag to see the output of rmdir command. Command : rmdir -pv dir1/dir2/dir3 .flag v is called verbose flag and this verbose refers to the mode or setting that this place or gets extended information so it will give you what’s happening in the background .

5.Now, in the directory structure if any of the directory contains a file then rmdir command will not work for that directory so if the directory contains any file you cannot use rmdir command direct.But starting from top , whatever is empty those will get deleted .

s2 is removed but not non-empty directory

6.There is another command you can use which is rm command and this command we can use to remove the files and directly directories.If you want to delete the whole directory structure you just need to give flag which is -r and it stands for a recursive . Command : rm -r diretory_structure .We can just add v flag also for just displaying the information what’s happening in the background . Command : rm -rv directory_structure .

In order to use the rm -r directory _name command you just need to give the parent directory name so you just need to give rm -r and then parent directory name would be enough to delete this directory and the child or subdirectory inside the parent directory whatever file it contains inside this directory .


Everything inside Image is removed

 so this is the brief information about rm command & rmdir command .



Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*