qaz*_*wsx 7 bash perl filesize
如何使用Perl或Bash找到给定目录中最大的10个文件?
编辑:
这将从当前目录递归打印10个最大的文件.
find . -type f -printf "%s %p\n" | sort -nr | awk '{print $2}' | head -10
Run Code Online (Sandbox Code Playgroud)
这是在perl中执行此操作的一种方法.(注:非递归版,根据问题的早期版本)
perl -wE 'say for ((sort { -s $b <=> -s $a } </given/dir/*>)[0..9]);'
Run Code Online (Sandbox Code Playgroud)
但是,我确信有更好的工具可以完成这项工作.
ETA:递归版,使用File :: Find:
perl -MFile::Find -wE '
sub wanted { -f && push @files, $File::Find::name };
find(\&wanted, "/given/dir");
@files = sort { -s $b <=> -s $a } @files;
say for @files[0..9];'
Run Code Online (Sandbox Code Playgroud)
要检查文件大小,请printf("%-10s : %s\n", -s, $_) for @files[0..9];
改为使用eg .