How to delete a directory in the Linux terminal?
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
Tagged: linux
Learning how to delete a directory in the Linux terminal makes it easy to manage directories.
To delete an empty directory, you need to use the rm -d
command followed by the name of the directory that you want to delete.
rm -d directory
To delete a directory containing subdirectories and files, use the rm -r
command followed by the name of the directory you want to delete.
rm -r directory
And to delete multiple directories containing subdirectories and files, use the rm -r
command followed by directory names separated by a space.
rm -r directory1 directory2 directory3
Note: Please be careful when deleting files or directories, because once deleted, it is not easy to recover them.
Learn more Linux commands.
If a subdirectory or a file within the main directory is write-protected, you will be prompted to confirm the deletion.
To force delete a directory containing subdirectories and files without being prompted, you need to use the rm -rf
command followed by the directory name.
rm -rf directory