Useful
commands for checking/find Directories/Files in Solaris
Display
the Size of Directories, Sub-directories, and Files
du -summarize disk usage
(By default,
file sizes are written in 512-byte units, rounded up to the next 512-byte unit.)
OPTIONS:
-a
Displays the size
of each file and subdirectory, and the total number of blocks that are
contained in the specified directory.
-s
Displays the total
number of blocks that are contained in the specified directory.
# du -s /var/adm/
1198
/var/adm
-h
All sizes are
scaled to a human readable
format,for example, 34K, 244M, 5.7G, or 2.0T.
Displays the size
of each directory in 1024–byte blocks.
# du -h /var/adm/
1K /var/adm/acct/fiscal
1K /var/adm/acct/nite
1K /var/adm/acct/sum
4K /var/adm/acct
1K /var/adm/streams
1K /var/adm/sm.bin
1K /var/adm/exacct
1K /var/adm/log
1K /var/adm/sa
599K
/var/adm
-H
Displays the size
of each directory in 1000–byte blocks.
# du -H /var/adm/
2
/var/adm/acct/fiscal
2
/var/adm/acct/nite
2
/var/adm/acct/sum
8
/var/adm/acct
2
/var/adm/streams
2
/var/adm/sm.bin
2
/var/adm/exacct
2
/var/adm/log
2
/var/adm/sa
1198
/var/adm
Using ls and find commands:
Changes the directory in to the place of files are locating
# ls [-lh] [-s]
-l
Displays a list of
files and directories in long format , sizes in bytes.
# ls -l
total 115540
-rw-r--r--
1 root root 233 May 21 2013 Cms2Serv.bak
-rw-rw-rw-
1 root root 213 May 21 2013 Cms2Serv.ini
-rw-r--r--
1 root root 56479733 Jan 7 10:26 EMdatabase0.sa
-rw-r--r--
1 root root
639742 Jan 7 10:28
EMdetect_00.bin
-h
Scales file sizes
and directory sizes into human readable format like Kbytes, Mbytes, Gbytes, or
Tbytes when the file or directory size is larger than 1024 bytes.
# ls -l -h
total 115540
-rw-r--r--
1 root root 233 May 21 2013 Cms2Serv.bak
-rw-rw-rw-
1 root root 213 May 21 2013 Cms2Serv.ini
-rw-r--r--
1 root root 54M Jan 7 10:26 EMdatabase0.sav
-rw-r--r--
1 root root 625K Jan 7 10:28 EMdetect_00.bin
-S
Displays a list of
the files and directories, showing the sizes in blocks.
# ls -s
total 115800
2 Cms2Serv.bak 1280 EMdetect_00.bin 92 EMhist.sav 28 elementMan.cms
How to Find Large Files
If the characters or
columns for the files are different, use following command to sort a list of
files by block size, from largest to smallest.
# ls -l| sort +4rn | more
# ls -l | sort +4rn | more
-rw-r--r--
1 root root 56660746 Jan 7 10:34 EMdatabase0.sav
-rw-r--r--
1 root root 961820 Jan 7 09:58 EMhist.bak
-rw-r--r--
1 root root 640113 Jan 7 10:33 EMdetect_01.bin
-rw-r--r--
1 root root 639742 Jan 7 10:28 EMdetect_00.bin
drwxr-xr-x
2 root root 233984 Jan 7 10:33 ipcfg
-rw-r--r--
1 root root 51608 Jan 7 10:36 EMhist.sav
drwxr-xr-x
2 root root 41472 Jan 7 09:48 ipinv
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.
Find Files That Exceed a Specified Size Limit
find directory -size +nnn
directory
Identifies the directory
that you want to search.
-size +nnn
Nnn in 512-byte blocks.
Files that exceed this size will list.
# find . -size +400 -print
./ipcfg
./ipcfg/ipdevcfg.bin
./EMdetect_01.bin
./EMdetect_00.bin
./EMhist.bak
./EMdatabase0.sav