[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Problem with the global weigh of several files



>> On Thu, 26 May 2011 17:12:25 +0200, 
>> "Gorka" <gorkalinux@yahoo.es> said:

G> I am looking for the best way of appending commands to obtain the global
G> amount of Mb of the modified files of my PC.  Something like this:
G> find ./ -mtime -7 | du -Sch

#!/bin/ksh
# filesize summary; optional argument is starting directory.
export PATH=/usr/local/bin:/bin:/usr/bin

case "$1" in
    "") dir="$HOME" ;;
    *)  dir="$1" ;;
esac

test -d "$dir" || { echo "$dir: not a directory"; exit 1; }
cd $dir        || { echo "$dir: cannot cd"; exit 2; }
dir=$(pwd)

find . -type f -mtime -7 -printf "%s\n" | gawk -v "d=$dir" \
     'BEGIN { size = 0; }
     { size += $1; }
     END {
       printf "%s: %d new files using %.1f Mb\n", d, NR, size/1048576;
     }'

exit 0

-- 
Karl Vogel                      I don't speak for the USAF or my company

Men are like a fine wine.  They start out as grapes and it's up to women
to stomp the sh*t out of them until they turn into something acceptable
to have with dinner.


Reply to: