Skip to content

Instantly share code, notes, and snippets.

@ruckuus
Last active August 29, 2015 14:05
Show Gist options
  • Save ruckuus/284fb90a7bcd2b13710a to your computer and use it in GitHub Desktop.
Save ruckuus/284fb90a7bcd2b13710a to your computer and use it in GitHub Desktop.
Directory_Pair_To_Store_File_Size
#!/usr/bin/env bash
[[ -z $1 ]] && echo "Please provide source directory" && exit -1
SOURCE=$1
DSTDIR=${SOURCE}.size
FILES=$(find $SOURCE -type f -not -user root -print | tr "\n" ",")
gen_file_size() {
SRCFILE="$1"
SRCDIR=$(dirname "$SRCFILE")
SRCFILENAME=$(basename "$SRCFILE")
SIZ=$(du -s "$SRCFILE" | awk '{print $1}')
DSTFILENAME=$(echo $SRCFILENAME | sed "s/\.txt//g")
DSTDIRPHYS=$(echo $SRCDIR | sed "s/${SOURCE}/${DSTDIR}/g")
mkdir -p $DSTDIRPHYS
touch $DSTDIRPHYS/${DSTFILENAME}.size
echo $SIZ > $DSTDIRPHYS/${DSTFILENAME}.size
}
IFS=$','
for f in $FILES ;do
echo $f
gen_file_size $f
done
unset IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment