LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old Today, 02:57 AM   #1
exerceo
Member
 
Registered: Oct 2022
Posts: 115

Rep: Reputation: 20
Lightbulb 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.
 
Old Today, 03:24 AM   #2
why_bother
Member
 
Registered: Apr 2025
Posts: 45

Rep: Reputation: 11
Quote:
Originally Posted by exerceo View Post
[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.
 
Old Today, 04:10 AM   #3
exerceo
Member
 
Registered: Oct 2022
Posts: 115

Original Poster
Rep: Reputation: 20
Blogs don't appear in search engines.

Quote:
Originally Posted by why_bother View Post
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.
 
Old Today, 04:44 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,447

Rep: Reputation: 8033Reputation: 8033Reputation: 8033Reputation: 8033Reputation: 8033Reputation: 8033Reputation: 8033Reputation: 8033Reputation: 8033Reputation: 8033Reputation: 8033
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).
 
Old Today, 07:36 AM   #5
why_bother
Member
 
Registered: Apr 2025
Posts: 45

Rep: Reputation: 11
Quote:
Originally Posted by exerceo View Post
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.
 
Old Today, 08:31 AM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,974

Rep: Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859
Quote:
Originally Posted by exerceo View Post
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 View Post
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.

 
Old Today, 08:55 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,294
Blog Entries: 4

Rep: Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145
One way to do it, IIRC, is rm -rf dirname. This will delete everything in the directory and then the directory entry itself.
 
Old Today, 02:55 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,836

Rep: Reputation: 6342Reputation: 6342Reputation: 6342Reputation: 6342Reputation: 6342Reputation: 6342Reputation: 6342Reputation: 6342Reputation: 6342Reputation: 6342Reputation: 6342
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.
Old Today, 04:03 PM   #9
exerceo
Member
 
Registered: Oct 2022
Posts: 115

Original Poster
Rep: Reputation: 20
Lightbulb

Quote:
Originally Posted by pan64 View Post
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 View Post
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 View Post
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.
 
Old Today, 04:04 PM   #10
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,294
Blog Entries: 4

Rep: Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145Reputation: 4145
Huh ... I don't think I've ever actually used "rmdir."
 
  


Reply

Tags
deletion



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] F27 - Empty Trash Bin icon is showing the non-empty icon Connor84 Fedora 2 02-17-2018 01:18 AM
[SOLVED] Non answered Questions ?? clifftec LQ Suggestions & Feedback 11 08-03-2017 02:05 AM
[SOLVED] [BASH] non-empty variable before loop end, is empty after exiting loop aitor Programming 2 08-26-2010 09:57 AM
can not delete NON-EMPTY directories through samba share Sandor Linux - Software 2 02-16-2006 03:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration