Monday, April 3, 2017

Bash: Scripting - part 2 - File Info

#!/bin/bash
#
#  fileinfo.sh
MYFILES="/auto/home/homeb/d54712/sandbox/scripts/bash.d/read1.sh
/auto/home/homeb/d54712/sandbox/scripts/data.d/states
/auto/home/homeb/d54712/sandbox/scripts/data.d/states12345"
     # List of files you are curious about
                                                                #Threw in in a dummy file, /auto/home/homeb/d54712/sandbox/scripts/bash.d/states12345
#

echo
for file in $MYFILES
do
        if [ ! -e "$file" ]
        then
                echo "$file does not exist."
                continue
        fi


        ls -l $file |awk '{ print "Filename: " $9 "\n" "Timestamp: " $8"\n" "File size: " $5"\n" }' # print 3 fields

        echo

done
exit 0




Results:

$ ./fileinfo.sh
Filename: /auto/home/homeb/d54712/sandbox/scripts/bash.d/read1.sh
Timestamp: 14:23
File size: 126

Filename: /auto/home/homeb/d54712/sandbox/scripts/data.d/states
Timestamp: 15:30
File size: 78

/auto/home/homeb/d54712/sandbox/scripts/data.d/states12345 does not exist.

No comments:

Post a Comment