LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 05-29-2014, 02:41 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
Discrepancy between df and ls?


Code:
root@server:~# ls -lh /SDA6/
total 3.6M
-rw-r--r-- 1 semoi semoi 1.8K 2014-04-17 13:23 almacen.xml
-rw-r--r-- 1 semoi semoi  57K 2014-04-17 13:23 almacen_menu0_bg.png
-rw-r--r-- 1 semoi semoi 1.7K 2014-04-17 13:23 almacen_menu0_bg_active_out.png
-rw-r--r-- 1 semoi semoi 1.5K 2014-04-17 13:23 almacen_menu0_bg_inactive_out.png
-rw-r--r-- 1 semoi semoi 1.7K 2014-04-17 13:23 almacen_menu0_bg_select_out.png
-rw-r--r-- 1 semoi semoi 3.5M 2014-04-17 13:24 almacen_menu_0.mpg
-rw-r--r-- 1 semoi semoi  321 2014-04-17 13:23 almacen_menu_0.xml
drwx------ 2 root  root   16K 2014-04-17 12:38 lost+found/
root@server:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        21G   16G  3.4G  83% /
tmpfs           1.9G     0  1.9G   0% /dev/shm
/dev/sda1        20G   12G  8.5G  57% /xp
/dev/sda6       415G   74M  394G   1% /SDA6
root@server:~#
I can't understand the output. Whereas ls shows no more than 4MB in /SDA6, df tells me I am using 74MB. mount's output is as follows:
Code:
root@server:~# mount
/dev/sda2 on / type ext2 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /xp type fuseblk (rw,allow_other,blksize=4096)
gvfs-fuse-daemon on /home/semoi/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=semoi)
/dev/sda6 on /SDA6 type ext2 (rw)
root@server:~#
Could somebody give me a cue?

Last edited by stf92; 05-29-2014 at 03:06 PM.
 
Old 05-29-2014, 03:06 PM   #2
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
ls -lh is not showing the contents of hidden directories, if any. And as used, ls is not recursive.

If you'd like to know how much space a directory is using, use du.

Code:
du -h /SDA6
sample from my system:

Code:
$ du -h /tmp
4.0K	/tmp/ssh-631mJO0cQhCC
4.0K	/tmp/.X11-unix
4.0K	/tmp/.ICE-unix
du: cannot read directory ‘/tmp/pulse-PKdhtXMmr18n’: Permission denied
4.0K	/tmp/pulse-PKdhtXMmr18n
4.0K	/tmp/orbit-anthony
28K	/tmp
It even does the math for you, see the last line. And yes, it is including the contents of the directory it can not list the contents of.

If you want to see specific files, add a to the command line:

Code:
$ du -ah /tmp
0	/tmp/ssh-631mJO0cQhCC/agent.4405
4.0K	/tmp/ssh-631mJO0cQhCC
4.0K	/tmp/.X0-lock
0	/tmp/.X11-unix/X0
4.0K	/tmp/.X11-unix
0	/tmp/.ICE-unix/3900
0	/tmp/.ICE-unix/4405
4.0K	/tmp/.ICE-unix
du: cannot read directory ‘/tmp/pulse-PKdhtXMmr18n’: Permission denied
4.0K	/tmp/pulse-PKdhtXMmr18n
4.0K	/tmp/orbit-anthony
28K	/tmp

Last edited by goumba; 05-29-2014 at 03:10 PM. Reason: Added info about files
 
1 members found this post helpful.
Old 05-29-2014, 03:21 PM   #3
Enindu
Member
 
Registered: Apr 2014
Location: Colombo, Sri Lanka
Distribution: Arch Linux
Posts: 69

Rep: Reputation: 13
'ls' doesn't print the size of directories contents. Isn't it? Here's my ~/ directory with 'ls'. It says 148K.

