如何递归地查找和列出包含子目录和时间的目录中的最新修改文件?

时间:2021-04-16 15:05:23
  • Operating system: Linux

    Linux操作系统:

  • Filesystem type: ext3

    ext3文件系统类型:

  • Preferred solution: bash (script/oneliner), ruby, python

    首选解决方案:bash(脚本/oneliner)、ruby、python。

I have several directories with several subdirectories and files in them. I need to make a list of all these directories that is constructed in a way such that every first-level directory is listed next to the date and time of the latest created/modified file within it.

我有几个目录,其中有几个子目录和文件。我需要列出所有这些目录的列表,以这样的方式构造每个一级目录,在它的最新创建/修改文件的日期和时间旁边列出。

To clarify, if I touch a file or modify its contents a few subdirectory levels down, that timestamp should be displayed next to the first-level directory name. Say I have a directory structured like this:

要澄清的是,如果我触摸一个文件或修改它的目录下的一些子目录级别,那么时间戳应该显示在一级目录名旁边。比如我有一个这样的目录:

./alfa/beta/gamma/example.txt

and I modify the contents of the file example.txt, I need that time displayed next to the first-level directory alfa in human readable form, not epoch. I've tried some things using find, xargs, sort and the likes but I can't get around the problem that the filesystem timestamp of 'alfa' doesn't change when I create/modify files a few levels down.

我修改了文件示例的内容。txt,我需要那个时间显示在人类可读形式的一级目录alfa,而不是纪元。我已经尝试了一些使用find、xargs、sort和like的东西,但是我无法解决这个问题:当我创建/修改文件时,“alfa”的文件系统时间戳不会发生变化。

16 个解决方案

#1


349  

Try this one:

试试这个:

#!/bin/bash
find $1 -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2- | head

Execute it with the path to the directory where it should start scanning recursively (it supports filenames with spaces).

执行它的路径到它应该开始扫描的目录(它支持空格的文件名)。

If there are lots of files it may take a while before it returns anything. Performance can be improved if we use xargs instead:

如果有很多文件,它可能需要一段时间才能返回任何东西。如果我们使用xargs,性能可以得到改善:

#!/bin/bash
find $1 -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head

which is a bit faster.

这有点快。

#2


131  

To find all files that file status was last changed N minutes ago:

为了找到所有文件,文件状态最后更改N分钟前:

find -cmin -N

找到-cmin - n

for example:

例如:

find -cmin -5

找到-cmin 5

#3


32  

I shortened halo's awesome answer to this one-liner

我缩短了halo的精彩答案。

stat --printf="%y %n\n" $(ls -tr $(find * -type f))

Updated: If there are spaces in filenames, you can use this modification

更新:如果文件名中有空格,可以使用这个修改。

OFS="$IFS";IFS=$'\n';stat --printf="%y %n\n" $(ls -tr $(find . -type f));IFS="$OFS";

#4


29  

GNU Find (see man find) has a -printf parameter for displying the files EPOC mtime and relative path name.

GNU Find(见man Find)有一个-printf参数,用于显示文件EPOC mtime和相对路径名。

redhat> find . -type f -printf '%T@ %P\n' | sort -n | awk '{print $2}'

#5


11  

Try this

试试这个

#!/bin/bash
stat --format %y $(ls -t $(find alfa/ -type f) | head -n 1)

It uses find to gather all files from the directory, ls to list them sorted by modification date, head for selecting the 1st file and finally stat to show the time in a nice format.

它使用find来收集目录中的所有文件,ls将它们按修改日期排序,头用于选择第一个文件,最后以一个良好的格式显示时间。

At this time it is not safe for files with whitespace or other special chars in their names. Write a commend if it doesn't meet your needs yet.

此时,对于带有空格或其他特殊字符的文件,其名称是不安全的。如果它还不能满足你的需要,写一个推荐信。

#6


7  

This command works on Mac OS X:

这个命令在Mac OS X上运行:

find "$1" -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head

查找“$1”-type f -print0 | xargs -0 stat—format '%Y:% Y %n' | sort -nr | cut -d: -f2- |头。

On Linux, as the original poster asked, use stat instead of gstat.

在Linux上,正如最初的海报所要求的,使用stat代替gstat。

This answer is, of course, user37078's outstanding solution, promoted from comment to full answer. I mixed in CharlesB's insight to use gstat on Mac OS X. I got coreutils from MacPorts rather than homebrew, by the way.

