仅列出最大文件的名称和大小 (UNIX)
Listing only name and size of the file with largest size (UNIX)
我怎样才能只列出目录中最大文件的名称和大小我使用了这个命令但是当我在不同的目录上尝试时它不起作用.
find . -type f -exec ls -lS {} \; | sort -t" " -n -k5 | cut -d" " -f5,10 | tail -n1
这应该有效
find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head -n 1
head -n 后的数字 1 表示它将输出多少个最大的文件,如果您还想在子目录中查找文件,您可以通过删除 -maxdepth 1 或更改数字来实现到更大的。
有关详细信息,请参阅之前的回复 post:How to find the largest file in a directory and its subdirectories?
对于 post 此类内容,我建议将它们标记为 bash、sh 或 shell。
我怎样才能只列出目录中最大文件的名称和大小我使用了这个命令但是当我在不同的目录上尝试时它不起作用.
find . -type f -exec ls -lS {} \; | sort -t" " -n -k5 | cut -d" " -f5,10 | tail -n1
这应该有效
find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head -n 1
head -n 后的数字 1 表示它将输出多少个最大的文件,如果您还想在子目录中查找文件,您可以通过删除 -maxdepth 1 或更改数字来实现到更大的。
有关详细信息,请参阅之前的回复 post:How to find the largest file in a directory and its subdirectories?
对于 post 此类内容,我建议将它们标记为 bash、sh 或 shell。