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).
Change the directory to where the files you want to check are located.
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. |
The following example shows that lastlog and messages are larger than the other files in the /var/adm directory.
$ cd /var/adm $ ls -l total 144 drwxrwxr-x 5 adm adm 512 Sep 1 14:11 acct/ -rw------- 1 uucp bin 0 Sep 1 14:08 aculog -r--r--r-- 1 root root 350700 Sep 3 10:37 lastlog drwxr-xr-x 2 adm adm 512 Sep 1 14:08 log/ -rw-r--r-- 1 root root 14619 Sep 2 16:11 messages -rw-r--r-- 1 adm adm 8200 Sep 3 14:35 pacct -rw-r--r-- 1 adm adm 920 Sep 3 10:47 pacct1 drwxr-xr-x 2 adm adm 512 Sep 1 14:08 passwd/ drwxrwxr-x 2 adm sys 512 Sep 1 14:11 sa/ drwxr-xr-x 2 root sys 512 Sep 1 14:36 sm.bin/ -rw-rw-rw- 1 root bin 0 Sep 1 14:08 spellhist -rw------- 1 root root 420 Sep 3 14:17 sulog -rw-r--r-- 1 root bin 4092 Sep 3 10:37 utmpx -rw-r--r-- 1 root root 122 Sep 1 15:39 vold.log -rw-r--r-- 1 adm adm 11904 Sep 3 10:47 wtmpx |
The following example shows that lpsched.1 uses two blocks.
$ cd /var/lp/logs $ ls -s total 2 0 lpsched 2 lpsched.1 |
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. |
In the following example, lastlog and messages 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 |
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. |
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 |