Code:
total 148K
drwx------ 25 enindu users 4.0K May 29 22:13 .
drwxr-xr-x  3 root   root  4.0K May 16 15:46 ..
-rw-------  1 enindu users   54 May 29 22:13 .Xauthority
drwx------  3 enindu users 4.0K May 16 19:36 .adobe
drwxr-xr-x  3 enindu users 4.0K May 22 18:05 .archiso
-rw-------  1 enindu users 9.4K May 30 00:00 .bash_history
-rw-r--r--  1 enindu users   21 Apr 15 11:28 .bash_logout
-rw-r--r--  1 enindu users   57 May 26 21:17 .bash_profile
-rw-r--r--  1 enindu users  172 May 28 13:07 .bashrc
drwxr-xr-x  7 enindu users 4.0K May 27 14:56 .cache
drwx------  2 enindu users 4.0K May 29 19:13 .cmus
drwx------ 15 enindu users 4.0K May 29 19:15 .config
drwxr-xr-x  2 enindu users 4.0K May 18 13:48 .conky
-rw-rw-rw-  1 enindu users 1.6K May 28 22:31 .conkyrc
drwx------  3 enindu users 4.0K May 16 18:13 .dbus
-rw-------  1 enindu users   16 May 16 22:27 .esd_auth
drwx------  3 enindu users 4.0K May 17 00:14 .gnome2
-rw-r--r--  1 enindu users  595 May 28 22:29 .gtkrc-2.0
drwxr-xr-x  2 enindu users 4.0K May 28 23:11 .i3
-rw-------  1 enindu root   776 May 23 00:39 .i3status.conf
drwx------  3 enindu users 4.0K May 16 18:12 .icons
drwxr-xr-x  3 enindu users 4.0K May 16 16:01 .local
drwx------  3 enindu users 4.0K May 16 19:36 .macromedia
drwx------  4 enindu users 4.0K May 16 16:13 .mozilla
drwx------  3 enindu users 4.0K May 26 19:44 .pki
drwx------  3 enindu users 4.0K May 17 21:21 .thumbnails
drwx------  4 enindu users 4.0K May 27 15:02 .thunderbird
-rw-r--r--  1 enindu users  197 May 19 23:01 .xinitrc
-rw-------  1 enindu users    0 May 16 16:52 .xsession-errors
drwxr-xr-x  2 enindu users 4.0K May 16 16:13 Desktop
drwxr-xr-x  2 enindu users 4.0K May 30 00:59 Documents
drwxr-xr-x  3 enindu users 4.0K May 30 00:58 Downloads
drwxr-xr-x  4 enindu users 4.0K May 19 15:49 Other
drwxr-xr-x 10 enindu users 4.0K May 16 18:07 Pictures
drwxrwxrwx  7 enindu users 4.0K May 25 13:39 Temporary Files
drwxrwxrwx  2 enindu users 4.0K May 29 23:58 Working Desk
 
Old 05-29-2014, 04:59 PM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
You're right.
Code:
semoi@server:~/STORE1/sma_/info/clear/internet$ sudo du -hs /SDA6/
3.7M	/SDA6/
semoi@server:~/STORE1/sma_/info/clear/internet$
 
Old 05-29-2014, 05:19 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,567

Rep: Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865
In a nutshell it is the total number of blocks allocated for all files in that directory.
 
1 members found this post helpful.
Old 05-29-2014, 05:28 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,767

Rep: Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209
By default, blocks are assigned to the "resize inode" (inode 7) so that the block descriptor table can grow in the future. These blocks are considered "used" by df, but will not show up as assigned to any file. You can verify that usage by running "debugfs /dev/sda6" and typing "stat <7>" at the "debugfs: " prompt, e.g.:
Code:
debugfs /dev/sda6
debugfs:  stat <7>
Inode: 7   Type: regular    Mode:  0600   Flags: 0x0
Generation: 0    Version: 0x00000000:00000000
User:     0   Group:     0   Size: 4299210752
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 89944
Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x5387b0f2:00000000 -- Thu May 29 17:13:06 2014
 atime: 0x5387b0f2:00000000 -- Thu May 29 17:13:06 2014
 mtime: 0x5387b0f2:00000000 -- Thu May 29 17:13:06 2014
