Hi ,
In a folder I have multiple files. I want total time taken to write those files. Can you please suggest what will be the best way to go for it?
Hi ,
In a folder I have multiple files. I want total time taken to write those files. Can you please suggest what will be the best way to go for it?
Do you have control over the process that creates those multiple files? If yes then you can add something like this in the code.
At the start of the script:
startsec=$(date +%s)
At the end of the script:
endsec=$(date +%s)
duration=$(expr $endsec - $startsec)
echo $duration
---------- Post updated at 10:46 AM ---------- Previous update was at 10:16 AM ----------
In case you need to find the difference between first file and last file in a directory, below script can be used.
DIR=/your/directory
first_ts=$(ls -lt $DIR | tail -1 | awk '{print $8}')
last_ts=$(ls -ltr $DIR | tail -1 | awk '{print $8}')
first_mm=$(echo $first_ts | cut -d":" -f 1)
first_ss=$(echo $first_ts | cut -d":" -f 2)
last_mm=$(echo $last_ts | cut -d":" -f 1)
last_ss=$(echo $last_ts | cut -d":" -f 2)
first_totsec=$(expr $first_mm \* 60 + $first_ss)
last_totsec=$(expr $last_mm \* 60 + $last_ss)
duration=$(expr $last_totsec - $first_totsec)
if [ $duration -gt 60 ]
then
echo "\n" Diff between first and last file mtime: $(echo $duration | awk '{printf("%2d min %2d sec",$1/60,$1%60)}') "\n"
else
echo "\n Diff between first and last file mtime: $duration seconds.\n"
fi
Hi ,
it's the 2nd one.
What will happen when files are created in different dates?
Can you somehow handle this through epoc? is there any way to get the epoc time of the file created?