LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-27-2020, 01:13 PM   #31
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Slackware, Amazon Linux
Posts: 1,925

Original Poster
Blog Entries: 20

Rep: Reputation: 126Reputation: 126

it would have been approaching half as many I/O operations for a lot of data i have (lots of empty directories).
 
Old 03-27-2020, 02:12 PM   #32
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,288

Rep: Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707
Quote:
Originally Posted by Skaperen View Post
if there was a way to determine that a directory is empty from its inode,
Only when
- the file system is ext?
- the directory has NEVER been used (there never were any names stored IN them)
the directory size is 48 bytes (only the . and .. entries), because that's the way "mkdir" creates them.

But as used directories, even after removing all files in them, never shrink their size in an ext? fs you cannot see from its I-node if they are empty (only how large they neede to be at their most full contents). And as extending the directory size goes to the next block size (often 4 KB) a size of "that block size" or a multiple doesn't tell you anything about the current content OF that directory.

EDIT: I was wrong, ext? does NOT create directories with an 48 bytes size.

Last edited by ehartman; 03-27-2020 at 04:45 PM. Reason: Correction
 
Old 03-27-2020, 03:13 PM   #33
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Slackware, Amazon Linux
Posts: 1,925

Original Poster
Blog Entries: 20

Rep: Reputation: 126Reputation: 126
Code:
lt2a/forums /home/forums 23> ls -dl foo
/bin/ls: cannot access 'foo': No such file or directory
lt2a/forums /home/forums 24> mkdir foo
lt2a/forums /home/forums 25> ls -dl foo
drwxr-xr-x 2 forums forums 4096 Mar 27 16:08 foo
lt2a/forums /home/forums 26> fgrep ' /home ' /proc/mounts
/dev/sda4 /home ext4 rw,relatime 0 0
lt2a/forums /home/forums 27>
maybe you are confusing ext4 with btrfs. or was that reiserfs?
 
Old 03-27-2020, 04:43 PM   #34
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,288

Rep: Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707
Quote:
Originally Posted by Skaperen View Post
maybe you are confusing ext4 with btrfs. or was that reiserfs?
No, reiserfs does shrink directory files as the tree is completely REwritten after changes.
Code:
On a ext3 fs
 % mkdir new
 % ls -dl new
drwxr-xr-x 2 hartman beheer 4096 2020-03-27 22:32 new
and a reiserfs one
 % mkdir new
 % ls -dl new
drwxr-xr-x 2 hartman beheer 48 2020-03-27 22:34 new
after putting some files in it
drwxr-xr-x 2 hartman beheer 240 2020-03-27 22:35 new
and removing them again
drwxr-xr-x 2 hartman beheer 48 2020-03-27 22:36 new
so you're right for ext3 at least (and I was wrong - I tested it too in ext2), but in reiserfs a directory size of 48 always means the directory is empty
but on ext? the directory size is a multiple of the blocksize for that fs (correction to my previous MSG), independant of how many filenames are IN it.

And thanks for the reaction, I do make mistakes sometimes!

Last edited by ehartman; 03-27-2020 at 04:46 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
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
LXer: How To Empty a File, Delete N Lines From a File, Remove Matching String From a File, And Remove Empty/Blank Lines From a File In Linux LXer Syndicated Linux News 0 11-22-2017 12:30 PM
Scripting Help--Check empty string condition (not null, but empty!) sungchoiok Linux - Newbie 4 01-01-2012 03:46 PM
[SOLVED] [BASH] non-empty variable before loop end, is empty after exiting loop aitor Programming 2 08-26-2010 09:57 AM
Gentoo VNC, empty dialog box !! "Question" window is empty ! TheHushedCaskeT Linux - Software 0 02-01-2005 10:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:53 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration