Last active
August 29, 2015 14:05
-
-
Save ruckuus/284fb90a7bcd2b13710a to your computer and use it in GitHub Desktop.
Directory_Pair_To_Store_File_Size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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