Question
How do I return a date of a file? Something like this does not work and it is ugly too.
ls -l tz1.sql | awk '{print $7$6 $8}'
7Jun10:00
Solution
You can use stat
to get the modification time, access time, or metadata change time of a file. Creation time is not recorded.
$ stat -c '%y' t.txt
2011-09-30 11:18:07.909118203 -0400
OTHER TIPS
use commas to separate the fields:
ls -l tz1.sql | awk '{print $7, $6, $8}'
When awk reads an input line, this line is split on the field separator FS. Thus you have to put those field separators back in, when you print the line. "," stands for those FSs.
EDIT:
If you want to use the variant with Ignacio Vazquez, try:
stat -c "%y" s.awk | cut -d. -f1
Output:
2011-09-30 22:44:46
HTH Chris
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow