[英]Displaying Last modification date
I need to display file's name, size, number of hard links, owner, and modify date (in that order). 我需要显示文件的名称,大小,硬链接数,所有者和修改日期(按此顺序)。
#!/bin/csh
echo Enter file name
set filename = $<
if(-f $filename)then
if(-z $filename)then
rm $filename
else
clear
echo $filename
stat -c %s $filename
stat -c %h $filename
stat -c %U $filename
stat -c %y $filename
endif
endif
Everything works (I think) except it shows more than just the date. 我认为,所有功能都可以正常工作,除了显示的不仅仅是日期。 What command would I use to just display the date of last modification?
我将使用什么命令仅显示上次修改的日期?
See the man stat
. 参见
man stat
。
You need to use a
, m
, c
or B
which gives the time file was last accessed or modified. 你需要使用
a
, m
, c
或B
这给时间上次访问文件或修改。
It seems you are looking for this: 看来您正在寻找:
stat -c %y $filename
Or this: 或这个:
date -r $filename
Or this (most portable): 或此(最便于携带):
fn=$filename perl -e 'print scalar localtime((stat("$ENV{fn}"))[9])'
On the other hand, stat -c %y
was already in your post, and you wrote: 另一方面,
stat -c %y
已经在您的帖子中,您写道:
Everything works (I think) except it shows more than just the date.
我认为,所有功能都可以正常工作,除了显示的不仅仅是日期。 What command would I use to just display the date of last modification?
我将使用什么命令仅显示上次修改的日期?
Which makes me think that perhaps you want only the date part? 这让我认为也许您只想要日期部分? One (lazy) solution for that is using shell commands like
cut
, awk
, sed
to extract just what you need, for example: 一种(惰性)解决方案是使用诸如
cut
, awk
, sed
类的shell命令来提取所需的内容,例如:
$ stat -c %y sample.txt
2013-10-12 09:24:08.096820646 -0700
$ stat -c %y sample.txt | cut -f1 -d' '
2013-10-12
A better solution is to generate dates in the desired format, but that depends on the command you used. 更好的解决方案是以所需的格式生成日期,但这取决于您使用的命令。 For example
stat
cannot do this, but date
and perl
can, for example: 例如,
stat
无法做到这一点,但是date
和perl
可以,例如:
date +%Y-%m-%d -r $filename
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.