LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-11-2013, 07:57 AM   #1
ralgal
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Rep: Reputation: Disabled
Where does the size come from if directory is empty?


Hello

This may have been asked time and time before but i havent been able to find the answer.

I used the ls command in my home directory.

The output of the

ls -ld /home/user1/logs

is
drwxr-xr-x 2 user1 user1 4145152 Dec 16 2010 /home/user1/logs

The directory is completely empty. I tried

du -sh *

in the home directory and it shows the size of /home/user1/logs as 3.8M.

Can someone please tell me how i can reduce the size, or what that size means? (i tried ls -al and there are no hidden folders)

Thank you in advance for your answer.
 
Old 12-11-2013, 08:06 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Whom to trust ls or du. Did you look up the option you are giving to ls? Check them out and you might see that the output you get from it does not really mean the directory is empty.
 
Old 12-11-2013, 08:49 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by ralgal View Post
The output of the

ls -ld /home/user1/logs

is
drwxr-xr-x 2 user1 user1 4145152 Dec 16 2010 /home/user1/logs

The directory is completely empty.
Assuming an ext[2|3|4] file-system: The brown part does not indicate the size of the content of the directory, it tells you the size of the the directory entry itself (meta-data about files, including the file names contained in that directory). This is always a multitude of the block-size used on the system (4096 on most modern systems). In this case 1012 blocks are/where needed at some point.

If you empty a directory these blocks are not reduced. This is a feature (or problem if you want) of the ext2/3/4 file system. The only easy way to reduce the amount of blocks assigned is to delete the directory and re-create it again.

Quote:
I tried

du -sh *

in the home directory and it shows the size of /home/user1/logs as 3.8M.

Can someone please tell me how i can reduce the size, or what that size means? (i tried ls -al and there are no hidden folders)
Deleting files in a directory doesn't necessarily reduce the content size of that directory to zero. This can happen when a running program still has a pipe to a (former) file in that directory. The file is still kept open by the program even though the file isn't visible.

You can use the lsof command to find out if a file is kept open:
Code:
lsof | grep /home/user1/logs
(you might need to run the above as root user).
 
1 members found this post helpful.
Old 12-11-2013, 09:37 AM   #4
Spect73
Member
 
Registered: Aug 2013
Distribution: Slackware 14.1
Posts: 128

Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
Assuming an ext[2|3|4] file-system: The brown part does not indicate the size of the content of the directory, it tells you the size of the the directory entry itself (meta-data about files, including the file names contained in that directory). This is always a multitude of the block-size used on the system (4096 on most modern systems). In this case 1012 blocks are/where needed at some point.

If you empty a directory these blocks are not reduced. This is a feature (or problem if you want) of the ext2/3/4 file system. The only easy way to reduce the amount of blocks assigned is to delete the directory and re-create it again.

Deleting files in a directory doesn't necessarily reduce the content size of that directory to zero. This can happen when a running program still has a pipe to a (former) file in that directory. The file is still kept open by the program even though the file isn't visible.

You can use the lsof command to find out if a file is kept open:
Code:
lsof | grep /home/user1/logs
(you might need to run the above as root user).
druuna, thanks for the explanation. I did know about the metadata part but not the part that the blocks aren't reduced just because the contents of the directory is deleted. Again, thanks for the tip.
 
Old 12-11-2013, 01:00 PM   #5
ralgal
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you so much for the clarification.
 
Old 12-11-2013, 01:13 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,957

Rep: Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267
For ext2/3/4, running fsck with the "-D" option will shrink oversized directories, but optimizing all the directories in the file system might not be what you want to do.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] C++: Size of an empty class TheIndependentAquarius Programming 7 12-20-2011 11:38 AM
rm: cannot remove directory `ff': Directory not empty blancs Linux - General 17 08-29-2011 02:47 PM
Empty a directory fhsm Linux - Newbie 3 04-17-2009 12:19 AM
Removing non-empty directory George2 Programming 5 07-31-2007 02:15 AM
The postgresql data directory content in the pgsql directory is lost (empty data dir) kisembo Linux - Software 1 02-13-2006 02:11 PM


All times are GMT -5. The time now is 04:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration