change the output format for time command

If you are doing some scripting and using ‘time’ command, then you know sometimes it becomes difficult to capture the output as the output would be something like this:

: amit ; time ls

real    0m0.002s
user    0m0.000s
sys 0m0.001s

So, it is better to change that format. Here is simple example:

1
 
TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls
amit ;  TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls
0.00user 0.00system 0:00.00elapsed 0%CPU (0text+0data 2432max)
0inputs+0outputs (0major+109minor)pagefaults 0swaps
amit ; TIMEFORMAT=’real %3R user %3U sys %3S’
amit ; time ls
real 0.001 user 0.001 sys 0.000
amit ;
amit ; TIMEFORMAT=’TIMEOUTPUT = real %3R user %3U sys %3S’
amit ; time ls
TIMEOUTPUT = real 0.001 user 0.001 sys 0.000
amit ;

image ordering by Original Date Time using bash script

Here is the script:

#!/bin/bash -
#===============================================================================
#
#          FILE: imgOrg.sh
#
#         USAGE: ./imgOrg.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka)
#      REVISION:  ---
#===============================================================================

for i in *
do
    if [[ $(file $i) == *image* ]] 
    then
        echo "Image file is :: $i"
        dir=$( exiftool -s -DateTimeOriginal $i | awk -F':' '{print $2"/"$3}')
        mkdir -p $dir
        cp $i $dir/
    else
        echo "Excluding $i"
    fi
done

 

Script looks at the DateTimeOriginal parameter in output of exiftools ( which is basically the date and time image was taken) and then puts the images in the folder in format YYYY/MM.

How to verify sha256sum for multiple file or one file.

So, lets say you have downloaded the SHA256SUMS files. This file contains the sha256sum for multiple files and you want to compare the values for only one or some of them, then the simplest thing you can do is:

sha256sum -c SHA256SUMS

Now, with this if you do not have some files present then you might get some errors and if you do not want that, then you can try this:

grep <filename> SHA256SUMS|tee /proc/self/fd/2|sha256sum --check -

And now if you have some files under some subdirectories as well and you want to generate the SHA256SUMS file, then the simplest is to use this:

sha256sum $(find . -type f -exec echo {} \+ )
###OR
sha256sum $(find . -type f)