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

前端 未结 15 1369
醉梦人生
醉梦人生 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 list the larger file in a folder

    ls -sh /pathFolder | sort -rh | head -n 1
    

    The output of ls -sh is a sized s and human h understandable view of the file size number.

    You could use ls -shS /pathFolder | head -n 1. The bigger S from ls already order the list from the larger files to the smaller ones but the first result its the sum of all files in that folder. So if you want just to list the bigger file, one file, you need to head -n 2 and check at the "second line result" or use the first example with ls sort head.

提交回复
热议问题