How to Delete a Directory in Linux & Mac OS X Terminal

| | Tutorial Software |

How to Delete a Directory in Linux & Mac OS X Terminal
When using the terminal on Linux or on Mac OS we sometimes need to delete the directory or folder.

When trying to delete a directory using the rmdir command, you may find the answer "rmdir: 'dir': Directory not empty" and you can not delete that directory.

To delete a directory that contains files or other subdirectories, then you can use the following command:
In the example above, you can try replacing FOLDER_NAME with the folder you want to delete, eg the name of the folder you want to delete is "MOVIES" then the command typed in terminal is rm -r MOVIES.

The above command if executed it will delete all the files and directories in the folder/directory mentioned in the command, the MOVIES folder and the contents in it. However, the command will prompt an approval to delete each file, if there are 10 then 10 approval requests will appear. The parameter r here means recursive, so the MOVIES folder and its contents will be deleted recursively, but will fail if there are any more folders.

It is actually good for security, so no mistake in removing the directory. But it would be troublesome. 

If you are sure you want to delete the MOVIES folder, you can change -r to -rf, rf means recursive+force, command to delete directory in terminal become like this:
rm -rf MOVIES
The above command if executed it will delete the MOVIES folder and all the contents contained therein without asking for confirmation. 

Removing FILE on Terminal Linux and Mac OS

While to delete files in Linux and Mac OS terminal is almost the same way that is using rm command, for example the file name to be deleted is flower.jpg, then the command becomes as follows:
rm flower.jpg
Those are some ways of deleting folders or directories in LINUX and MAC OS terminal, please use which one is safe and comfortable according to you.

Disclaimer: Images, Content of articles or videos that exist on the web sometimes come from various sources of other media. Copyright is fully owned by the source. If there is a problem with this matter, you can contact us here.
How to style text in Disqus comments:
  • To write a bold letter please use <strong></strong> or <b></b>.
  • To write a italic letter please use <em></em> or <i></i>.
  • To write a underline letter please use <u></u>.
  • To write a strikethrought letter please use <strike></strike>.
  • To write HTML code, please use <code></code> or <pre></pre> or <pre><code></code></pre>, and please parse the code in the parser box below.
Show Parser Box