System Administration Guide

Checking the Size of Files

You can check the size of files and sort them by using the ls command. You can find files that exceed a size limit by using the find command. For more information, see ls(1) and find(1).

How to Display the Size of Files

  1. Change the directory to where the files you want to check are located.

  2. Display the size of the files.


    $ ls [-l] [-s]

    -l

    Displays a list of files and directories in long format, showing the sizes in bytes. 

    -s

    Displays a list of the files and directories, showing the sizes in blocks. 

Examples--Displaying the Size of Files

The following example shows that lastlog, wtmp, and wtmpx are substantially larger than the other files in the /var/adm directory.


venus% cd /var/adm
venus% ls -l
total 434
-r--r--r--   1 root     other     585872 Jan 28 14:53 lastlog
drwxrwxr-x   2 adm      adm          512 Dec  1 16:35 log
-rw-r--r--   1 root     other        408 Jan 28 14:15 messages
-rw-r--r--   1 root     other        177 Jan 24 16:56 messages.0
-rw-r--r--   1 root     other        177 Jan 17 16:13 messages.1
-rw-r--r--   1 root     other          0 Jan  4 04:05 messages.2
-rw-r--r--   1 root     other        562 Jan  2 13:13 messages.3
drwxrwxr-x   2 adm      adm          512 Dec  1 16:35 passwd
drwxrwxr-x   2 adm      sys          512 Jan 28 11:38 sa
-rw-rw-rw-   1 bin      bin            0 Nov 26 10:56 spellhist
-rw-------   1 root     root        1319 Jan 28 14:58 sulog
-rw-r--r--   1 root     bin          288 Jan 28 14:53 utmp
-rw-r--r--   1 root     bin         2976 Jan 28 14:53 utmpx
-rw-rw-r--   1 adm      adm        12168 Jan 28 14:53 wtmp
-rw-rw-r--   1 adm      adm       125736 Jan 28 14:53 wtmpx

The following example shows that lpNet uses eight blocks and lpsched and lpsched-1 use two blocks each.


% cd /var/lp/logs
% ls -s
total 14            2 lpsched-1    0 lpsched-4      0 requests-2
   8 lpNet          2 lpsched-2    0 requests
   2 lpsched        0 lpsched-3    0 requests-1
%

How to Find Large Files

  1. Change directory to the location where you want to search.

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


    $ ls -s | sort -nr | more
    

    sort -nr

    Sorts the list of files by block size from smallest to largest. 

Example--Finding Large Files

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


$ cd /var/adm
$ ls -s | sort -nr | more
 320 wtmpx
 128 lastlog
  74 pacct
  56 messages
  30 wtmp
   6 utmpx
   2 utmp
   2 sulog
   2 sa
   2 passwd
   2 log
   0 spellhist
total 624

How to Find Files That Exceed a Given Size Limit

To locate and display the names of files that exceed a specified size, use the find command.


$ find directory -size +nnn 

directory

Directory you want to search. 

--size +nnn

Is a number of 512-byte blocks. Files that exceed the size indicated are listed. 

Example--Finding Files That Exceed a Given Size Limit

The following example shows how to find files with more than 400 blocks in the current working directory.


$ find . -size +400 -print
./Howto/howto.doc
./Howto/howto.doc.backup
./Howto/howtotest.doc
./Routine/routineBackupconcepts.doc
./Routine/routineIntro.doc
./Routine/routineTroublefsck.doc
./.record
./Mail/pagination
./Config/configPrintadmin.doc
./Config/configPrintsetup.doc
./Config/configMailappx.doc
./Config/configMailconcepts.doc
./snapshot.rs