I was going through a tutorial on the latest Linux Shell Handbook for Linux Pro mag and I am having trouble getting this block of code to work. When I run the script it tells me that du and awk commands are not found.


. /usr/local/sbin/functions.bash

printf "USER\tGB USED\n"
for WHO in $(</user/local/sbin/chusers); do
    HOMESUM=`eval du -s -$WHO |awk '{print $1}'`
    TMPLIST=$( ls -lR --block-size 1024 $(</user/local/bin/chdirs) | egrep "^.......... +[0-9]+ $WHO" | awk '{print $5}' )
    for N in $TMPLIST; do
        TSUM=$(( $TSUM+$N ))
    TOT=$(( $HOMESUM+$TSUM ))
    to_gb $WHO $TOT

Here is the to_gb function from function.bash

        local MB D1 D2 USER
        MB=$(( $2/1024))
        D1=$(( $MB/1000))
        D2=$(( $MB-($D1*1000) ))
        printf "%s\t%s\n" $USER $D1.${D2:0:1}

I have been able to run each command du -s ~username and awk '{ print $1 }' from the command line with no problem and seen the expected output but the script fails to work.

  • also chusers and chdirs is a flat file containing usernames and directories to check. – Jeff Beougher Aug 6 '17 at 18:45
  • The to_gb() function seems rather limited. I like to use this function that converts the file size to Bytes, KiB, MiB, GiB, TiB, EiB, PiB, YiB and ZiB. – WinEunuuchs2Unix Aug 6 '17 at 19:20
  • 1
    I see some really horrible stuff in Linux magazines tbh. Better you reformulate your question by writing a description of specifically what you want to do, and what help you need with that, otherwise we are all going to pick holes in the script in the comments, without really knowing what the desired output is, instead of giving you a useful answer (although Florian Diesch's answer should solve the painfully obvious issue causing the command not found errors...) – Zanna Aug 6 '17 at 19:25

should be


Both awk and du are in /usr/bin:

$ type -p du;type -p awk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.