質問

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
役に立ちましたか?

解決

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

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top