Which command is used to remove a non empty directory (Linux)?

- Advertisment -

Many time on Linux operating system we got a situation where we want to remove some folder but the OS does not allow us. The reason: the directory is not empty that’s why the Linux prompt message “rmdir: ‘dir’: Directory not empty” and could not be get deleted at all.

We generally use rm command to delete files and empty folder, however, the command for deleting full directory will be different.

For example, If I want to delete an XYZ folder on Ubuntu then the command I used will be:

sudo rmdir xyz

But this will not work if the folder is not empty.

So, to remove the directory on Ubuntu or any other Linux that has files or folders, use the below command:

rm -rf {folder name}

In the above command, the folder name has to be replaced with the directory name which you want to be get deleted on Linux.

For example, in the below image you can see that I used the rm -rf command to remove a folder called php. When I had used it without -rf flag it said the deletion couldn’t be possible because the directory contains the file. So, then I used rm -rf and it successfully deleted it. So, the command will be:

rm -rf php

Where php was my folder name and you have to use your directory name that you want to delete.

how to remove full directory with folder in Linux

Note: The above-given command is very powerful when used with root privilege, it will delete all files and subfolders present in a directory without intimating. I mean it will not be going to prompt even once before deleting any file. So, make sure you know what you are doing…

Other Useful Resources:

H2S Media Team
H2S is a group of tech enthusiasts those are passionate about latest technology developments. They always like to solve own technical problems and share the same solution with others through this Website.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Posts

Xbox Scarlett is now officially Xbox Series X

Ending every speculation and rumours, Microsoft named the next-gen console as Xbox Series X. Taking the opportunity of The...

What points one should look to get the best internet connection for gaming

Finding the right gaming computer of your choice might not be a difficult exercise today when you...

Microsoft’s next-generation 2020 console is Xbox Series X not Scarlett

At the stage of The Game Awards (TGA), Microsoft's vice-president of Gaming "Phil Spencer" announced that the new generation...

Now we can send and receive tabs on Firefox Reality VR Browser

Last year launched Firefox Reality browser especially meant for VR headsets has got some updates. This Mozilla VR browser's...
- Advertisement -

Best Way to find new Movies or TV series to Watch

Do you want to know how to discover something new to watch, I mean quality video content? If you...

What is Xbox Project Scarlett? Anaconda or Lockhart

Now the time of 9th gen gaming console is about to meet an end. Even the primary...
- Advertisement -

You might also likeRELATED
Recommended to you