How to find the largest file in a directory and its subdirectories?

前端 未结 15 1368
醉梦人生
醉梦人生 2020-11-28 18:29

We\'re just starting a UNIX class and are learning a variety of Bash commands. Our assignment involves performing various commands on a directory that has a number of folder

15条回答
  •  温柔的废话
    2020-11-28 18:59

    To find the top 25 files in the current directory and its subdirectories:

    find . -type f -exec ls -al {} \; | sort -nr -k5 | head -n 25

    This will output the top 25 files by sorting based on the size of the files via the "sort -nr -k5" piped command.

    Same but with human-readable file sizes:

    find . -type f -exec ls -alh {} \; | sort -hr -k5 | head -n 25

提交回复
热议问题