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 :
Extract list of file concerns (just file with option -type f):
find . -type f
Print the size and the name of file:
-printf '%s\t%f\n'
Sort by size (with -n option for numeric)
sort -n