crtime: 0x5387b0f2:00000000 -- Thu May 29 17:13:06 2014
Size of extra inode fields: 28
BLOCKS:
(DIND):1544, (IND):3, (3084):32771, (3085):98307, (3086):163843, (3087):229379, (3088):294915,  ...
If you are sure you will not want to grow this filesystem in the future, you can turn off the feature and release the space:
Code:
tune2fs -O '^resize_inode' /dev/sda6
e2fsck -f /dev/sda6
The e2fsck is necessary because tune2fs just clears the feature's bit in the super block. The actual work is done by e2fsck. Note that once you have turned off this feature, you cannot turn it back on again without re-making the filesystem.
 
2 members found this post helpful.
Old 05-29-2014, 06:02 PM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by michaelk View Post
In a nutshell it is the total number of blocks allocated for all files in that directory.
Hence, it should be greater than or equal than that given by ls, in case this lists all files in the directory. Should it not?

Last edited by stf92; 05-29-2014 at 06:07 PM.
 
Old 05-29-2014, 06:15 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,567

Rep: Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865
Quote:
it should be greater than or equal than that given by ls
What is it?
 
Old 05-29-2014, 06:28 PM   #9
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by rknichols View Post
By default, blocks are assigned to the "resize inode" (inode 7) so that the block descriptor table can grow in the future. These blocks are considered "used" by df, but will not show up as assigned to any file. You can verify that usage by running "debugfs /dev/sda6" and typing "stat <7>" at the "debugfs: " prompt, e.g.:
Code:
debugfs /dev/sda6
debugfs:  stat <7>
Inode: 7   Type: regular    Mode:  0600   Flags: 0x0
Generation: 0    Version: 0x00000000:00000000
User:     0   Group:     0   Size: 4299210752
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 89944
Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x5387b0f2:00000000 -- Thu May 29 17:13:06 2014
 atime: 0x5387b0f2:00000000 -- Thu May 29 17:13:06 2014
 mtime: 0x5387b0f2:00000000 -- Thu May 29 17:13:06 2014
crtime: 0x5387b0f2:00000000 -- Thu May 29 17:13:06 2014
Size of extra inode fields: 28
BLOCKS:
(DIND):1544, (IND):3, (3084):32771, (3085):98307, (3086):163843, (3087):229379, (3088):294915,  ...
If you are sure you will not want to grow this filesystem in the future, you can turn off the feature and release the space:
Code:
tune2fs -O '^resize_inode' /dev/sda6
e2fsck -f /dev/sda6
The e2fsck is necessary because tune2fs just clears the feature's bit in the super block. The actual work is done by e2fsck. Note that once you have turned off this feature, you cannot turn it back on again without re-making the filesystem.
I understand. The first quantity is 4.2GB and the second one only 0.2GB. I'll see what the data I get are. Thank you.
 
Old 05-29-2014, 07:07 PM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,767

Rep: Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209
Oops. Looking at it again, I'm not sure just what to make of that "Size" value, and the "Blockcount" value appears to be in 512-byte sectors. I should have looked at the numbers more closely.
 
Old 06-05-2014, 08:35 AM   #11
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
ls will not show you removed files (still open in a process) but df will count that space.

ls is going to double-count file hardlinks unless you allow for this.
 
  


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
discrepancy between quota and du -sh ~ meirm Linux - Newbie 1 05-04-2014 10:10 PM
df vs du discrepancy DebianUser Linux - Hardware 3 09-12-2011 04:36 PM
Discrepancy df/du aztrix SUSE / openSUSE 5 01-12-2010 04:52 PM
Login Password Discrepancy sjreilly Linux - Security 0 07-27-2009 12:02 PM
x.org 6.9 discrepancy? bobbens Linux - Software 6 01-12-2006 06:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 09:25 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