In Linux, a folder is also known as directory and directory is nothing but simply a group of files. If the directory or folder is empty then you can use rmdir command to delete the folder or directory in Linux. On the other hand if the folder or directory is not empty then you have to use rm to remove it.

Syntax to delete folder or directory using rmdir command in Linux

rmdir command can be used to delete a folder or directories in Linux.

The syntax is;

$ rmdir directory-name

$ rmdir rmdir

For example, if you have a folder named myfolder and it is empty and you want to delete it, then do the following steps;

  • Open the terminal application in your Linux Operating system
  • Then type the command:

$ rmdir myfolder

Example to delete a folder in Linux

In this example delete the folder named /temp/alpha/.

$ rmdir /temp/alpha/

We can use rmdir command to delete two folders at the same time by using the following syntax.

$ rmdir dir1 dir2

This command will delete both dir1 and dir2 directories. We can use options to get additional information about what is happening when running rmdir command. Pass the –v (verbose) option as follows:

$ rmdir –v dir1

How to delete directory and subdirectories in Linux

The -p option can delete a directory and its subdirectories/sub-folders:

$ rmdir -p dir1/dir2/dir3

  • -p option will remove the parent folder and specified subfolder.
  • -v diagnose every directory that we have processed
  • –ignore-fail-on-non-empty this option will ignore each failure if a folder is non-empty.

How to delete directory/folder recursively in Linux

The rm command is used to delete all directories and subdirectories recursively. For example, remove *.doc files and all sub-directories and files inside letters directory, type the following command.

$ rm -rf  letters/


  • -r:  Attempt to remove the document hierarchy rooted in every record argument i.E. Recursively take away subdirectories and documents from the required listing.
  • -f: Attempt to remove the files without prompting for confirmation, no matter the document’s permissions.

The only root user can delete the directory or subdirectory using above commands. System admin also deletes any directory or folder created by anyone.


In this tutorial, we learned how to delete folder/directories in Linux using rm and rmdir command. rmdir command is used to delete empty directory/folder in Linux operating system and rm command is used to delete directory and subdirectories recursively.

How do I delete a directory in Linux terminal?

How to force delete a directory in Linux
  1. Open the terminal application on Linux.
  2. The rmdir command removes empty directories only. Hence you need to use the rm command to remove files on Linux.
  3. Type the command rm -rf dirname to delete a directory forcefully.
  4. Verify it with the help of ls command on Linux.

How do I delete a folder and content in Linux?

To delete an empty directory, use the -d ( —dir ) option and to delete a non-empty directory, and all of its contents use the -r ( –recursive or -R ) option. The -i option tells rm to prompt you to confirm the deletion of each subdirectory and file.

How do I delete a folder in Terminal?

To delete (i.e. remove) a directory and all the sub-directories and files that it contains, navigate to its parent directory, and then use the command rm -r followed by the name of the directory you want to delete (e.g. rm -r directory-name ).

How do I empty a folder in Linux?

You can delete a directory in Linux using the rm command. The rm command can delete a directory if it contains files as long as you use the -r flag. If a directory is empty, you can delete it using the rm or rmdir commands.

How do I delete a folder?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

How do I empty a folder?

In Windows Explorer, right-click the file or folder that you want to delete and then choose Delete. The Delete File dialog box appears. Click Yes to delete the file. Instead of right-clicking and choosing Delete from the menu that appears earlier, you can press the Delete key on your keyboard.

How do I delete a folder using command prompt?

To remove a directory, just use the command rmdir <directory name> . Note: Any directories deleted with the rmdir command cannot be recovered.

Is it OK to delete empty folders?

Yes, it is totally safe to delete empty folders in android. If your system required those folders it will automatically create those folders for you in the future. If you use some apps in the past and now you are not using them then those apps also left some empty folders so you can delete them as well.

How do you delete folders in your email?

Delete a folder
  1. Right-click the folder you want to delete and click Delete Folder.
  2. Click Yes to move the folder and its contents to the Deleted Items folder. When you empty the Deleted Items folder, everything in it — including any folders you’ve deleted — is permanently erased.

Is it safe to delete empty folders Windows 10?

Is it safe to delete Empty Folders in Windows 10? Generally speaking, it is safe to delete empty folders, although you would make no real space savings as they occupy 0 bytes.

How do I delete empty folders on android?

How do I delete empty folders on my phone?

You can find them using your built-in file explorer or ES(recommended) just go to a location and long-press on a map. You will see an option to see the size of the map. If it’s zero, you can of course delete it. But remember not to look in the Android map and DCIM map because here are critical data stored.

How do I delete a folder on my Samsung phone?

How do I delete unnecessary files on Android?

Clear your junk files
  1. On your Android device, open Files by Google .
  2. On the bottom left, tap Clean .
  3. On the “Junk Files” card, tap. Confirm and free up.
  4. Tap See junk files.
  5. Select the log files or temporary app files you want to clear.
  6. Tap Clear .
  7. On the confirmation pop up, tap Clear.

How do I delete internal storage?

To clean up Android apps on an individual basis and free up memory:
  1. Open your Android phone’s Settings app.
  2. Go to the Apps (or Apps and Notifications) settings.
  3. Make sure All apps is selected.
  4. Tap on the app you wish to clean.
  5. Select Clear Cache and Clear Data to remove the temporary data.

How can I clean my phone from viruses?

How to remove viruses and other malware from your Android device
  1. Power off the phone and reboot in safe mode. Press the power button to access the Power Off options.
  2. Uninstall the suspicious app.
  3. Look for other apps you think may be infected.
  4. Install a robust mobile security app on your phone.

How do I clear other storage?

How to shrink “Otherstorage. In settings, head into the “Messages” category and scroll to “Message History”. Your iPhone is set to keep messages forever, but this can soon lead to running out of space. You can swap it to 1 year or 30 days, which will clear anything beyond those parameters.