How to Remove Linux Directories
There will be times when you want to remove an entire directory including all subdirectories and files. You can do this in Linux with a few simple commands typed at a command line.
Instructions
-
Instructions
-
1
Open a terminal window. Terminal windows are usually found under Utilities in the Start Menu.
-
2
Go to one directory above the directory you want to remove. For example, if your directory tree is /home/user/Documents/oldDocs, and you want to remove oldDocs, you would go to /home/user/Documents.
cd /home/user/Documents
or
cd ~/Documents
The ~ (tilde) signifies your home directory. -
-
3
List the contents of the current directory to make sure you are in the correct directory with the following command:
ls -
4
List the contents of the directory you are going to remove to make sure you are not deleting anything important.
ls -a oldDocs
The -a option will show all files, including any hidden files in a directory. -
5
Remove the directory and all its contents:
rm -r oldDocs
The -r option specifies that the command should be recursive. It is necessary if there are files in the directory. -
6
If there are no files in the directory, use the following command:
rmdir oldDocs
-
1
Tips & Warnings
If your operating system prompts you for a yes/no response for each file while executing the rm command, you can tell it to force the removal of files with the command "rm -rf oldDocs." You can perform the directory removal from your home directory by specifying the exact path to the directory "rm -r /home/user/Documents/oldDocs" or "rm -r ~/Documents/oldDocs."
There is no undelete command in Linux. If you are not sure that you really want to delete the files, use the Graphical User Interface (GUI) and place the file in the Trash folder. This folder acts the same as Windows Recycle Bin. Do not use the rm -rf command in the root file system. This will delete your entire file system.