使用shell在目录下检索文件以及上次修改日期

时间:2013-10-19 14:11:52

标签: shell awk

我正在尝试检索(unix)目录中的文件列表,我想检索文件以及修改日期

ls -LR为我检索文件,但我需要单独修改日期,我该怎么做?

2 个答案:

答案 0 :(得分:1)

使用tree

tree -D

引自man tree

  

-D打印上次修改时间的日期,或者如果使用-c,则列出所列文件的最后状态更改时间。

测试

% tree -D
.
|-- [Oct 19 20:20]  dir1
|   |-- [Oct 19 19:49]  file1
|   |-- [Oct 19 19:49]  file2
|   `-- [Oct 19 19:49]  file3
`-- [Oct 19 20:20]  dir2
    |-- [Oct 19 20:20]  file1
    |-- [Oct 19 20:20]  file2
    `-- [Oct 19 20:20]  file3

2 directories, 6 files

使用ls后跟awk

ls -lR | awk '$9 {print $6, $7, $8, $9}'

测试

% ls -lR | awk '$9 {print $6, $7, $8, $9}'
Oct 19 19:49 file1
Oct 19 19:49 file2
Oct 19 19:49 file3

答案 1 :(得分:0)

使用find -type f -printf "<whatever>"打印文件名以及修改日期或您想要了解的有关该文件的任何其他内容。 man find

相关问题