HowTo: Deleting Directories in Linux

www.lau‮c.irutt‬om
HowTo: Deleting Directories in Linux

To delete a directory in Linux, you can use the rmdir command.

  1. Make sure the directory is empty. You cannot delete a directory that is not empty using rmdir. To delete the directory and all its contents, including subdirectories and files, you can use the rm command with the -r option.

  2. Navigate to the parent directory of the directory that you want to delete.

  3. Use the rmdir command to delete the directory:

rmdir DIRECTORY_NAME

Replace DIRECTORY_NAME with the name of the directory that you want to delete.

For example, to delete the directory foo in the current directory, you would run:

rmdir foo

If the directory is not empty, rmdir will display an error message. In this case, you can use the rm command with the -r option to delete the directory and all its contents:

rm -r DIRECTORY_NAME

It is important to use these commands with caution, as they can delete a large number of files and directories at once and cannot be undone. Make sure you understand the consequences of the command before running it.

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