Low Orbit Flux Logo 2 D

Linux How To Delete A Directory That Is Not Empty

If you are using Linux and do any amount of work on the command line it probably hasn’t taken very long to find an instance where you need to delete a directory that isn’t empty.

To delete a directory that is not empty on Linux use the following command:


rm -rf junkDir1

Be careful running this command. If you specify the directory wrong or make a typo you can cause a lot of damage.

-r recursive, needed for directories
-f force, needed for directories that are not empty

To delete an empty directory you can use the rmdir command but this only works with empty directories. You can run that like this.


rmdir  my_empty_dir1    

If you want to just delete a regular file you can use the rm command like this.


rm my_junk_file1.txt

You can also delete multiple non-empty directories like this.


rm -rf junk1 junk2 oldDir1 oldDir5