如何获得时间,因为文件最后以秒为单位修改使用bash? [英] How to get time since file was last modified in seconds with bash?

查看:117
本文介绍了如何获得时间,因为文件最后以秒为单位修改使用bash?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在几秒钟时间,因为一个文件的最后修改。 的ls -l <​​/ code>不显示它。

I need to get the time in seconds since a file was last modified. ls -l doesn't show it.

推荐答案

在Linux中,日期-r文件时打印文件的最后修改日期:

In Linux, date -r file prints the date when the file was last modified:

date +%s -r file.txt

要打印自上次修改后经过的秒,你可以使用 EXPR 以秒当前日期减去最后修改日期:

To print the seconds elapsed since the last modification, you can use expr with the current date in seconds minus the date of the last modification:

expr $(date +%s) - $(date +%s -r file.txt)

在Mac OS X中(日期BSD的味道),这是不行的,你需要使用统计其他答案指出。

In Mac OS X (BSD flavor of date) this won't work, you'd need to use stat as other answers pointed out.

这篇关于如何获得时间,因为文件最后以秒为单位修改使用bash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