Hello, du of lastlog reports 120K size ls of lastlog reports 38M [root@c-106 root]# du -sh /var/log/lastlog 120K /var/log/lastlog [root@c-106 root]# ls -lah /var/log/lastlog -rw-r--r-- 1 root root 38M Dec 30 13:30 /var/log/lastlog
Why du and ls reporting differnt size of the same file?
Thanks
Regards,
Komal
---------------------------------------------------------------- This message was sent using NWebmail, BSNL's Webmail Program
On Friday 30 December 2005 13:04, agencies_ad1@sancharnet.in wrote:
Hello, du of lastlog reports 120K size ls of lastlog reports 38M [root@c-106 root]# du -sh /var/log/lastlog 120K /var/log/lastlog [root@c-106 root]# ls -lah /var/log/lastlog -rw-r--r-- 1 root root 38M Dec 30 13:30 /var/log/lastlog
Why du and ls reporting differnt size of the same file?
very interesting indeed. I checked out man du and I found a switch which would give me the exact size as ls -lh gave.
[basix@linuxbox log]$ du -h lastlog 52K lastlog
[basix@linuxbox log]$ ls -lh lastlog -r-------- 1 root root 19M Dec 30 18:08 lastlog
[basix@linuxbox log]$ du -h --apparent-size lastlog 19M lastlog
Here is what man had to say about the --apparent-size switch:
--apparent-size print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in (‘sparse’) files, internal fragmentation, indirect blocks, and the like.
Wikipedia didn't have anything significant to tell me either.
Experts, please clarify!
On Fri, Dec 30, 2005 at 07:42:03PM +0000, Dinesh Joshi wrote:
On Friday 30 December 2005 13:04, agencies_ad1@sancharnet.in wrote:
Hello, du of lastlog reports 120K size ls of lastlog reports 38M [root@c-106 root]# du -sh /var/log/lastlog 120K /var/log/lastlog [root@c-106 root]# ls -lah /var/log/lastlog -rw-r--r-- 1 root root 38M Dec 30 13:30 /var/log/lastlog
Why du and ls reporting differnt size of the same file?
Experts, please clarify!
du operates on blocks. du -b gives the right size in bytes.
On Saturday 31 Dec 2005 5:16 am, Dinesh Joshi wrote:
du operates on blocks. du -b gives the right size in bytes.
That explains it... But why is there such a large difference between size reported in blocks and that reported by bytes?
duh ;-)
Quoting Dinesh Joshi dinesh.a.joshi@gmail.com:
On Friday 30 December 2005 15:57, Satya wrote:
du operates on blocks. du -b gives the right size in bytes.
That explains it... But why is there such a large difference between size reported in blocks and that reported by bytes?
The size of the file /var/log/lastlog can appear to be overly large on some systems, most especially in 64 bit architectures.
This file is what we call a sparse file. A sparse file is a file that contains unallocated blocks or "empty space", as it implies, it does not actually take up filesystem space. To test this theory, execute the following command:
du -H /var/log/lastlog 6.0MB /var/log/lastlog
Here the file is reported to be only ~6MB. This is the actual disk space the file is taking up. The lastlog file only records data for users that have logged in.
An important point to note when operating with sparse files is that certain tools do have built-in functionality to deal with these types of files. For example cp, tar and rsync. See the man page for each of those commands for further information.
Regards,
Komal
---------------------------------------------------------------- This message was sent using NWebmail, BSNL's Webmail Program