Useful Unix Commands and Settings

Below are some of the useful Unix commands and settings.

COLUMNS

Set the column length for bash shell.

$ echo $COLUMNS
157

This bash can only display a maximum of 157 characters in a line. To increase the line size to 200, use below command.

export COLUMNS=200
LDD

To list dynamic linked libraries used by a program. This is a level 1 command and can be used by non-root user.

ldd
FUSER

To find the processes that are using a processes. This can be used by non-privileged user also.

fuser
Converting float to int in AWK
int (1.3333)

This will cast to interger 1

How to check files opened by a process in Solaris?

Get the process id by executing ps -eaf

/usr/proc/bin/pfiles <pid>
Example
$ /usr/proc/bin/pfiles 2780

The output of above command is seen below

2780:   ora_mmon_orcl
  Current rlimit: 65536 file descriptors
   0: S_IFCHR mode:0666 dev:349,0 ino:6815752 uid:0 gid:3 rdev:13,2
      O_RDONLY|O_LARGEFILE
      /devices/pseudo/mm@0:null
   1: S_IFCHR mode:0666 dev:349,0 ino:6815752 uid:0 gid:3 rdev:13,2
      O_RDONLY|O_LARGEFILE
      /devices/pseudo/mm@0:null
   2: S_IFCHR mode:0666 dev:349,0 ino:6815752 uid:0 gid:3 rdev:13,2
      O_RDONLY|O_LARGEFILE
      /devices/pseudo/mm@0:null
   3: S_IFCHR mode:0666 dev:349,0 ino:6815752 uid:0 gid:3 rdev:13,2
      O_RDONLY|O_LARGEFILE
      /devices/pseudo/mm@0:null
   4: S_IFCHR mode:0666 dev:349,0 ino:6815752 uid:0 gid:3 rdev:13,2
      O_RDONLY|O_LARGEFILE
      /devices/pseudo/mm@0:null
   5: S_IFREG mode:0640 dev:316,79008 ino:1081 uid:131 gid:107 size:592
      O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE
      /opt/oracle/admin/orcl/udump/orcl_ora_2750.trc
   6: S_IFREG mode:0644 dev:316,79008 ino:2678 uid:131 gid:107 size:8733
      O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE
   7: S_IFREG mode:0644 dev:316,79008 ino:2678 uid:131 gid:107 size:8733
      O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE
   8: S_IFREG mode:0660 dev:316,79002 ino:30322 uid:131 gid:107 size:1544
      O_RDWR|O_SYNC|O_LARGEFILE
      /opt/oracle/product/10.2.0/db/dbs/hc_orcl.dat
   9: S_IFCHR mode:0666 dev:349,0 ino:6815772 uid:0 gid:3 rdev:13,12
      O_RDONLY|O_LARGEFILE
      /devices/pseudo/mm@0:zero
  10: S_IFREG mode:0660 dev:316,79002 ino:130111 uid:131 gid:107 size:0
      O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE
  11: S_IFCHR mode:0666 dev:349,0 ino:6815772 uid:0 gid:3 rdev:13,12
      O_RDONLY|O_LARGEFILE
      /devices/pseudo/mm@0:zero
  12: S_IFDOOR mode:0444 dev:358,0 ino:54 uid:0 gid:0 size:0
      O_RDONLY|O_LARGEFILE FD_CLOEXEC  door to nscd[437]
      /var/run/name_service_door
  13: S_IFREG mode:0644 dev:316,79002 ino:14860 uid:131 gid:107 size:849408
      O_RDONLY|O_LARGEFILE FD_CLOEXEC
      /opt/oracle/product/10.2.0/db/rdbms/mesg/oraus.msb
  14: S_IFREG mode:0660 dev:316,79002 ino:30322 uid:131 gid:107 size:1544
      O_RDWR|O_SYNC|O_LARGEFILE
      /opt/oracle/product/10.2.0/db/dbs/hc_orcl.dat
  15: S_IFREG mode:0660 dev:316,79002 ino:30323 uid:131 gid:107 size:24
      O_RDWR|O_LARGEFILE
      advisory read lock set by process 2756
      /opt/oracle/product/10.2.0/db/dbs/lkORCL
  16: S_IFREG mode:0644 dev:316,79002 ino:14860 uid:131 gid:107 size:849408
      O_RDONLY|O_LARGEFILE FD_CLOEXEC
      /opt/oracle/product/10.2.0/db/rdbms/mesg/oraus.msb
  17: S_IFSOCK mode:0666 dev:356,0 ino:33804 uid:0 gid:0 size:0
      O_RDWR
        SOCK_STREAM
        SO_SNDBUF(49152),SO_RCVBUF(49152),IP_NEXTHOP(0.0.192.0)
        sockname: AF_INET 0.0.0.0  port: 0
 256: S_IFREG mode:0640 dev:316,79004 ino:15 uid:131 gid:107 size:429924352
      O_RDWR|O_DSYNC|O_LARGEFILE FD_CLOEXEC
      advisory write lock set by process 2762
      /u05/oracle/orcl/system01.dbf
 257: S_IFREG mode:0640 dev:316,79004 ino:16 uid:131 gid:107 size:241180672
      O_RDWR|O_DSYNC|O_LARGEFILE FD_CLOEXEC
      advisory write lock set by process 2762
      /u05/oracle/orcl/sysaux01.dbf
 258: S_IFREG mode:0640 dev:316,79006 ino:18 uid:131 gid:107 size:5251072
      O_RDWR|O_DSYNC|O_LARGEFILE FD_CLOEXEC
      advisory write lock set by process 2762
      /u07/oracle/orcl/users01.dbf
 259: S_IFREG mode:0640 dev:316,79004 ino:17 uid:131 gid:107 size:524296192
      O_RDWR|O_DSYNC|O_LARGEFILE FD_CLOEXEC
      advisory write lock set by process 2762
      /u05/oracle/orcl/ORCL_DAT1.dbf
 260: S_IFREG mode:0640 dev:316,79005 ino:16 uid:131 gid:107 size:524296192
      O_RDWR|O_DSYNC|O_LARGEFILE FD_CLOEXEC
      advisory write lock set by process 2762
      /u06/oracle/orcl/ORCL_DAT2.dbf
 261: S_IFREG mode:0640 dev:316,79006 ino:19 uid:131 gid:107 size:524296192
      O_RDWR|O_DSYNC|O_LARGEFILE FD_CLOEXEC
      advisory write lock set by process 2762
      /u07/oracle/orcl/ORCL_DAT3.dbf
 262: S_IFREG mode:0640 dev:316,79005 ino:14 uid:131 gid:107 size:256909312
      O_RDWR|O_DSYNC|O_LARGEFILE FD_CLOEXEC
      advisory write lock set by process 2762
      /u06/oracle/orcl/undotbs01.dbf
