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?
- Open the terminal application on Linux.
- The rmdir command removes empty directories only. Hence you need to use the rm command to remove files on Linux.
- Type the command rm -rf dirname to delete a directory forcefully.
- Verify it with the help of ls command on Linux.
How do I delete a folder and content in Linux?
How do I delete a folder in Terminal?
How do I empty a folder in Linux?
How do I delete a folder?
How do I empty a folder?
How do I delete a folder using command prompt?
Is it OK to delete empty folders?
How do you delete folders in your email?
- Right-click the folder you want to delete and click Delete Folder.
- 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?
How do I delete empty folders on android?
How do I delete empty folders on my phone?
How do I delete a folder on my Samsung phone?
How do I delete unnecessary files on Android?
- On your Android device, open Files by Google .
- On the bottom left, tap Clean .
- On the “Junk Files” card, tap. Confirm and free up.
- Tap See junk files.
- Select the log files or temporary app files you want to clear.
- Tap Clear .
- On the confirmation pop up, tap Clear.
How do I delete internal storage?
- Open your Android phone’s Settings app.
- Go to the Apps (or Apps and Notifications) settings.
- Make sure All apps is selected.
- Tap on the app you wish to clean.
- Select Clear Cache and Clear Data to remove the temporary data.
How can I clean my phone from viruses?
- Power off the phone and reboot in safe mode. Press the power button to access the Power Off options.
- Uninstall the suspicious app.
- Look for other apps you think may be infected.
- Install a robust mobile security app on your phone.
How do I clear other storage?
Ads by Google