How to Delete a Directory in Linux in 2023 (4 Methods).
Linux is strikingly completely different from the Windows working system. For instance, if you wish to delete a folder in Windows, you’ll be able to merely right-click on it and delete it. However, issues will not be that easy in Linux. Deleting a listing or folder in Linux may be achieved through the graphical consumer interface in addition to the command line interface. If you’re unsure how to delete a listing in Linux, we now have ready a easy but environment friendly information for you. In this text, we’ll present each the GUI and the CLI strategies to delete directories in Linux.
Remove a Directory in Linux (2023)
Folders in Linux are often called directories. And on this planet of Linux, every part is handled as a file, even a listing. Let us now see how to delete a listing in Linux using 4 alternative ways – one GUI and three CLI.
How to Delete a Directory in Linux (GUI Method)
This methodology of deleting information is simple and best suited to customers who’ve newly migrated to Linux. It can work on any distribution, supplied a “Desktop Environment” and file supervisor is put in on the pc. In this text, we’re using Ubuntu 20.04 LTS with Gnome desktop setting and Nautilus file supervisor. Here’s the way it works:
1. First, open any file supervisor of your alternative and navigate to the trail the place you need to delete the listing.

2. Select the folder(s) you need to delete and press the “Delete” button on the keyboard. Or, it’s also possible to right-click on the chosen folder and choose “Move to Trash” from the context menu.

3. All deleted information and directories in Linux will not be deleted completely however moved to a particular location often called Trash, which has similarities to Recycle Bin in Windows.
4. To completely delete a listing in Linux, choose it and press “Shift + Delete” on the keyboard. It will open a immediate whether or not you need to delete it completely or not. Click on “Delete” within the dialogue field once more.

Delete a Directory in Linux through the Command Line
Doing any activity using the command line is quicker with many choices than the GUI methodology. Also, the CLI methodology deletes the information and folders completely. Here, we’ll present three instructions to delete a listing in Linux that comes preinstalled in each Linux Distribution.
Delete Directory Using the rmdir
Command
The rmdir
command is usually used to delete empty directories, however will also be used to delete non-empty ones. The command doesn’t have a ton of options and choices but it surely will get the job achieved. The common syntax of the command is as follows:
rmdir <choices> <directory_name>
Some of the choices that the rmdir
command can take are:
Option | Description |
---|---|
--ignore-fail-on-non-empty |
used to delete non-empty directories |
-p, --parents |
used to delete the listing together with its youngsters specified |
-v, --verbose |
used to get a diagnostic message for each listing |
Delete Empty Directory in Linux
To delete an empty listing in Linux, use the next command:
rmdir <directory_name>

Here, on this instance, since we get no output, this implies the command obtained efficiently executed and the listing has been deleted.
Delete Non-Empty Directory in Linux
When you’ll attempt to delete a non-empty listing using the rmdir
command, you’re going to get the next error:
rmdir: didn't take away '<directory_name>': Directory not empty
To delete a non-empty listing in Linux, use the next command:
rmdir --ignore-fail-on-non-empty <directory_name>

Delete Directory Using the rm
Command
The rm
command is a robust instrument that may delete each information in addition to directories whereas offering many nice options. The primary syntax of the command is:
rm <choices> <file_name/directory_name>
Some of the choices which the command can take are:
Option | Description |
---|---|
-f |
When this flag is used, the affirmation immediate is not going to seem, and all of the nonexistent information and directories can be ignored |
-i |
When this flag is used, the command will ask for affirmation from the consumer for every deletion. |
-r |
When this flag is used, the command will take away all of the contents of the listing specified. |
-d |
This flag is used to take away empty directories. |
-v |
This flag is used to get a proof of what’s being achieved presently. |
Delete Empty Directories
To delete empty directories in Linux, use the -d
flag with the command as proven beneath:
rm -d <directory_name>

Delete Non-Empty Directory
When deleting non-empty contents, it may be very harmful as some important information might get deleted. So, be further cautious when deleting non-empty directories. To delete a listing with all its contents, use the -r
flag with the command as proven beneath:
rm -r <directory_name>

Force Delete Directories in Linux
The rm command offers a immediate, by default, when deleting the write-protected information and directories. Press both 'y'
or 'n'
relying upon your alternative. To bypass the immediate, we use the -f
flag as proven beneath:
rm -rf <directory_name>
This command can show to be fairly disastrous if executed unintentionally within the root listing.

