Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

Find Large Files in Linux - DesignLinux

Jun 22 2020
designlinux 0 Comments
Find Large Files in Linux

In Linux, it is very necessary to find the unnecessary files and free up them from your hard disk. Usually, Linux systems run out of disk space due to large log or backup files. This tutorial explains how to find the large files and directories in Linux systems using the find and du command.

Find Large Files Using the find Command#

The find command is very useful tools in the Linux systems. Using it you can search for files and directories with specific criteria.

For example, if you want to find files with size greater than 200MB in current working directory, type:

sudo find . -xdev -type f -size +200M

You should replace . dot with the path if you want to find in specific directory.

The above command will show a list of files without any additional information.

/home/tecnstuff/bkp.zip
/home/tecnstuff/image1.jpg

You also can use find command with combination of other commands such as ls or sort to perform operations on those files.

For example, we will pass the output of the find command to ls which will show the size of the each found file.

find . -xdev -type f -size +100M -print | xargs ls -lh

It will show the below output:

-rw------- 1 tecnstuff tecnstuff 365M Dec 28 01:10 /home/tecnstuff/bkp.zip
-rw------- 1 tecnstuff tecnstuff 290M Mar 7 20:06 /home/tecnstuff/image1.jpg

If there are more lines in output you can combine head command to show only first 10 line as given below:

find . -xdev -type f -size +100M -print | xargs ls -lh | head

Following is the explaination of the command:

  • find . -xdev -type f -size +100M -print – It will search only for files (-type f) in the current working directory, file size larger than 200MB, don’t descend directories on other filesystems (-xdev) and print the full file name on the standard output, followed by a new line (-print).
  • xargs ls -lh – the output of the find command is piped to xargs which executes the ls -lh command that will print the output in long listing human-readable format.
  • head : To prints only the first 10 lines of the piped output.

The find command has lot of powerful options. For example, you can search for large files that are older than specific days, large files with a specific extension or large files that belong to a particular user.

Find Large Files and Directories Using the du Command#

Generally, the du command is used to finding directories and files that consume large amounts of disk space.

The below command will display the list of largest files and directories:

du -ahx . | sort -rh | head -5
35G .
24G ./images
12G ./data

Let’s break down the command:

  • du -ahx . : It estimates disk space usage in the current working directory, a will print count both files and directories , h prints sizes in a human-readable format and x skips directories on different file systems.
  • sort -rh : It will sort lines by comparing values in human-readable format (-h) and reverse the result (-r).
  • head -5 : prints only the first 5 lines of the piped output.

The du command includes more other options.

Conclusion#

It is necessary to find large files and free it up, when your disk is full and getting out of space.

If you have any questions or remarks, please leave a comment below.

Related

Tags: disk, find, terminal

Type Command in Linux with Examples

Prev Post

How to Install WordPress with Nginx in Ubuntu 20.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 2
  • 801
  • 571,156

DesignLinux.com © All rights reserved

Go to mobile version