Linux find largest file in directory recursively using find/du
I have 500GB SSD installed on my Linux server. My web server is running out of the disk space. I need to find a biggest or largest file concerning file size on the disk. How do I find largest file in a directory recursively using the find command?
To find a big file concerning file size on disk is easy task if you know how to use the find, du and other command. The du command used to estimate file space usage on Linux system. The output of du passed on to the sort and head command using shell pipes. Let us see how to find largest file in Linux server using various commands.
Linux find largest file in directory recursively using find
## shell alias ## aliasducks='du -cks * | sort -rn | head'### run it ###
## shell alias ##
alias ducks=’du -cks * | sort -rn | head’
### run it ###
Finding largest file recursively on Linux bash shell using find
One can only list files and skip the directories with the find command instead of using the du command, sort command and NA command combination: $ sudo find / -type f -printf "%st%pn" | sort -n | tail -1 $ find $HOME -type f -printf '%s %pn' | sort -nr | head -10 Sample outputs:
You just learned how to search, find and list largest or biggest directories/files in Linux using the combination of du/find and other commands. For more info see this page or man pages of du and find commands: man du man find man sort man head man tail
The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.