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 the ls(1) and find(1) man pages.
The ls commands displays a list of files on a specific directory. The following ls options are useful for obtaining information about file sizes on the system.
–l – displays a list of files and directories in long format and shows the sizes in bytes.
–h – scales file sizes and directory sizes into KB, MB, GB, or TB when the file or directory size is larger than 1024 bytes.
–s – displays a list of the files and directories and shows the sizes in blocks.
For more information, see thels(1) man page.
The following example shows that the lastlog and messages files are the two largest files in the /var/adm directory.
$ cd /var/adm $ ls -lh total 148 -rw------- 1 uucp bin 0 Nov 26 09:25 aculog -r--r--r-- 1 root other 342K Nov 26 13:56 lastlog -rw-r--r-- 1 root root 20K Nov 26 13:55 messages -rw-r--r-- 1 root bin 3.3K Nov 26 13:56 utmpx -rw-r--r-- 1 adm adm 19K Nov 26 13:56 wtmpx
In the following example that uses the –sh options, the first column of the output indicates the blocks that are used by the files.
$ ls -sh 880 -r--r--r-- 1 root other 342K Nov 26 13:56 lastlog 25 -rw-r--r-- 1 root root 20K Nov 26 13:55 messages 7 -rw-r--r-- 1 root bin 3.3K Nov 26 13:56 utmpx 24 -rw-r--r-- 1 adm adm 19K Nov 26 13:56 wtmpx
You can combine the ls command with the sort command to display a directory's files in an ascending or descending order according to a criterion such as file size. For more information about the sort command, see the sort(1) man page.
The find command enables you to search for files that fit a specific search criteria. For example, to find files that exceed a specific file size, you use the following command syntax:
$ find directory -size +nnn
where directory specifies the directory that you want to search and nnn is a number that represents a size in 512-byte blocks which you specify for the –size option.
The following example shows how to find files larger than 400 blocks in the current working directory. The –print option displays the output of the find command.
$ find . -size +400 -print ./Howto/howto.doc ./Howto/howto.doc.backup ./Howto/howtotest.doc ./Routine/routineBackupconcepts.doc ./Routine/routineIntro.doc