Search This Blog

Shell scripts to count files and sum up file sizes

#!/bin/sh
[ $# -ne 1 ] && echo "$(basename $0) <dir>" && exit 1
[ ! -d $1 ] && echo "$1 is not a directory." && exit 1
find "$1" -type f | wc -l
#!/bin/sh
[ $# -ne 1 ] && echo "$(basename $0) <dir>" && exit 1
[ ! -d $1 ] && echo "$1 is not a directory." && exit 1
if [ $(uname) == "Darwin" ]; then
find "$1" -type f -print0 | xargs -0 stat -f '%z ' | paste -sd+ - | bc
else
find "$1" -type f -printf %s\\n | paste -sd+ | bc
fi

No comments:

Post a Comment