question about empty directories in unix system


 
Thread Tools Search this Thread
Top Forums Programming question about empty directories in unix system
# 1  
Old 03-17-2011
question about empty directories in unix system

how is it possible for a directory to be empty and still have a size greater than 0 in bytes...

i made a shell script that shows info about all files/directories and this is what came up
the last one is the size, here its showing 1024
in the for loop i did something like
for h in * .*; do

so i did account for hidden files
text-base,directory,5662879,1024
{
}
# 2  
Old 03-17-2011
Quote:
Originally Posted by omega666
how is it possible for a directory to be empty and still have a size greater than 0 in bytes...
It takes space for a directory to exist at all; the directory's name, access permissions, etc, etc. all have to be stored somewhere. Most filesystems parcel up disk space in minimum chunks of at least a few kilobytes, so even an empty directory is given the full minimum chunk.

Also, if the directory used to have a whole lot of files in it, it won't shrink when empty in case it needs the space again.
# 3  
Old 03-17-2011
then how is it posssible that one empty directory has the size 80 while another has the size 1024?

does this have to do with their length of name and inode number?
# 4  
Old 03-17-2011
Quote:
Originally Posted by Corona688
Also, if the directory used to have a whole lot of files in it, it won't shrink when empty
How are you measuring these sizes anyway?
# 5  
Old 03-17-2011
using this line
echo "$(stat -c %n,%F,%i,%s $name)"

i am able to see the size in bytes
%s does it
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Empty Directories

Please help me. How i can find empty directories in solaris?? (4 Replies)
Discussion started by: FoDeGe
4 Replies

2. Shell Programming and Scripting

How to exclude the empty directories

Hi., I have a script, in which I am processing a files present in the directory types. ls -lrt | grep ^d | grep Dir_type | awk -f '{print $9}' |\ while read dir_name; do #operations done where Dir_type is the pattern in which directories get created. How to filter out empty... (2 Replies)
Discussion started by: IND123
2 Replies

3. Shell Programming and Scripting

Listing non empty directories

Hi Gurus, How to list directories that are non-empty and non-hidden Thanks in advance (2 Replies)
Discussion started by: kinny
2 Replies

4. UNIX for Dummies Questions & Answers

Remove only Empty Directories

I know this one was answered before in forum below - https://www.unix.com/unix-dummies-questions-answers/58210-removing-empty-folders-using-find-command.html But that one is closed & I have a question so here it goes. I want to delete all 2006 files. Now if along with the files, if the... (2 Replies)
Discussion started by: kedar.mehta
2 Replies

5. Shell Programming and Scripting

identify the empty directories

Hi Wrote the below script to identify the empty directories ,when executing the below showing that directory is not empty but the directories are empty.Please help to identify the empty directories 33 is not empty 33 is not empty 33 is not empty 33 is not empty for file in `find .... (5 Replies)
Discussion started by: mohan705
5 Replies

6. UNIX for Dummies Questions & Answers

Empty directories having different size

$ls -lrt mydir total 12 drwxrwxrwx 2 nobody nobody 512 Aug 8 11:51 tmp drwxrwxrwx 2 nobody nobody 4608 Jan 19 12:20 web.cache $ ls -lrt mydir/web.cache/ total 0 $ ls -lrt mydir/tmp/ total 0 Can anyone explain me the above results? I know the o/p of ls, but this... (3 Replies)
Discussion started by: rahulrathod
3 Replies

7. UNIX for Dummies Questions & Answers

Help identifying empty directories

Is there a way you can identify directories that are empty? I do not need to remove them, I just need to identify them below a cetain path. I have tried the following already and it returned everything for some reason. #!/bin/sh && set -- . find "$@" -type d -depth -print > dir.txt |... (2 Replies)
Discussion started by: dboard
2 Replies

8. UNIX for Dummies Questions & Answers

Unix File System performance with large directories

Hi, how does the Unix File System perform with large directories (containing ~30.000 files)? What kind of structure is used for the organization of a directory's content, linear lists, (binary) trees? I hope the description 'Unix File System' is exact enough, I don't know more about the file... (3 Replies)
Discussion started by: dive
3 Replies

9. UNIX for Dummies Questions & Answers

scanning empty directories

Hi, I want to produce a text file representing a list of empty directories on a unix system starting from a specified directory. I hope I explained well my problem. Thanks in advance. (7 Replies)
Discussion started by: N065956BM
7 Replies

10. IP Networking

I have some question on unix system

Dear all, If I login to a Unix system (general user account), will the unix system generate a history file? If positve, will it stored the IP adress also? Thanks and Regards Penny Li ;) (2 Replies)
Discussion started by: PennyLi
2 Replies
Login or Register to Ask a Question