174

I have a linux server, which currently has below space usage:

/dev/sda3              20G   15G  4.2G  78% /
/dev/sda6              68G   42G   23G  65% /u01
/dev/sda2              30G  7.4G   21G  27% /opt
/dev/sda1              99M   19M   76M  20% /boot
tmpfs                  48G  8.2G   39G  18% /dev/shm

As you can see. / is at 78%. I want to check, which files or folders are consuming space.

I tried this:

find . -type d -size +100M

Which shows result like this:

./u01/app/june01.dbf
./u01/app/temp01.dbf
./u01/app/smprd501.dbf
./home/abhishek/centos.iso
./home/abhishek/filegroup128.jar

Now this is my issue. I only want the name of those files located in folders that are consuming space at / and not at /u01 or /home. Since / is base of everything, it is showing me every file of my server.

Is is possible to get big files that is contributing to 78% of / ?

4

3 Answers 3

283

Try:

find / -xdev -type f -size +100M

It lists all files that has size bigger than 100M.

If you want to know about directory, you can try ncdu.

If you aren't running Linux, you may need to use -size +204800 or -size +104857600c, as the M suffix to mean megabytes isn't in POSIX.

find / -xdev -type f -size +102400000c
4
  • 6
    -xdev just prevents find from walking across filesystems, so you'll only search your current physical drive. If that's not what you want, just remove the -xdev arg.
    – hobs
    Jan 13, 2019 at 5:58
  • i was just wondering. Should be this command run without sudo (on /) ? Without sudo it produces a LOT of warnings, rendering the output unreadable Oct 23, 2020 at 13:05
  • 1
    @user1762087 You can use sudo if you don't have permission.
    – cuonglm
    Oct 24, 2020 at 2:00
  • what do you mean by ncdu for directory? How to search for directories? Oct 1, 2021 at 18:42
62

The following command not only find you the top 50 largest files (>100M) on your filesystem, but also sort (GNU sort) by the biggest:

find / -xdev -type f -size +100M -exec du -sh {} ';' | sort -rh | head -n50

-xdev Don't descend directories on other filesystems.

On BSD find use -x which is equivalent to the deprecated -xdev primary.

For all files and directories, it's even easier:

du -ahx / | sort -rh | head -20

(the -x flag is what's required to constrain du to a single filesystem)

If you're not using GNU sort (from coreutils), use it without -h:

du -ax / | sort -rn | head -20

For current directory only (for quicker results), replace / with ..

4
  • 1
    I would mention that this method is good because -h shows human readable output, and add a sample output. May 21, 2019 at 13:32
  • Very good solution. Thank you.
    – Tigin
    Aug 6, 2019 at 11:04
  • how to make du show only files not directories?
    – Akhil
    Jun 27, 2020 at 5:43
  • Works like a charm on Ubuntu 20. Sep 21, 2020 at 9:00
57

In addition to @Gnouc answer, you can also use the exec option of find combined with ls -la to get more details. You should have sudo privileges to do that.

$ find / -xdev -type f -size +100M -exec ls -lha {} \; | sort -nk 5

To only see files that are in the gigbyte, do:

root# du -ahx / | grep -E '\d+G\s+'

1.8G    /.Spotlight-V100/Store-V2/A960D58E-A644-4497-B3C1-866A529BF919
1.8G    /.Spotlight-V100/Store-V2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.