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

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

    Try following command :

    find /your/path -printf "%k %p\n" | sort -g -k 1,1 | awk '{if($1 > 500000) print $1/1024 "MB" " " $2 }' |tail -n 1 
    

    This will print the largest file name and size and more than 500M. You can move the if($1 > 500000),and it will print the largest file in the directory.

提交回复
热议问题