You can use the following commands to delete the directory (also known as folder in the Macintosh OS X and Microsoft Windows operating system).
a] rmdir command - Deletes the specified empty directories.
|Estimated completion time||Less than a minute|
Syntax- rmdir command
The rmdir command remove the DIRECTORY(ies), if they are empty. The syntax is:
rmdir [option] directory-name
Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following command to remove a directory called /tmp/docs:
If a directory is not empty you will get an error:
$ rmdir letters
rmdir: letters: Directory not empty
You can cd to the directory to find out files:
$ cd letters
In this example, remove data, foo and bar if bar were empty, foo only contained bar and data only contained foo directories:
cd /home/nixcraft rmdir -p data/foo/bar
- -p - Each directory argument is treated as a pathname of which all components will be removed, if they are empty, starting with the last most component.
Linux remove entire directory including all files and sub-directories command
To remove all directories and subdirectories use rm command. For example remove *.doc files and all subdirectories and files inside letters directory, type the following command (warning all files including subdirectories will be deleted permanently):
$ rm -rf letters/
- -r : Attempt to remove the file hierarchy rooted in each file argument i.e. recursively remove subdirectories and files from the specified directory.
- -f : Attempt to remove the files without prompting for confirmation, regardless of the file's permissions
See alsoTweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?
- 30 Cool Open Source Software I Discovered in 2013
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012
- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop