• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

Find Large Files in Linux

Written by Admin, Updated On December 10, 2022
disk, find, terminal
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.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install TeamViewer on Debian 10
Next Article   Ps Command in Linux (List Processes)

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook