using du command

Hi,

is there a way to use "du" command without going in all the subtree ?

i have a dir called "rep" for exemple with many subdir as rep1;rep2;rep3 and so on.

I would calculate the "rep" size without having to calculate all the subdir.
Is it possible to do that without doing:

du -k rep|grep rep

thanks in advance
Christian

du -sh /path/to/rep

Hope this helps...:slight_smile:

thanks

on my AIX server the flag "h" is not valid , what does it mean ?

regards
Christian

Formats the output 'human readable' example: 1.2TB or 56GB instead of a massive number.

h stands for human-readable.

"-h" is "human readable" on Linux systems (which nowadays usually means "display in Gigabytes").

On AIX systems you could use "-k" instead to get the values displayed in units of kilobytes or nothing at all to get bytes. The important part is the flag "-s", which traverses subdirectories and sums up recursively all the content there.

The value displayed for "/some/dir" is the sum of all the files in "/some/dir" plus all the files and sums of subdirs in "/some/dir/subdir1" plus the all the files and sums of subdirs in "/some/dir/subdir2", etc..

If you need to convert this to MBs (GBs, ...) use "bc" and divide by 1024 (repeatedly).

For instance:

# du -ks /home/bakunin
58829668        /home/bakunin   # <= in KBs

# print - "58829668/1024" | bc
57450                           # <= in MBs

# print - "58829668/1024/1024" | bc
56                              # <= in GBs

I hope this helps.

bakunin

1 Like

Thanks

but there's no way to count the "rep" dir without going through subdir ?

i hope no

Christian

With -x

-x When evaluating file sizes, evaluates only those files that reside on the same device as the file or directory specified by the File parameter. For example, you may specify a directory that contains files on several devices. In this case, the -x flag displays block sizes for all files that reside on the same device as the directory.

cd /path/to/rep
du -sk .

or

du -sk /path/to/rep

Below command counts only the disk usage of rep and not its sub-directory..

find /path/to/rep -maxdepth 1 -type f -exec du -hs {} \; | awk '{i=$1+i} END {print i}'

thanks for your help,

the maxdepth doesn't work on AIX machine....

regards
Christian

hmm.. try to search this forum or other external sites for the equivalent of maxdepth in AIX. I could find this post quite relevant.

thanks

i think this is a good way to search

Christian

Without the "-s" flag "du" works non-recursively, therefore, to get the disk usage of all the files in "/the/directory/rep" issue:

du /the/directory/rep/*

(and add "-k" if you want it in Kilobytes instead of bytes)

I hope this helps.

bakunin