Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
16.  Managing Disk Use (Tasks) Displaying Information About Files and Disk Space How to Display Information About Files and Disk Space Examples--Displaying Information About File Size and Disk Space  Previous   Contents   Next 
   
 

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 to the directory where the files you want to check are located.

  2. Display the size of the files.

    $ ls [-lh] [-s]

    -l

    Displays a list of files and directories in long format, showing the sizes in bytes. (See the example that follows.)

    -h

    Scales file and directory sizes into Kbytes, Mbytes, Gbytes, or Terabytes when the file or directory size is larger than 1024 bytes. This option also modifies the output displayed by the -o, -n, -@, and -g options to display file or directory sizes in the new format. For more information, see ls(1).

    -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 the lastlog and messages files are larger than the other files in the /var/adm directory.

$ cd /var/adm
$ ls -lh
total 148
drwxrwxr-x   5 adm      adm          512 Nov 26 09:39 acct/
-rw-------   1 uucp     bin            0 Nov 26 09:25 aculog
drwxr-xr-x   2 adm      adm          512 Nov 26 09:25 exacct/
-r--r--r--   1 root     other       342K Nov 26 13:56 lastlog
drwxr-xr-x   2 adm      adm          512 Nov 26 09:25 log/
-rw-r--r--   1 root     root         20K Nov 26 13:55 messages
drwxr-xr-x   2 adm      adm          512 Nov 26 09:25 passwd/
drwxrwxr-x   2 adm      sys          512 Nov 26 09:39 sa/
drwxr-xr-x   2 root     sys          512 Nov 26 09:49 sm.bin/
-rw-rw-rw-   1 root     bin            0 Nov 26 09:25 spellhist
drwxr-xr-x   2 root     sys          512 Nov 26 09:25 streams/
-rw-r--r--   1 root     bin         3.3K Nov 26 13:56 utmpx
-rw-r--r--   1 root     root           0 Nov 26 10:17 vold.log
-rw-r--r--   1 adm      adm          19K Nov 26 13:56 wtmpx

The following example shows that the lpsched.1 file uses two blocks.

$ cd /var/lp/logs
$ ls -s
total 2            0 lpsched       2 lpsched.1

How 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.

    $ ls -s | sort -nr | more

    sort -nr

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

Example--Finding Large Files

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

How to Find Files That Exceed a Specified Size Limit

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

$ find directory -size +nnn 

directory

Identifies the directory you want to search.

-size +nnn

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

Example--Finding Files That Exceed a Specified Size Limit

The following example shows how to find files larger 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

Checking the Size of Directories

You can display the size of directories by using the du command and options. Additionally, you can find the amount of disk space used by user accounts on local UFS file systems by using the quot command. For more information about these commands, see du(1) and quot(1M).

How to Display the Size of Directories, Subdirectories, and Files

Display the size of one or more directories, subdirectories, and files by using the du command. Sizes are displayed in 512-byte blocks.

$ du [-as] [directory ...]

du

Displays the size of each directory you specify, including each subdirectory beneath it.

-a

Displays the size of each file and subdirectory, and the total number of blocks contained in the specified directory.

-s

Displays the total number of blocks contained in the specified directory.

-h

Displays the size of each directory in 1024 bytes.

-H

Displays the size of each directory in 1000 bytes.

directory ...

Identifies one or more directories you want to check.

Examples--Displaying the Size of Directories, Subdirectories, and Files

The following example shows the total sizes of two directories.

$ du -s /var/adm /var/spool/lp
130     /var/adm
40      /var/spool/lp

The following example shows the sizes of two directories, all of the subdirectories and files they contain, and the total number of blocks contained in each directory.

$ du /var/adm /var/spool/lp
2       /var/adm/log
2       /var/adm/passwd
2       /var/adm/acct/fiscal
2       /var/adm/acct/nite
2       /var/adm/acct/sum
8       /var/adm/acct
2       /var/adm/sa
2       /var/adm/sm.bin
130     /var/adm
4       /var/spool/lp/admins
2       /var/spool/lp/fifos/private
2       /var/spool/lp/fifos/public
6       /var/spool/lp/fifos
2       /var/spool/lp/requests/starbug
4       /var/spool/lp/requests
2       /var/spool/lp/system
2       /var/spool/lp/tmp/starbug
2       /var/spool/lp/tmp/.net/tmp/starbug
4       /var/spool/lp/tmp/.net/tmp
2       /var/spool/lp/tmp/.net/requests/starbug
4       /var/spool/lp/tmp/.net/requests
10      /var/spool/lp/tmp/.net
14      /var/spool/lp/tmp
40      /var/spool/lp
 
 
 
  Previous   Contents   Next