df reports file system disk space usage. Thus, given an argument, FILE, it will report the disk space usage of the filesystem containing FILE. Note that it is not reporting the disk space usage of the directory represented by FILE.
du on the other hand, given an argument FILE, reports the disk space usage of the directory represented by FILE. Presumably, it performs a recursive directory traversal of FILE adding the reported size of each file until the traversal is complete. In contrast with df, du may potentially report cumulative file sizes from files on multiple filesystems.
But, to answer your question more directly--it is best to use du. In many cases (depending on the number of files in the directory represented by FILE), du will take many times longer to execute than df due to the aforementioned directory traversal so expect to wait a little.
du reports usage for the files in directories, while df reports on the filesystem itself. Filesystem overhead like a journal, allocation tables, etc. that take space on the filesystem will show as being used by df, but will not show with du, as they are not userspace accessible. Make a new, empty filesystem and du will should nothing but the cluster(s) for the directory(ies) in it, where df will show only the userspace accessible files on the filesystem.
example of a 2G drive ext3, so journal and lost+found directory:
the same with mkfs.vfat (no journal, small allocation table, smaller allocation of for the single directoy):
My guess is that you've got 200M worth of journal and filesystem allocation information, so you show 1.7G on df (1.7 GB of files) and 1.9G on du (1.7 + 200M filesystem stuff)
Good Morning,
What's a good way to get partition/slice sizes down to the byte on Solaris 9? I've tried a few ways, but only see results like 8.21GB which rounds the number.
Thanks! (5 Replies)
Hi ,
I'm trying to list the files and output is written to a file. But when I execute the command , the output file is being listed. How to exclude it ?
/tmp
file1.txt
file2.txt
ls -ltr |grep -v '-' | awk print {$9, $5} > output.txt
cat output.txt
file1.txt
file2.txt
output.txt (8 Replies)
Hi everyone!
I need to compare two file sizes.
One of them (size) will be stored in a flat file and the other coming from a listed file.
I can now get the first file size using:
SIZE=`ls -l $DOCTYPE | awk '{print $5}'`
1. How can I store this value in a flat file?
2. How... (2 Replies)
I have 2 big files in the size of gb. They are same with respect to content, both are “,” delimited. Now both of them are created by two different processes but has the same logic. The problem is they are differing only in few bytes for e.g one file is 202195751 bytes other is 202195773. So... (2 Replies)
Hello everyone,
can anybody help me in finding a way to obtain a list of all the directories and their sizes.
I would like to be able to run this and obtain an output like a tree structure with each branch saying how much space it is taking up .
Hope you can point me in the right direction.... (1 Reply)
I have the following script:
#!/usr/bin/ksh
export MDIR=/datafiles
NAME=$1
SERVER=$2
DIRECTORY=$3
DATABASE=$4
ID=$5
export dirlist=`/usr/bin/ssh -q $ID@$SERVER find $DIRECTORY -type d -print`
for dir in $dirlist
do
SIZE=`</dev/null /usr/bin/ssh -q $ID@$SERVER du -ks $dir`
echo... (6 Replies)
Hello every one,
Iam newbie to this forum and shell programming &scripting.
i needed to compare each and every folder of two separate servers.
Actually I have copied some directory structure from one server to second server, to build on second server the files all should be copied... (3 Replies)
Hi, Need help for a Script for checking and reporting database file sizes in a directory.
Request you to please give your valuable inputs.
Thanks a lot in advance.
Best Regards,
Marconi (1 Reply)
Hi I need to take a list of files that are defined by an ls -ltr or grep for particular file names - and add up the byte size colum which is field 5 seperated by a space.
I tried to do this but I think I am way off:
for file in 'ls -ltr | grep 20070916 | nawk -F" " '{temp+=5} END {print... (1 Reply)
Can someone tell me how to read these damn sizes.
i mean, i prefer to see sizes in MB but that is not the case when you do an ls -l on directories. i have a had time converting these to MB
just for verification purposes, what would a directory size like this = 3499990308 represent in MB
or... (3 Replies)