Prompt Before Deleting Folders in Linux
When deleting a number of information, use the -i
flag with the rm
command to get a immediate earlier than every file as proven beneath:
rm -ri <directory_name>

Delete Directories Using the discover
Command
Delete Empty Directory in Linux
You also can delete folders using the discover
command with the -delete
flag as proven beneath:
discover <path_to_search> -type d -name "directory_name" -delete
This command will search for the empty listing specified by the parameter <directory_name> within the given path and delete them.

Delete Non-Empty Directories
To delete non-empty directories using the discover command, use the next syntax:
discover <path_to_search> -type d -name "directory_name" -exec rm -r {}
+
Understanding the above syntax:
In the above syntax, the discover
command appears for directories matching with the <directory_name> within the <path_to_search> after which the -exec
flag will cross the searched gadgets to the rm
command, which can delete the listing using the -r
flag.

Frequently Asked Questions
The command line methodology is the quickest technique to delete directories. You can use rmdir
, rm
, and discover
instructions to delete directories in Linux.
The principal purpose you can not take away a listing in Linux is that you simply wouldn’t have applicable permissions to make any modifications within the listing. To delete a listing by bypassing lacking permission, use the next command: sudo rm -rf <directory_name>
Delete Files and Directories Using Linux Commands
Deleting directories/information in Linux is a quite simple activity but a vital one for customers of every kind. Here, we now have proven two methods to delete folders in Linux and we hope this text has given you an excellent understanding of the 2 strategies and the instructions. Do tell us within the feedback in case of any points.
Check out more article on – How-To tutorial and latest highlights on – Technical News
How to Spawn Warden in Minecraft 1.19 (Easy Guide)
Gundam Evolution: How to Change Server
How do I Fix System Restore Not Working on a Windows PC
How do I deploy the Percona database performance monitor with Docker
How do I handle errors with a generic error-handling routine in Microsoft VBA procedures
How to Sort Data Alphabetically in Excel
How to Install an SSD In Your PS5 Console (2023)
How do I Diagnose & Fix an Xbox Controller Not Charging
How do I Play Spotify Through a USB on an Android
What is Heart Rate Variability (HRV) in Apple Watch and How do I Check It? (2021)
How to Use the Animations Pane in Microsoft PowerPoint
How do I Add New Items in macOS Context Menu
How do I set up the Jotform plug-in in WordPress
How do I send mass emails from Gmail
How to Use the Board View in Microsoft 365’s Calendar
How do I deploy the Portainer container manager with Podman
How do I Enable Efficiency Mode for Apps in Windows 11
How to Repost a Video or Picture on Instagram
How to Use Microsoft Outlook for Project Management
How to Add a Personal Note to Your Profile in Microsoft Teams
How do I Set a Screensaver on a Windows PC
How do I deploy a container to a remote Docker machine with ServerCat
How do I integrate Google Calendar with Asana
How to Get Free Microsoft Office for Students
How do I go passwordless for shell scripts in Linux
How do I permanently disable Sticky Keys on Windows 11 [2023]
How to Increase the Functionality of OneNote With OneMore Add-In
How to Use PowerPoint Speaker Coach to Improve Your Presentation Skills
How to Delete Your Roblox Account Permanently (2021)
How do I Unlock Android Phone if I Forgot the Password
How do I integrate monday work management with Google Calendar
How to Enable Material You Design on Your Chromebook
How do I Create AI Art With Midjourney
How to Find a Village in Minecraft (2022)
How do I Connect to AirPods for a Zoom Conference on a Windows PC, Mac, or Chromebook
How to Set up a Valheim Dedicated Server (Easiest Method)
How do I Open the Command Prompt on a Windows 10 or 11 PC
How to Make a Minecraft Skin in 2022 (Easiest Guide)
How do I Create AI Art With DALL-E 2
How to Tame a Cat in Minecraft Bedrock and Java Edition (2022)
How do I enable unattended-upgrades in Ubuntu and Debian Linux
How do I Use Mods in Google Snake Game in 2022 (Guide)
How do I Add Events to a Shared Calendar in Google Calendar
How to Adjust or Disable PS5 DualSense Controller Haptics
How do I Get Alerts of New Crypto Listings
How to Make a Fletching Table in Minecraft (2023 Guide)
How do I Toggle Autocorrect On or Off on an iPad
How to Clear DNS Cache on Android Devices (2023)
How do I add Gmail as a search engine in Chrome-based browsers
How to Tame a Cat in Minecraft Bedrock and Java Edition (2022)
How to Use the New AI-Powered Bing on Your Chromebook
How to Move, Reorder, and Rearrange Pages in Microsoft Word
How to Run GeForce Now on a Chromebook [All Regions]
How do I Lock a Mouse to One Monitor
How to Install WSJT-X on Linux Mint (2023 Guide)
How do I Record the Screen in Ubuntu (3 Easy Methods)
How do I Change File Extensions for a File on an iPhone
How to Craft and Use Boat with Chest in Minecraft (2022)
How to Get Fireflies in Minecraft (June 2022)
How to Use the IFS Function in Excel
How to Zoom In and Out on a Chromebook (5 Ways)
Roblox Shirt Template: How to Make Custom Roblox Shirts
How to Find Diamonds in Minecraft 1.18.1 (2022)
How to Make a Mob Farm in Minecraft for XP and Rare Loot
How to Make a Bootable CD/DVD/USB to Install Windows
How do I Recover Android Data After Factory Reset
How to Make a Goat Farm in Minecraft (2022)
Why Microsoft Excel Prints Blank Pages and How to Fix the Issue
How do I block posts based on language on Mastodon
How do I create content from transcribed audio and video using Trint
How do I automate data quality processes
How To Peep And What To Do With Creature Cards
How to Use PowerPoint Speaker Coach to Improve Your Presentation Skills
How do I Use a VPN With FanDuel
How do I Change Your Payment Method in Crunchyroll
Install and Activate Microsoft Office 2019 [via Internet]
How to Auto-Track Your Anime Shows and Manga (2023)
How to Make Potion of Weakness in Minecraft (2022)
How to Edit an Image in Microsoft Word: 8 Useful Tools
How do I Record Browser Activity w/o Any Tools
How to Check if Two Values Are Equal in Excel
How to Create a Whiteboard Animation in PowerPoint
How do I transfer EVERY data from Android to iPhone [2023]
How do I Open the Command Prompt on a Windows 10 or 11 PC
How to Enable Hidden Education Themes on Windows 11
How do I multitask apps with Stage Manager in macOS Ventura
How do I Create a New Project in Redmine
How do I Block Spam in Google Calendar [2023]
How to Enable or Disable Gyroscope in Apex Legends Mobile
How to Create an Ebook With Microsoft Word
Crunchyroll: How do I Cancel Your Subscription (2022)
How do I learn coding absolutely for free
How do I Earn a Promotion as a Networking Expert
How do I Resize an Image in PhotoPea
How do I Fix a Zoom Connection That’s Stuck on Connecting
How to Import Excel Spreadsheets to Google Sheets
How to Get Allay in Minecraft Right Now (March 2022)
How do I automatically open a Microsoft 365 app or file when you launch your computer
How to Get Fireflies in Minecraft (June 2022)
How do I Turn Off Your Birthday in LinkedIn
How To Get The Tier 2 Insect Axe In Grounded & What It Does
How do I Turn Bluetooth On or Off in Windows 11
How do I Play Music From Phone on Alexa
Medieval Dynasty: How to Find Clay
How to record in ProRAW and ProRes on the iPhone 14 Pro and 14 Pro Max
How to Install OptiFine in Minecraft 1.18.1 in 2022 [Guide]
How to Use Microsoft Excel for Sentiment Analysis
How to Create and Share a Notebook in OneNote
How to Change MAC Address in Linux (Two Methods)
How to Get Minecraft for Free (Official Methods)
How do I Transfer Apps From Android to Android
How do I add a GitHub repository to VS Code
How to Stop Discord Showing What Game You’re Playing
How do I Change Your Professional Focus with Minimal Downtime
How do I Backup an Android Device to an External Hard Drive
How to Add or Remove a Digital Signature in Microsoft Office Files
How do I set up HubSpot and Jira integration
How to Get Elytra in Minecraft in 2022 (3 Best Ways)
How do I Group Multiple App Windows as Tabs in Windows 11
How do I Change Your Gmail Address
How to Schedule Instagram Posts on Time Using Buffer
How do I make the case for increased test automation resources
How do I Make Text Fill a Cell in Google Sheets
How do I Play Music From Phone on Alexa
How To Get The Pinch Whacker In Grounded
How to Create a Professional Roadmap in PowerPoint
How to Use Create Button on PS5 DualSense Controller
How to Find Sniffer in Minecraft 1.20 Right Now (2023)
How to Get XP Fast and Level the Battle Pass
How to Manage Multiple Microsoft 365 Accounts on One Device
How to Use Instagram Stories Effectively: Basics, Tips, and Tricks