How to find the Free memory in Solaris
sar -r 5 10

Output of above command

SunOS evscpsvdu1 5.10 Generic_142900-13 sun4u    04/19/2011

22:50:58 freemem freeswap

22:51:03 1408275 73715456
22:51:08 1408264 73715430
22:51:13 1408258 73715360
22:51:18 1407912 73708282
22:51:23 1408250 73715312
22:51:28 1408245 73715296
22:51:33 1408240 73715280
22:51:38 1408165 73713805
22:51:43 1408227 73715184
22:51:48 1408223 73715152

Average  1408206 73714456

Free Memory=freemen*8 (pagesize=8k)
================================================================
 vmstat 5 10
 kthr      memory            page            disk          faults      cpu
 r b w   swap  free  re  mf pi po fr de sr s0 s1 s2 s3   in   sy   cs us sy id
 0 0 0 38188840 12557120 133 444 15 2 2 0 0 0 11 12  0 3765 13299 3727 1  0 99
 0 0 0 36858048 11264800 974 2330 2 3 3 0 0 0  1  1  1 5391 18970 6072 2  1 98
 0 0 0 36857824 11264960 32 117 0 0 0 0  0  0  5  5  0 4694 9963 4552  2  0 98
 0 0 0 36318352 10727032 0 30348 0 0 0 0 0  0  0  0  0 7473 14610 11684 20 2 78
 0 0 0 34927520 9336272 0 32633 0 0 0 0  0  0 16 19  0 7289 14426 11784 24 2 73
 0 0 0 34012408 8420920 0 9239 0 0 0  0  0  0  0  0  0 9550 17127 14913 11 1 88
 0 0 0 33966480 8374968 0 101 0 0  0  0  0  0  1  1  0 10579 19914 15607 5 1 95
 0 0 0 33819584 8228472 0 11371 0 0 0 0  0  0 47 47  1 33331 69353 61302 13 3 84
 0 0 0 33109904 7520000 33 18606 6 0 0 0 0  0  6  6  0 50641 137140 98266 21 5 74
 0 0 0 32416064 6826744 131 17770 0 0 0 0 0 0  0  0  0 44825 89925 86716 19 4 77

For Swap Memory Status
----------------------
swap -s
swap -l
Commands to find system configuration in Solaris
prtdiag
prtconf
swap -l
Comments