这个答案当然是user37078的优秀解决方案,从评论到完整的答案。我把CharlesB的insight混合到Mac OS x上使用gstat,顺便说一下,我从MacPorts获得了coreutils,而不是homebrew。

And here's how I packaged this into a simple command ~/bin/ls-recent.sh for reuse:

下面是我如何把它打包成一个简单的命令~/bin/ls-最近。sh重用:

#!/bin/bash
# ls-recent: list files in a dir tree, most recently modified first
#
# Usage: ls-recent path [-10 | more]
# 
# Where "path" is a path to target directory, "-10" is any arg to pass
# to "head" to limit the number of entries, and "more" is a special arg
# in place of "-10" which calls the pager "more" instead of "head".
if [ "more" = "$2" ]; then
   H=more; N=''
else
   H=head; N=$2
fi

find "$1" -type f -print0 |xargs -0 gstat --format '%Y :%y %n' \
    |sort -nr |cut -d: -f2- |$H $N

#7


5  

Both the perl and Python solutions in this post helped me solve this problem on Mac OS X: https://unix.stackexchange.com/questions/9247/how-to-list-files-sorted-by-modification-date-recursively-no-stat-command-avail.

这篇文章中的perl和Python解决方案都帮助我在Mac OS X上解决了这个问题:https://unix. stackexchange.com/questions/9247/howto -list-files- by- modificationdate -recursively-no-stat-command-。

Quoting from the post:

从《华盛顿邮报》引用:

Perl:

Perl:

find . -type f -print |
perl -l -ne '
    $_{$_} = -M;  # store file age (mtime - now)
    END {
        $,="\n";
        print sort {$_{$b} <=> $_{$a}} keys %_;  # print by decreasing age
    }'

Python:

Python:

find . -type f -print |
python -c 'import os, sys; times = {}
for f in sys.stdin.readlines(): f = f[0:-1]; times[f] = os.stat(f).st_mtime
for f in sorted(times.iterkeys(), key=lambda f:times[f]): print f'

#8


2  

I'm showing this for latest access time, you can easily modify this to do latest mod time.

我展示的是最新的访问时间,你可以很容易地修改它来做最新的mod时间。

There is two ways to do this:

有两种方法可以做到:


1)If you want to avoid global sorting which can be expensive if you have tens of millions of files, then you can do: (position yourself in the root of the directory where you want your search to start)

1)如果你想避免全局排序,如果你有数千万个文件,那么你就可以做:(把自己定位在你想要搜索的目录的根目录下)

linux> touch -d @0 /tmp/a;
linux> find . -type f -exec tcsh -f -c test `stat --printf="%X" {}` -gt  `stat --printf="%X" /tmp/a`  ; -exec tcsh -f -c touch -a -r {} /tmp/a ; -print 

The above method prints filenames with progressively newer access time and the last file it prints is the file with the latest access time. You can obviously get the latest access time using a "tail -1".

上面的方法以逐渐更新的访问时间打印文件名,最后一个文件打印的文件是具有最新访问时间的文件。显然,您可以使用“tail -1”来获得最新的访问时间。


2)You can have find recursively print the name,access time of all files in your subdirectory and then sort based on access time and the tail the biggest entry:

2)您可以找到递归打印出子目录中所有文件的名称、访问时间,然后根据访问时间和最大条目排序:

linux> \find . -type f -exec stat --printf="%X  %n\n" {} \; | \sort -n | tail -1

And there you have it...

这就是。

#9


2  

I have this alias in my .profile that I use quite often

我的.profile中有这个别名,我经常使用它。

$ alias | grep xlogs
xlogs='sudo find . \( -name "*.log" -o -name "*.trc" \) -mtime -1 | sudo xargs ls -ltr --color | less -R'

