Linux - GeneralThis 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
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.
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.
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
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.