468x60 Ads

Wednesday, January 29, 2014

Display the number of files in a directory

Count the number of files in a directory

# ls -l | wc -l
   11484

#ls -1 targetdir | wc -l

Monday, January 27, 2014

Creating Persistent Routes in Solaris



Creating Persistent Routes in Solaris

Print the currently active routes:

# netstat -rn

Routing Table: IPv4
  Destination           Gateway           Flags  Ref     Use     Interface
-------------------- -------------------- ----- ----- ---------- ---------
default              172.16.0.254         UG        1 1650937522
10.0.0.0             172.16.0.12          UG        1   10206514
172.16.0.0           172.16.0.3           U         1    9528249 igb0:1
224.0.0.0            172.16.0.3           U         1          0 igb0:1
127.0.0.1            127.0.0.1            UH       19      26626 lo0:1

Add a route persistently:

# route -p add default ip-address

Eg:
# route -p add 192.168.10.0/24 172.16.0.10

-p             Make changes to the network route tables per-
                    sistent across system restarts. The operation
                    is applied  to  the  network  routing  tables
                    first  and, if successful, is then applied to
                    the list  of  saved  routes  used  at  system
                    startup.  In determining whether an operation
                    was successful, a failure to add a route that
                    already  exists  or to delete a route that is
                    not in the routing table is ignored. Particu-
                    lar  care  should be taken when using host or
                    network  names  in  persistent   routes,   as
                    network-based  name  resolution  services are
                    not available at the time routes are added at
                    startup.
          (Reference :Solaris man page)

For routes that are created by using this method, use following command
to display all of the static routes

 #route -p show 

Following examples creates an IPv4 route to the destination 192.168.10.0 and subnet  with the subnet  mask of 255.255.255.0(/24):

# route add 192.168.10.0/24 somegateway
       
# route add 192.168.10.0 -netmask 255.255.255.0 somegateway

# route add 192.168.10.0 somegateway 255.255.255.0

For IPv6, only “/” format is accepting for subnet. The following example creates an IPv6 route to the destination 35dd:: with netmask of 16 one-bits followed by 112 zero-bits.


# route add -inet6 35dd::/16 somegateway




Monday, January 6, 2014

Useful commands for checking/find Directories/Files in Solaris

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