How to find big files in Linux, Unix, AIX



      Most often we see that the utilization of file systems grows up and we need to do some sort of housekeeping in the file system. Mainly we identify which file consumes more space in the file systems. Sometimes we see chunk of files with small size of single file with more size consume more space in the file systems. In either situation our goal is to find out what is consuming more space, identify the necessity of those files in the file system and decide to housekeep the file system by removing the unwanted files.

Here are some ways to find the big files in a directory. People mostly use the below steps to identify the big files in a directory.

1.       By using “du” command.
2.       By using “find” command

By using “du” command.

Eg.  # du -a /

Here “du” command will look for all the files in the directory including filesystems mounted on directories under “/” directory and list them with their size on kilo bites (KB).
If you want to sort the files in the order of its size user sort command with switches “n” and “r” like below.

# du -a /root | sort -rn

8148    /root
6524    /root/.cache
4032    /root/.cache/tracker
2044    /root/.cache/tracker/meta.db-wal
1576    /root/.cache/tracker/meta.db
1436    /root/.local/share
1436    /root/.local
#

Here “n” used to sort according to its numerical value and “r” stands for – Reverse order (bit files and top and small at bottom.). If you want to just sort the files based on numerical in ascending order, then  use only “sort -n” in the command line.

Now say you want to list only first 10 numbers in ascending or descending order, then use:

# du -a /root | sort -rn | head -n 10

8148    /root
6524    /root/.cache
4032    /root/.cache/tracker
2044    /root/.cache/tracker/meta.db-wal
1576    /root/.cache/tracker/meta.db
1436    /root/.local/share
1436    /root/.local
1268    /root/.cache/gnome-software
1124    /root/.local/share/app-info/xmls/extensions-web.xml
1124    /root/.local/share/app-info/xmls
#

There are may other ways to get the size values other than listing in kilo bites (KB). Some of them are:

# du -ah    - In human readable format.
# du -am    - In MB
# du -ab    - In bytes.

For more information refer “man” page of “du” command.

By using “find” command

Another way of finding the files is by using “find” command. Some examples are given below.

# find / -type f -size +1000M

/proc/kcore/data/images/CentOS-8.iso
/data/images/CentOS-7.iso
/data/vir_images/labprd1/labprd1.qcow2
/data/vir_images/Template_CentOS-8.qcow2
#

Find files (-type f) under directory “/” with size greater than 1G (-size +1000M).

If you want to see the complete details of these files by long listing, then use:

# find /root -size +1024 -exec ls -l {} \;

-rw-r--r--. 1 root root 1310728 Dec 17 00:00 /root/.cache/mesa_shader_cache/index
-rw-r--r--. 1 root root 1612800 Dec 16 21:47 /root/.cache/tracker/meta.db
-rw-r--r--. 1 root root 2090792 Dec 16 21:47 /root/.cache/tracker/meta.db-wal
-rw-------. 1 root root 879215 Dec 16 21:47 /root/.cache/gstreamer-1.0/registry.x86_64.bin
-rw-r--r--. 1 root root 728343 Dec 16 21:47 /root/.cache/gnome-software/shell-extensions/gnome.json
-rw-r--r--. 1 root root 1149703 Dec 16 21:47 /root/.local/share/app-info/xmls/extensions-web.xml
#

Here find command will list the files under directory “/root” (find /root) with size greater than 1KB (-size +1024) and long list them (-exec ls -l {} \;). In this case this will include file systems mounted in the sub directories as well. If you want to exclude other file systems, then use -xdev option with find command.

# find / -xdev -size +1240 -exec ls -l {} \;

The below command will help you get the details of files in more structured way with size in human readable format, last modification date, owner of the file and the name of the files sorted with size.

# find / -xdev  -size +1024 -exec ls -l {} \;|awk '{print $5, $7$6$8, $3, $9}'|awk '{printf("%9.1fMB %s %12s %s\n", $1/1024/1024, $2, $3, $4) }' | sort -nr | head -10

    575.5MB 13Dec20:15         root /var/spool/abrt/ccpp-2019-12-13-20:14:57-11977/coredump
    146.7MB 7Dec05:58         root /opt/google/chrome/chrome
    131.0MB 15Dec17:36         root /var/spool/abrt/vmcore-127.0.0.1-2019-12-15-17:33:56/vmcore
    131.0MB 15Dec17:34         root /var/crash/127.0.0.1-2019-12-15-17:33:56/vmcore
    103.5MB 17Dec21:48         root /var/lib/rpm/Packages
    101.2MB 14Dec01:07         root /usr/lib/locale/locale-archive
     96.5MB 11Jul23:33         root /usr/lib64/firefox/libxul.so
     94.2MB 11Dec22:11         root /var/cache/yum/x86_64/7/updates/packages/firefox-68.3.0-1.el7.centos.x86_64.rpm
#





Comments

Popular posts from this blog

AIX Firefox Installation

AIX Commands

How to increase swap size on CentOS 8 / RHEL 8

How to configure NTP in RHEL8 or CentOS 8 by chronyd.

System Administration

How to manage Linux systems through web browser (cockpit for Linux): CentOS 7, CentOS 8, RHEL 7, RHEL 8, Fedora, Ubuntu and Debian systems.

Remote X11 forwarding for AIX in command line.

How to enable VNC server (get GUI remotely) in CentOS 7, RHEL 7, CentOS 8 and RHEL 8 servers.

How to change Time Zone in CentOS 8, RHEL 8 and Ubuntu systems