How to Delete a Directory in Linux in 2023 (4 Methods)
Linux is strikingly completely different from the Home windows working system. For instance, if you wish to delete a folder in Home windows, you may merely right-click on it and delete it. Nonetheless, issues aren’t that easy in Linux. Deleting a listing or folder in Linux will be achieved through the graphical consumer interface in … The post How to Delete a Directory in Linux in 2023 (4 Methods) appeared first on Ferdja.

Linux is strikingly completely different from the Home windows working system. For instance, if you wish to delete a folder in Home windows, you may merely right-click on it and delete it. Nonetheless, issues aren’t that easy in Linux. Deleting a listing or folder in Linux will be achieved through the graphical consumer interface in addition to the command line interface. In case you’re unsure how one can delete a listing in Linux, we’ve ready a easy but environment friendly information for you. On this article, we are going to present each the GUI and the CLI strategies to delete directories in Linux.
Take away a Listing in Linux (2023)
Folders in Linux are often called directories. And on the earth of Linux, the whole lot is handled as a file, even a listing. Allow us to now see how one can delete a listing in Linux utilizing 4 other ways – one GUI and three CLI.
Methods to Delete a Listing in Linux (GUI Methodology)
This technique of deleting recordsdata is straightforward and finest fitted to customers who’ve newly migrated to Linux. It could work on any distribution, supplied a “Desktop Setting” and file supervisor is put in on the pc. On this article, we’re utilizing Ubuntu 20.04 LTS with Gnome desktop atmosphere and Nautilus file supervisor. Right here’s the way it works:
1. First, open any file supervisor of your selection and navigate to the trail the place you wish to delete the listing.

2. Choose the folder(s) you wish to delete and press the “Delete” button on the keyboard. Or, you can too right-click on the chosen folder and choose “Transfer to Trash” from the context menu.

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

Delete a Listing in Linux through the Command Line
Doing any process utilizing the command line is quicker with many choices than the GUI technique. Additionally, the CLI technique deletes the recordsdata and folders completely. Right here, we are going to present three instructions to delete a listing in Linux that comes preinstalled in each Linux Distribution.
Delete Listing Utilizing the rmdir
Command
The rmdir
command is usually used to delete empty directories, however may also be used to delete non-empty ones. The command doesn’t have a ton of options and choices nevertheless it will get the job performed. The final syntax of the command is as follows:
rmdir
A number of the choices that the rmdir
command can take are:
Choice
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 Listing in Linux
To delete an empty listing in Linux, use the next command:
rmdir

Right 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 Listing in Linux
When you’ll attempt to delete a non-empty listing utilizing the rmdir
command, you’ll get the next error:
rmdir: didn't take away '
To delete a non-empty listing in Linux, use the next command:
rmdir --ignore-fail-on-non-empty

Delete Listing Utilizing the rm
Command
The rm
command is a strong software that may delete each recordsdata in addition to directories whereas offering many nice options. The essential syntax of the command is:
rm
A number of the choices which the command can take are:
Choice
Description
-f
When this flag is used, the affirmation immediate is not going to seem, and all of the nonexistent recordsdata and directories will likely 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 an evidence of what’s being performed presently.
Delete Empty Directories
To delete empty directories in Linux, use the -d
flag with the command as proven under:
rm -d

Delete Non-Empty Listing
When deleting non-empty contents, it may be very harmful as some important recordsdata could 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 under:
rm -r

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

Immediate Earlier than Deleting Folders in Linux
When deleting a number of recordsdata, use the -i
flag with the rm
command to get a immediate earlier than every file as proven under:
rm -ri

Delete Directories Utilizing the discover
Command
Delete Empty Listing in Linux
You can too delete folders utilizing the discover
command with the -delete
flag as proven under:
discover
This command will search for the empty listing specified by the parameter To delete non-empty directories utilizing the discover command, use the next syntax:
Understanding the above syntax:
Within the above syntax, the The command line technique is the quickest solution to delete directories. You should utilize The principle cause you can’t take away a listing in Linux is that you simply shouldn’t have acceptable permissions to make any adjustments within the listing. To delete a listing by bypassing lacking permission, use the next command: Deleting directories/recordsdata in Linux is a quite simple process but a vital one for customers of every kind. Right here, we’ve proven two methods to delete folders in Linux and we hope this text has given you understanding of the 2 strategies and the instructions. Do tell us within the feedback in case of any points.
Delete Non-Empty Directories
discover
+discover
command seems to be for directories matching with the -exec
flag will go the searched objects to the rm
command, which is able to delete the listing utilizing the -r
flag.
Continuously Requested Questions
rmdir
, rm
, and discover
instructions to delete directories in Linux.
sudo rm -rf
Delete Recordsdata and Directories Utilizing Linux Instructions
The post How to Delete a Directory in Linux in 2023 (4 Methods) appeared first on Ferdja.