在 Bash 中打印文件的上次修改日期 [英] Print a file's last modified date in Bash
本文介绍了在 Bash 中打印文件的上次修改日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎找不到如何打印文件日期的方法.到目前为止,我能够打印出目录中的所有文件,但我需要用它打印出日期.
我知道我需要在条目的回显中附加日期格式,但我找不到正确的格式.
echo "请输入要列出所有文件的目录"读取目录用于$目录"中的条目/*做回声$条目"完毕
解决方案
您可以使用stat
命令
stat -c %y "$entry"
更多信息
<前>%y 上次修改时间,人类可读I can't seem to find how to print out the date of a file. I'm so far able to print out all the files in a directory, but I need to print out the dates with it.
I know I need to attach a date format with the echo of the entry, but all I can't find the correct format.
echo "Please type in the directory you want all the files to be listed"
read directory
for entry in "$directory"/*
do
echo "$entry"
done
解决方案
You can use the
stat
command
stat -c %y "$entry"
More info
%y time of last modification, human-readable
这篇关于在 Bash 中打印文件的上次修改日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文