Home > front end >  finding the biggest file in a directory in linux command line
finding the biggest file in a directory in linux command line

Time:09-30

I am currently using Linux-Ubuntu and I want to know if there is a way to do this in the command line : Suppose I have a directory and I want to find the biggest file (in size) inside this directory (eventually in its sub directories). I know I have to use find command with -exec option or with xargs command in addition to sort command but I do not know how. How can I do this ?

CodePudding user response:

You right find/exec/sort/xargs could be usefull for this kind of use case. One solution is this :

find . -type f -printf '%s\t%f\n'|sort -n

Let me explain how :

  1. Extract list of file concerns (just file with option -type f):

    find . -type f

  2. Print the size and the name of file:

    -printf '%s\t%f\n'

  3. Sort by size (with -n option for numeric)

    sort -n

  • Related