Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
Today, 02:57 AM
|
#1
|
Member
Registered: Oct 2022
Posts: 115
Rep:
|
Why can non-empty directories not be deleted directly? [self-answered]
[ Log in to get rid of this advertisement]
[This is a self-answered question. Just added for completeness.]
Deletion works by unlinking a file from the file system tree and marking the space it occupied as unused. If a directory was unlinked from the file system without deleting its contents first, the space occupied by those files would not be made free, so it would waste space.
This is why a non-empty directory can't just be deleted in a single operation.
|
|
|
Today, 03:24 AM
|
#2
|
Member
Registered: Apr 2025
Posts: 45
Rep:
|
Quote:
Originally Posted by exerceo
[This is a self-answered question. Just added for completeness.]
Deletion works by unlinking a file from the file system tree and marking the space it occupied as unused. If a directory was unlinked from the file system without deleting its contents first, the space occupied by those files would not be made free, so it would waste space.
This is why a non-empty directory can't just be deleted in a single operation.
|
While as far as I know you're correct; I don't think this is the right place to be posting questions that you've already answered. I think this should be posted maybe in your blog or maybe the "Linux Tutorials" forum instead of here.
|
|
|
Today, 04:10 AM
|
#3
|
Member
Registered: Oct 2022
Posts: 115
Original Poster
Rep:
|
Blogs don't appear in search engines.
Quote:
Originally Posted by why_bother
While as far as I know you're correct; I don't think this is the right place to be posting questions that you've already answered. I think this should be posted maybe in your blog or maybe the "Linux Tutorials" forum instead of here.
|
Blogs are not indexed by search engines because they can only be seen while logged in. And it is not exactly a tutorial either. It is a technical explanation for a behaviour.
|
|
|
Today, 04:44 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,447
|
what do you mean by "a single operation"? rm -rf <dir> will delete that dir (regardless of its content, as long as you are allowed to remove all or them).
|
|
|
Today, 07:36 AM
|
#5
|
Member
Registered: Apr 2025
Posts: 45
Rep:
|
Quote:
Originally Posted by exerceo
Blogs are not indexed by search engines because they can only be seen while logged in. ...
|
You can set the relevant blog setting to make your blog visible to people who aren't logged in. Yes, as some do, you can also set it so it's not visible to those not logged in too.
|
|
|
Today, 08:31 AM
|
#6
|
Senior Member
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,974
|
Quote:
Originally Posted by exerceo
Blogs are not indexed by search engines because they can only be seen while logged in.
|
Even if that were true (it isn't; just enable the "Guests may... View your blog" option in Blog Settings), one one can create a blog on many different platforms.
However...
Quote:
Originally Posted by exerceo
Just added for completeness.
|
Your explanation is far from complete.
If this were a blog entry, I would expect a much more comprehensive answer to this question.
Also...
Quote:
Why can non-empty directories not be deleted directly?
|
They can, "rm -r dir" will delete a directory that contains files. (Blindly using -rf options is a stupid habit.)
As the -v option will show, it simply removes the files in each directory first.
|
|
|
Today, 08:55 AM
|
#7
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,294
|
One way to do it, IIRC, is rm -rf dirname. This will delete everything in the directory and then the directory entry itself.
|
|
|
Today, 02:55 PM
|
#8
|
Moderator
Registered: Aug 2002
Posts: 26,836
|
The only function of rmdir is to delete empty directories mainly as a safety feature AFAIK. Otherwise as posted rm can delete non empty directories in a single operation but it requires the use of options.
|
|
1 members found this post helpful.
|
Today, 04:03 PM
|
#9
|
Member
Registered: Oct 2022
Posts: 115
Original Poster
Rep:
|
Quote:
Originally Posted by pan64
what do you mean by "a single operation"? rm -rf <dir> will delete that dir (regardless of its content, as long as you are allowed to remove all or them).
|
Quote:
Originally Posted by boughtonp
They can, "rm -r dir" will delete a directory that contains files. (Blindly using -rf options is a stupid habit.)
|
Quote:
Originally Posted by sundialsvcs
One way to do it, IIRC, is rm -rf dirname. This will delete everything in the directory and then the directory entry itself.
|
Indeed, but that command performs many operations. Each file requires one deletion operation. If a folder contains 50000 files, it requires this many file operations to delete the folder.
I have read in some comment (I can't remember where) that someone believes rmdir's inability to delete non-empty directories is just for safety. But that is only half the truth.
|
|
|
Today, 04:04 PM
|
#10
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,294
|
Huh ... I don't think I've ever actually used "rmdir."
|
|
|
All times are GMT -5. The time now is 04:13 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|