Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Stat命令在管道和无管道中使用时返回不同的修改日期_Bash - Fatal编程技术网

Bash Stat命令在管道和无管道中使用时返回不同的修改日期

Bash Stat命令在管道和无管道中使用时返回不同的修改日期,bash,Bash,使用时 stat-f“%Sm”-t“%Y%m%d%H%m”测试/0025-05-026-107339_14.PDF 返回finder中显示的修改日期(此处:201611110137) 但是,为了获取目录中的最新文件而进行管道传输时;像 ls-t$dir/0025-05*.PDF | head-1 | stat-f“%Sm”-t“%Y%m%d%H%m” 返回系统时间(此处:201701061146),即使 ls-t$dir/0025-05*.PDF | head-1 返回相同的文件(test/00

使用时

stat-f“%Sm”-t“%Y%m%d%H%m”测试/0025-05-026-107339_14.PDF

返回finder中显示的修改日期(此处:201611110137)

但是,为了获取目录中的最新文件而进行管道传输时;像

ls-t$dir/0025-05*.PDF | head-1 | stat-f“%Sm”-t“%Y%m%d%H%m”

返回系统时间(此处:201701061146),即使

ls-t$dir/0025-05*.PDF | head-1

返回相同的文件(test/0025-05-026-107339_14.PDF)


我错了什么?

您的
stat
语句似乎有点奇怪,但除此之外,管道为我返回
stat:missing operand
。我的理论是管道实际上并没有将文件本身提供给
stat
,只是一个包含文件名的字符串,文件名是动态生成的,这就是系统时间返回的原因。我会尝试使用命令替换替换管道,如下所示:

stat-f“%Sm”-t“%Y%m%d%H%m”$(ls-t$dir/0025-05*.PDF | head-1)

至少它用了一个格式稍有不同的
stat
命令来帮我搞定了。

stat(GNU coreutils)8.5给出了以下两个错误:
stat:无法读取“%Sm”的文件系统信息:没有这样的文件或目录
stat:无法读取“%Y%m%d%H%m”的文件系统信息:没有这样的文件或目录