So it does what you are looking for (with exception it doesn't travers change date/time multiple levels) - looks for latest files (*.log and *.trc files in this case); also it only finds files modified in last day, then sorts by time and pipes output through less:

所以它做了你想要的(但它不会改变日期/时间的多个级别)-寻找最新的文件(*。日志和*。本案例中的trc文件);而且,它只发现在最后一天修改的文件,然后按时间排序,并通过较少的管道输出:

sudo find . \( -name "*.log" -o -name "*.trc" \) -mtime -1 | sudo xargs ls -ltr --color | less -R

ps. Notice I don't have root on some of the servers, but always have sudo, so you may not need that part.

注意,我在某些服务器上没有根,但总是有sudo,所以您可能不需要这个部分。

#10


1  

Quick bash function:

快速bash函数:

# findLatestModifiedFiles(directory, [max=10, [format="%Td %Tb %TY, %TT"]])
function findLatestModifiedFiles() {
    local d="${1:-.}"
    local m="${2:-10}"
    local f="${3:-%Td %Tb %TY, %TT}"

    find "$d" -type f -printf "%T@ :$f %p\n" | sort -nr | cut -d: -f2- | head -n"$m"
}

Find the latest modified file in a directory:

在目录中找到最新修改的文件:

findLatestModifiedFiles "/home/jason/" 1

You can also specify your own date/time format as the third argument.

您还可以指定自己的日期/时间格式作为第三个参数。

#11


1  

The following returns you a string of the time-stamp and the name of the file with the most recent time-stamp:

下面返回的是时间戳的字符串和最近时间戳中文件的名称:

find $Directory -type f -printf "%TY-%Tm-%Td-%TH-%TM-%TS %p\n" | sed -r 's/([[:digit:]]{2})\.([[:digit:]]{2,})/\1-\2/' |     sort --field-separator='-' -nrk1 -nrk2 -nrk3 -nrk4 -nrk5 -nrk6 -nrk7 | head -n 1

Resulting to an output of the form: <yy-mm-dd-hh-mm-ss.nanosec> <filename>

产生的形式为: <文件名> 。nanosec>

#12


1  

Here is one version that works with filenames that may contain spaces, newlines, glob characters as well:

这是一个与文件名一起工作的版本,它可能包含空格、换行符、glob字符:

find . -type f -printf "%T@ %p\0" | sort -zk1nr
  • find ... -printf prints file modification (EPOCH value) followed by a space and \0 terminated filenames.
  • 找到……-printf打印文件修改(EPOCH值),然后是空格和\0终止文件名。
  • sort -zk1nr reads NUL terminated data and sorts it reverse numerically
  • sort -zk1nr读取NUL终止的数据并对其进行数字排序。

As question is tagged with Linux so I am assuming gnu utils are available.

由于问题是用Linux标记的,所以我假定gnu utils是可用的。

You can pipe above with:

你可以用以下的方法来处理:

xargs -0 printf "%s\n"

to print modification time and filenames sorted by modification time (most recent first) terminated by newlines.

打印修改时间和文件名按修改时间(最近的第一次)以换行结束。

#13


1  

Ignoring hidden files — with nice & fast time stamp

Handles spaces in filenames well — not that you should use those!

在文件名中处理空格-不是你应该使用那些!

$ find . -type f -not -path '*/\.*' -printf '%TY.%Tm.%Td %THh%TM %Ta %p\n' |sort -nr |head -n 10

2017.01.28 07h00 Sat ./recent
2017.01.21 10h49 Sat ./hgb
2017.01.16 07h44 Mon ./swx
2017.01.10 18h24 Tue ./update-stations
2017.01.09 10h38 Mon ./stations.json

More find galore can be found by following the link.

通过以下链接可以找到更多的galore。

#14


0  

You may give the printf command of find a try

你可以让printf命令找到一个尝试。

%Ak File's last access time in the format specified by k, which is either @' or a directive for the C strftime' function. The possible values for k are listed below; some of them might not be available on all systems, due to differences in `strftime' between systems.

%Ak文件的最后访问时间以k指定的格式,这是@'或C strftime'函数的指令。k的可能值如下所示;由于系统之间的“strftime”差异,有些系统可能无法在所有系统上使用。

#15


0  

For plain ls output, use this. There is no argument list, so it can't get too long:

对于普通的ls输出,请使用它。没有参数列表,所以不能太长:

find . | while read FILE;do ls -d -l "$FILE";done

And niceified with cut for just the dates, times, and name:

并为日期、时间和名称进行了剪裁。

find . | while read FILE;do ls -d -l "$FILE";done | cut --complement -d ' ' -f 1-5

EDIT: Just noticed that the current top answer sorts by modification date. That's just as easy with the second example here, since the modification date is first on each line - slap a sort onto the end:

编辑:刚刚注意到当前的顶部回答排序是按修改日期排序的。这和第二个例子一样简单,因为修改日期在每一行上都是第一个——在末尾加上一个排序:

find . | while read FILE;do ls -d -l "$FILE";done | cut --complement -d ' ' -f 1-5 | sort

#16


0  

This could be done with a reccursive function in bash too

这也可以在bash中使用一个reccursive函数来完成。

Let F a function that displays the time of file which must be lexicographically sortable yyyy-mm-dd etc., (os-dependent?)

让F作为一个函数来显示文件的时间,它必须是字典式的sortable yyyy-mm-dd等等,(依赖于os的?)

F(){ stat --format %y "$1";}                # Linux
F(){ ls -E "$1"|awk '{print$6" "$7}';}      # SunOS: maybe this could be done easier

R the recursive function that run through directories

R是通过目录运行的递归函数。

R(){ local f;for f in "$1"/*;do [ -d "$f" ]&&R $f||F "$f";done;}

And finally

最后

for f in *;do [ -d "$f" ]&&echo `R "$f"|sort|tail -1`" $f";done

#1


349  

Try this one:

试试这个:

#!/bin/bash
find $1 -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2- | head

Execute it with the path to the directory where it should start scanning recursively (it supports filenames with spaces).

执行它的路径到它应该开始扫描的目录(它支持空格的文件名)。

If there are lots of files it may take a while before it returns anything. Performance can be improved if we use xargs instead:

如果有很多文件,它可能需要一段时间才能返回任何东西。如果我们使用xargs,性能可以得到改善:

#!/bin/bash
find $1 -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head

which is a bit faster.

这有点快。

#2


131  

To find all files that file status was last changed N minutes ago:

为了找到所有文件,文件状态最后更改N分钟前:

find -cmin -N

找到-cmin - n

for example:

例如:

find -cmin -5

找到-cmin 5

#3


32  

I shortened halo's awesome answer to this one-liner

我缩短了halo的精彩答案。

stat --printf="%y %n\n" $(ls -tr $(find * -type f))

Updated: If there are spaces in filenames, you can use this modification

更新:如果文件名中有空格,可以使用这个修改。

OFS="$IFS";IFS=$'\n';stat --printf="%y %n\n" $(ls -tr $(find . -type f));IFS="$OFS";

#4


29  

GNU Find (see man find) has a -printf parameter for displying the files EPOC mtime and relative path name.

GNU Find(见man Find)有一个-printf参数,用于显示文件EPOC mtime和相对路径名。

redhat> find . -type f -printf '%T@ %P\n' | sort -n | awk '{print $2}'

#5


11  

Try this

试试这个

#!/bin/bash
stat --format %y $(ls -t $(find alfa/ -type f) | head -n 1)

It uses find to gather all files from the directory, ls to list them sorted by modification date, head for selecting the 1st file and finally stat to show the time in a nice format.

它使用find来收集目录中的所有文件,ls将它们按修改日期排序,头用于选择第一个文件,最后以一个良好的格式显示时间。

At this time it is not safe for files with whitespace or other special chars in their names. Write a commend if it doesn't meet your needs yet.

此时,对于带有空格或其他特殊字符的文件,其名称是不安全的。如果它还不能满足你的需要,写一个推荐信。

#6


7  

This command works on Mac OS X:

这个命令在Mac OS X上运行:

find "$1" -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head

查找“$1”-type f -print0 | xargs -0 stat—format '%Y:% Y %n' | sort -nr | cut -d: -f2- |头。

On Linux, as the original poster asked, use stat instead of gstat.

在Linux上,正如最初的海报所要求的,使用stat代替gstat。

This answer is, of course, user37078's outstanding solution, promoted from comment to full answer. I mixed in CharlesB's insight to use gstat on Mac OS X. I got coreutils from MacPorts rather than homebrew, by the way.

这个答案当然是user37078的优秀解决方案,从评论到完整的答案。我把CharlesB的insight混合到Mac OS x上使用gstat,顺便说一下,我从MacPorts获得了coreutils,而不是homebrew。

And here's how I packaged this into a simple command ~/bin/ls-recent.sh for reuse:

下面是我如何把它打包成一个简单的命令~/bin/ls-最近。sh重用:

#!/bin/bash
# ls-recent: list files in a dir tree, most recently modified first
#
# Usage: ls-recent path [-10 | more]
# 
# Where "path" is a path to target directory, "-10" is any arg to pass
# to "head" to limit the number of entries, and "more" is a special arg
# in place of "-10" which calls the pager "more" instead of "head".
if [ "more" = "$2" ]; then
   H=more; N=''
else
   H=head; N=$2
fi

find "$1" -type f -print0 |xargs -0 gstat --format '%Y :%y %n' \
    |sort -nr |cut -d: -f2- |$H $N

#7


5  

Both the perl and Python solutions in this post helped me solve this problem on Mac OS X: https://unix.stackexchange.com/questions/9247/how-to-list-files-sorted-by-modification-date-recursively-no-stat-command-avail.

这篇文章中的perl和Python解决方案都帮助我在Mac OS X上解决了这个问题:https://unix. stackexchange.com/questions/9247/howto -list-files- by- modificationdate -recursively-no-stat-command-。

Quoting from the post:

从《华盛顿邮报》引用:

Perl:

Perl:

find . -type f -print |
perl -l -ne '
    $_{$_} = -M;  # store file age (mtime - now)
    END {
        $,="\n";
        print sort {$_{$b} <=> $_{$a}} keys %_;  # print by decreasing age
    }'

Python:

Python:

find . -type f -print |
python -c 'import os, sys; times = {}
for f in sys.stdin.readlines(): f = f[0:-1]; times[f] = os.stat(f).st_mtime
for f in sorted(times.iterkeys(), key=lambda f:times[f]): print f'

#8


2  

I'm showing this for latest access time, you can easily modify this to do latest mod time.

我展示的是最新的访问时间,你可以很容易地修改它来做最新的mod时间。

There is two ways to do this:

有两种方法可以做到:


1)If you want to avoid global sorting which can be expensive if you have tens of millions of files, then you can do: (position yourself in the root of the directory where you want your search to start)

1)如果你想避免全局排序,如果你有数千万个文件,那么你就可以做:(把自己定位在你想要搜索的目录的根目录下)

linux> touch -d @0 /tmp/a;
linux> find . -type f -exec tcsh -f -c test `stat --printf="%X" {}` -gt  `stat --printf="%X" /tmp/a`  ; -exec tcsh -f -c touch -a -r {} /tmp/a ; -print 

The above method prints filenames with progressively newer access time and the last file it prints is the file with the latest access time. You can obviously get the latest access time using a "tail -1".

上面的方法以逐渐更新的访问时间打印文件名,最后一个文件打印的文件是具有最新访问时间的文件。显然,您可以使用“tail -1”来获得最新的访问时间。


2)You can have find recursively print the name,access time of all files in your subdirectory and then sort based on access time and the tail the biggest entry:

2)您可以找到递归打印出子目录中所有文件的名称、访问时间,然后根据访问时间和最大条目排序:

linux> \find . -type f -exec stat --printf="%X  %n\n" {} \; | \sort -n | tail -1

And there you have it...

这就是。

#9


2  

I have this alias in my .profile that I use quite often

我的.profile中有这个别名,我经常使用它。

$ alias | grep xlogs
xlogs='sudo find . \( -name "*.log" -o -name "*.trc" \) -mtime -1 | sudo xargs ls -ltr --color | less -R'

So it does what you are looking for (with exception it doesn't travers change date/time multiple levels) - looks for latest files (*.log and *.trc files in this case); also it only finds files modified in last day, then sorts by time and pipes output through less:

所以它做了你想要的(但它不会改变日期/时间的多个级别)-寻找最新的文件(*。日志和*。本案例中的trc文件);而且,它只发现在最后一天修改的文件,然后按时间排序,并通过较少的管道输出:

sudo find . \( -name "*.log" -o -name "*.trc" \) -mtime -1 | sudo xargs ls -ltr --color | less -R

ps. Notice I don't have root on some of the servers, but always have sudo, so you may not need that part.

注意,我在某些服务器上没有根,但总是有sudo,所以您可能不需要这个部分。

#10


1  

Quick bash function:

快速bash函数:

# findLatestModifiedFiles(directory, [max=10, [format="%Td %Tb %TY, %TT"]])
function findLatestModifiedFiles() {
    local d="${1:-.}"
    local m="${2:-10}"
    local f="${3:-%Td %Tb %TY, %TT}"

    find "$d" -type f -printf "%T@ :$f %p\n" | sort -nr | cut -d: -f2- | head -n"$m"
}

Find the latest modified file in a directory:

在目录中找到最新修改的文件:

findLatestModifiedFiles "/home/jason/" 1

You can also specify your own date/time format as the third argument.

您还可以指定自己的日期/时间格式作为第三个参数。

#11


1  

The following returns you a string of the time-stamp and the name of the file with the most recent time-stamp:

下面返回的是时间戳的字符串和最近时间戳中文件的名称:

find $Directory -type f -printf "%TY-%Tm-%Td-%TH-%TM-%TS %p\n" | sed -r 's/([[:digit:]]{2})\.([[:digit:]]{2,})/\1-\2/' |     sort --field-separator='-' -nrk1 -nrk2 -nrk3 -nrk4 -nrk5 -nrk6 -nrk7 | head -n 1

Resulting to an output of the form: <yy-mm-dd-hh-mm-ss.nanosec> <filename>

产生的形式为: <文件名> 。nanosec>

#12


1  

Here is one version that works with filenames that may contain spaces, newlines, glob characters as well:

这是一个与文件名一起工作的版本,它可能包含空格、换行符、glob字符:

find . -type f -printf "%T@ %p\0" | sort -zk1nr
  • find ... -printf prints file modification (EPOCH value) followed by a space and \0 terminated filenames.
  • 找到……-printf打印文件修改(EPOCH值),然后是空格和\0终止文件名。
  • sort -zk1nr reads NUL terminated data and sorts it reverse numerically
  • sort -zk1nr读取NUL终止的数据并对其进行数字排序。

As question is tagged with Linux so I am assuming gnu utils are available.

由于问题是用Linux标记的,所以我假定gnu utils是可用的。

You can pipe above with:

你可以用以下的方法来处理:

xargs -0 printf "%s\n"

to print modification time and filenames sorted by modification time (most recent first) terminated by newlines.

打印修改时间和文件名按修改时间(最近的第一次)以换行结束。

#13


1  

Ignoring hidden files — with nice & fast time stamp

Handles spaces in filenames well — not that you should use those!

在文件名中处理空格-不是你应该使用那些!

$ find . -type f -not -path '*/\.*' -printf '%TY.%Tm.%Td %THh%TM %Ta %p\n' |sort -nr |head -n 10

2017.01.28 07h00 Sat ./recent
2017.01.21 10h49 Sat ./hgb
2017.01.16 07h44 Mon ./swx
2017.01.10 18h24 Tue ./update-stations
2017.01.09 10h38 Mon ./stations.json

More find galore can be found by following the link.

通过以下链接可以找到更多的galore。

#14


0  

You may give the printf command of find a try

你可以让printf命令找到一个尝试。

%Ak File's last access time in the format specified by k, which is either @' or a directive for the C strftime' function. The possible values for k are listed below; some of them might not be available on all systems, due to differences in `strftime' between systems.

%Ak文件的最后访问时间以k指定的格式,这是@'或C strftime'函数的指令。k的可能值如下所示;由于系统之间的“strftime”差异,有些系统可能无法在所有系统上使用。

#15


0  

For plain ls output, use this. There is no argument list, so it can't get too long:

对于普通的ls输出,请使用它。没有参数列表,所以不能太长:

find . | while read FILE;do ls -d -l "$FILE";done

And niceified with cut for just the dates, times, and name:

并为日期、时间和名称进行了剪裁。

find . | while read FILE;do ls -d -l "$FILE";done | cut --complement -d ' ' -f 1-5

EDIT: Just noticed that the current top answer sorts by modification date. That's just as easy with the second example here, since the modification date is first on each line - slap a sort onto the end:

编辑:刚刚注意到当前的顶部回答排序是按修改日期排序的。这和第二个例子一样简单,因为修改日期在每一行上都是第一个——在末尾加上一个排序:

find . | while read FILE;do ls -d -l "$FILE";done | cut --complement -d ' ' -f 1-5 | sort

#16


0  

This could be done with a reccursive function in bash too

这也可以在bash中使用一个reccursive函数来完成。

Let F a function that displays the time of file which must be lexicographically sortable yyyy-mm-dd etc., (os-dependent?)

让F作为一个函数来显示文件的时间,它必须是字典式的sortable yyyy-mm-dd等等,(依赖于os的?)

F(){ stat --format %y "$1";}                # Linux
F(){ ls -E "$1"|awk '{print$6" "$7}';}      # SunOS: maybe this could be done easier

R the recursive function that run through directories

R是通过目录运行的递归函数。

R(){ local f;for f in "$1"/*;do [ -d "$f" ]&&R $f||F "$f";done;}

And finally

最后

for f in *;do [ -d "$f" ]&&echo `R "$f"|sort|tail -1`" $f";done