Linux Delete Folder Using rmdir and rm Command

https‮//:‬www.lautturi.com
Linux Delete Folder Using rmdir and rm Command

To delete a folder using the command line in Linux, you can use the rmdir command to delete an empty folder or the rm command to delete a folder and its contents.

To delete an empty folder using the rmdir command, you can use the following syntax:

$ rmdir /path/to/folder

This will delete the /path/to/folder folder if it is empty. If the folder is not empty, the rmdir command will return an error.

To delete a folder and all its contents using the rm command, you can use the -f option to force the deletion of the files and the -r option to delete the files recursively:

$ rm -rf /path/to/folder

This will delete the /path/to/folder folder, including any subdirectories and their contents.

Note that these commands will delete the folder and all its contents, including hidden files and files that are protected by special permissions. Be careful when using these commands, as they cannot be undone and there is no way to recover the deleted files.

You can also use the rm command with the -i option to interactively delete the files, which will prompt you to confirm each file before it is deleted:

$ rm -ir /path/to/folder

This can be useful if you want to delete some, but not all, of the files in the folder.

These are just a few examples of how to delete a folder using the rmdir and rm commands in Linux. The specific steps may vary depending on the distribution and version of Linux that you are using. You can refer to the documentation for the rmdir and rm commands for more information on how to use them.

Created Time:2017-10-29 22:08:53  Author:lautturi