'stat' vs 'date' w/re string manipulation in Bash scripts
I started browsing the Web tonight looking to do something I had been doing in my Bash scripts with stat and three more lines of string cutting in one line instead.
I had been using stat -c &y file to get a file's modification date in scripts, but I have never liked the nine-digit "blink-of-an-eye" part of the return on that command. My method up till now has been to eliminate it with lines like these:
After reading this post, I looked at the (ostensibly generic) date manual page on linux.die.net, and skimmed through the other format flags, if that's the right name for them, to see if there were any that returned the time and UTC offset (again, not sure of my terms, but it sounds right). After a bit of trial and error, I came up with this code:
which returns the date of a file in the same format as stat -c &y file does, but without that string of nine extra numbers, which reminds me of nothing so much as the real-time duration of some of the highest-numbered elements on the Periodic Table -- that is, when it's not all zeros.
I hope this gets spidered by the search engines. I'd love to help someone out with the above advice and tips, abstruse as they might be.
BZT
I had been using stat -c &y file to get a file's modification date in scripts, but I have never liked the nine-digit "blink-of-an-eye" part of the return on that command. My method up till now has been to eliminate it with lines like these:
Code:
gdate=$(stat -c %y foo.jpg) pqdate=$(echo ${gdate%.*}) rdate=$(echo ${gdate##* }) mdate=$(echo -e "$pqdate $rdate")
Code:
date -r foo.jpg "+%F %T %z"
I hope this gets spidered by the search engines. I'd love to help someone out with the above advice and tips, abstruse as they might be.
BZT
Total Comments 0