在 linux 终端中,如何显示文件夹的上次修改日期,同时考虑其内容? [英] in linux terminal, how do I show the folder's last modification date, taking its content into consideration?

查看:17
本文介绍了在 linux 终端中,如何显示文件夹的上次修改日期,同时考虑其内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这就是交易.假设我有一个名为web"的目录,所以

So here's the deal. Let's say I have a directory named "web", so

$ ls -la

drwx------  4 rimmer rimmer 4096 2010-11-18 06:02 web

但是在这个目录里面,web/php/

BUT inside this directory, web/php/

$ ls -la

-rw-r--r-- 1 rimmer rimmer 1957 2011-01-05 08:44 index.php

这意味着即使我的目录/web/php/index.php 的内容最后修改时间为 2011-01-05,但/web/目录本身报告为最后修改时间为 2010-11-18.

That means that even though the content of my directory, /web/php/index.php has been last modified at 2011-01-05, the /web/ directory itself is reported as last modified at 2010-11-18.

我需要做的是将我的/web/目录的最后修改日期报告为该目录中任何文件/目录的最新修改日期,递归.

What I need to do is have my /web/ directory's last modification date reported as the latest modification date of any file/directory inside this directory, recursively.

我该怎么做?

推荐答案

类似:

find /path/ -type f -exec stat {} --printf="%y
" ; | 
     sort -n -r | 
     head -n 1

说明:

  • find 命令将递归地忽略目录打印每个文件的修改时间(根据 IQAndreas 的评论,您不能依赖文件夹时间戳)
  • sort -n(数字)-r(反向)
  • head -n 1:获取第一个条目

这篇关于在 linux 终端中,如何显示文件夹的上次修改日期,同时考虑其内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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