9 Easy Tips - How to remove directory in Linux

Tip1 - Remove empty directory with "rmdir" command

$ rmdir dir1 

* dir1 is directory name

Tip2 - Delete empty directory with "rm" command

$ rm -d dir1 

* dir1 is directory name

Tip3 - Delete non-empty directory with "rm" command

$ rm -r dir1 

* dir1 is directory name
* -r is used for recursive

Tip4 - Remove multiple non-empty directory with "rm"

$ rm -r dir1 dir2 dir3 

* dir1,dir2,dir3 are directories name
* -r is used for recursive

Tip5 - Remove write protected directory with "rm" command

$ rm -rf dir1 

* dir1 is the directory name
* -r is used for recursive
* -f flag is used to delete forcefully

Tip7 - Use "sudo" as prefix to remove root owned files using rm command

$ sudo rm -rf dir1 

* dir1 - directory name
* -r  for recursive
* -f flag is used, to delete forcefully.
* sudo for root privileges

Tip8 - use "man" command to see help of rm or rmdir command

$ man rm 

To see more help or manual on rm command and its options. use "man" command 

Tip9 - use "--help" flag to see all available options of rm command

$ rm --help

To see more help or options on rm command. 

Want more Linux tutorials and webstories ??