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

前端 未结 15 1357
醉梦人生
醉梦人生 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

    Quote from this link-

    If you want to find and print the top 10 largest files names (not directories) in a particular directory and its sub directories

    $ find . -printf '%s %p\n'|sort -nr|head

    To restrict the search to the present directory use "-maxdepth 1" with find.

    $ find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head

    And to print the top 10 largest "files and directories":

    $ du -a . | sort -nr | head

    ** Use "head -n X" instead of the only "head" above to print the top X largest files (in all the above examples)

提交回复
热议问题