How To Find The Largest Files In Linux

Why Find The Largest Files In Linux

Before starting with the tutorial let me clarify why will somebody need finding the largest files in Linux. There could be several reasons. All the reasons boil down to log files.
1. Your server could have been a target of brute-force attacks. In this case /var/log/btmp file grows extremely big. Huge /var/log/btmp is an clue that you need to enhance your server security on several levels: change the port for SSH from 22 to something arbitrary and install a firewall. Of course, DenyHosts can block login attempts after a certain number of failures. ConfigServer is a better and more complex solution that definitely is worth all the time invested in its installing and configuring.
2. There could be a problem with systemd journal performance. To start off, let’s take a look at /etc/systemd/journald.conf. There is a setting to limit the amount of journals the system keeps.
Old ones get rotated out. Nevertheless, corrupted files do not get counted against this total. You can recognize the corrupted journal files by a .journal~ suffix.
3. Sometimes /var/lib/mysql/ibdata1 can get quite big. Preventing the shared table of  InnoDB’s, ibdata1, is  out of scope of this article. But you can find a good source of information on the topic at StackOverflow

Piped Commands to help you Find The Largest File On the Disk

There isn’t a single command to determine the largest file in Linux (Unix,BSD). Piped commands are used instead.
# du -a /var | sort -n -r | head -n 12
du – summarizes disk usage of each FILE, recursively for directories. The option -a writes counts on all files, not just directories.
sort – writes sorted concatenation of all FILE(s) to standard output. The option -n compares according to string numerical value. -r reverses the result of comparisons
head – prints the first 10 lines of a file to standard output, -n number option prints number lines instead 10 lines only.
Here is a sample answer

159502 /var
112868 /var/lib
100237 /var/lib/mysql
64922 /var/lib/mysql/ibdata1
22218 /var/log
12717 /var/cache
12712 /var/cache/yum
12712 /var/cache/yum/x86_64
12712 /var/cache/yum/x86_64/7
11141 /var/www

Judging by the results we might improve the ibdata1 mysql problem. At least we can check the configuration settings in my.conf

Diana D has written 18 articles

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>