System Administration Guide: Advanced Administration

ProcedureHow to Find Large Files

  1. Change to the directory that you want to search.

  2. Display the size of files in blocks from largest to smallest.

    • If the characters or columns for the files are different, use the following command to sort a list of files by block size, from largest to smallest.


      $ ls -l | sort +4rn | more
      

      Note that this command sorts files in a list by the character that is in the fourth field, starting from the left.

    • If the characters or columns for the files are the same, use the following command to sort a list of files by block size, from largest to smallest.


      $ ls -s | sort -nr | more
      

      Note that this command sorts files in a list, starting with the left most character.


Example 6–5 Finding Large Files (Sorting by the Fifth Field's Character)


$ cd /var/adm
$ ls -l | sort +4rn | more
-r--r--r--   1 root     root     4568368 Oct 17 08:36 lastlog
-rw-r--r--   1 adm      adm       697040 Oct 17 12:30 pacct.9
-rw-r--r--   1 adm      adm       280520 Oct 17 13:05 pacct.2
-rw-r--r--   1 adm      adm       277360 Oct 17 12:55 pacct.4
-rw-r--r--   1 adm      adm       264080 Oct 17 12:45 pacct.6
-rw-r--r--   1 adm      adm       255840 Oct 17 12:40 pacct.7
-rw-r--r--   1 adm      adm       254120 Oct 17 13:10 pacct.1
-rw-r--r--   1 adm      adm       250360 Oct 17 12:25 pacct.10
-rw-r--r--   1 adm      adm       248880 Oct 17 13:00 pacct.3
-rw-r--r--   1 adm      adm       247200 Oct 17 12:35 pacct.8
-rw-r--r--   1 adm      adm       246720 Oct 17 13:15 pacct.0
-rw-r--r--   1 adm      adm       245920 Oct 17 12:50 pacct.5
-rw-r--r--   1 root     root      190229 Oct  5 03:02 messages.1
-rw-r--r--   1 adm      adm       156800 Oct 17 13:17 pacct
-rw-r--r--   1 adm      adm       129084 Oct 17 08:36 wtmpx


Example 6–6 Finding Large Files (Sorting by the Left Most Character)

In the following example, the lastlog and messages files are the largest files in the /var/adm directory.


$ cd /var/adm
$ ls -s | sort -nr | more
  48 lastlog
  30 messages
  24 wtmpx
  18 pacct
   8 utmpx
   2 vold.log
   2 sulog
   2 sm.bin/
   2 sa/
   2 passwd/
   2 pacct1
   2 log/
   2 acct/
   0 spellhist
   0 aculog
total 144