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

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

    This will find the largest file or folder in your present working directory:

    ls -S /path/to/folder | head -1
    

    To find the largest file in all sub-directories:

    find /path/to/folder -type f -exec ls -s {} \; | sort -nr | awk 'NR==1 { $1=""; sub(/^ /, ""); print }'
    

提交回复
热议问题