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

kbd { display: inline-block; margin: 0 .1em; padding: .1em .6em; font-family: Arial,”Helvetica Neue”,Helvetica,sans-serif; font-size: 11px; line-height: 1.4; color: #242729; text-shadow: 0 1px 0 #FFF; background-color: #e1e3e5; border: 1px solid #adb3b9; border-radius: 3px; box-shadow: 0 1px 0 rgba(12,13,14,0.2), 0 0 0 2px #FFF inset; white-space: nowrap;}

The procedure to find largest files including directories in Linux is as follows:

  1. Open the terminal application
  2. Login as root user using the sudo -i command
  3. Type du -a /dir/ | sort -n -r | head -n 20
  4. du will estimate file space usage
  5. sort will sort out the output of du command
  6. head will only show top 20 largest file in /dir/

Linux find a biggest files in /

Run the command:
$ sudo du -a /dir/ | sort -n -r | head -n 20
$ sudo du -a / 2>/dev/null | sort -n -r | head -n 20

Linux find large files quickly with bash alias

One can hunt down disk space hogs with ducks bash shell alias

## shell alias ##  
alias ducks='du -cks * | sort -rn | head'
### run it ###

## shell alias ## alias ducks=’du -cks * | sort -rn | head’ ### run it ### ducks

How To Find Largest Top 10 Files and Directories On Linux / UNIX / BSD

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:

295599646	/home/vivek/backups/
302654548	/home/vivek/backups/books/pdfs/unit443.wmv
313499710	/home/vivek/backups/books/pdfs/magzine.rar
340414464	/home/vivek/.local/share/baloo/index
346359808	/home/vivek/isoimages/VMware-VMvisor-Installer-6.7.0-8169922.x86_64.iso
352256000	/home/vivek/install63.iso
830054400	/home/vivek/linux/linux-4.18.8.tar
1014864333	/home/vivek/backups/corpapp/vsnl_9.5.2_E_21_Linux.tar.gz
1216380038	/home/vivek/backups/books/full.edition.tar.gz
1787822080	/home/vivek/Fedora-Workstation-Live-x86_64-28-1.1.iso

295599646 /home/vivek/backups/ 302654548 /home/vivek/backups/books/pdfs/unit443.wmv 313499710 /home/vivek/backups/books/pdfs/magzine.rar 340414464 /home/vivek/.local/share/baloo/index 346359808 /home/vivek/isoimages/VMware-VMvisor-Installer-6.7.0-8169922.x86_64.iso 352256000 /home/vivek/install63.iso 830054400 /home/vivek/linux/linux-4.18.8.tar 1014864333 /home/vivek/backups/corpapp/vsnl_9.5.2_E_21_Linux.tar.gz 1216380038 /home/vivek/backups/books/full.edition.tar.gz 1787822080 /home/vivek/Fedora-Workstation-Live-x86_64-28-1.1.iso

Great! I found the largest files on my disk. What next?>

Depend upon file/dir type you can either move or delete the file. For example, you cannot remove or move the Linux kernel or diver directories. To delete unwanted file on Linux use the rm command:
rm -i -v /path/to/file
To get rid of all files and its sub-directories recursively use following command:
rm -rf /path/to/folderName
To move file to a usb pen mounted at /mnt/usb/, run the mv command:
mv /path/to/large/file/ /mnt/usb/


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

(adsbygoogle = window.adsbygoogle || []).push({});

Posted by: SXI ADMIN

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.


How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...