UNIX COMMANDS
FIND: find command is case sensitive command ie string and String are different.
1) find / -name "string" ---- finds the file/directory starting with string under root directory
2) find / -name "string" -type f -print --- finds the file starting with string under root directory
3) find / -name "string" -type d -print --- finds the directory starting with string under root directory
4) If you need to do action on couple of files then go for "exec XXXXX {} \;" xxxx is the command
i) find /usr -name "*.conf" -exec chmod 777 {} \; -- It search for conf file and executes rwx permissions on all the files under /usr ending with conf.
ii) find /root -name "*.java" -exec grep -il string {} \; --- finds for the java files which consists of the word string.
5) find . -type f -print | xargs grep -il 'bin/ksh
[root@localhost bin]# find / -name "*.java" -exec grep -il string {} \;| more
/Weblogic/apps/weblogic10.3/wlserver_10.3/samples/server/medrec/modules/common/src/com/bea/medrec
/common/naming/NamingClient.java
/weblogic10.3/wlserver_10.3/samples/server/medrec/modules/common/src/com/bea/medrec
/common/naming/CachingNamingClientDecorator.java
/weblogic10.3/wlserver_10.3/samples/server/medrec/modules/common/src/com/bea/medrec
/common/naming/NamingException.java
5) find . -type f -exec ls -s {} \; | sort -n -r | head -5 -- which searches for a file and prints top 5 based on size of the file.
6)find . -name *.* | xargs grep "oldip" ---- which is used to serch a word in a file
VI Editor:
ctrl+b -- move screen backward
ctrl+f -- move screen forward
shift+g -- go to end of line in the file
0 --- begining of the current line
$ -- end of the line
:0 -- begining of the file
:$ -- end of the file
:n -- Go to partiicular file.
?String -- forward search use n or N
N-- backword search
n-- forward search
SORT:
FIND: find command is case sensitive command ie string and String are different.
1) find / -name "string" ---- finds the file/directory starting with string under root directory
2) find / -name "string" -type f -print --- finds the file starting with string under root directory
3) find / -name "string" -type d -print --- finds the directory starting with string under root directory
4) If you need to do action on couple of files then go for "exec XXXXX {} \;" xxxx is the command
i) find /usr -name "*.conf" -exec chmod 777 {} \; -- It search for conf file and executes rwx permissions on all the files under /usr ending with conf.
ii) find /root -name "*.java" -exec grep -il string {} \; --- finds for the java files which consists of the word string.
5) find . -type f -print | xargs grep -il 'bin/ksh
[root@localhost bin]# find / -name "*.java" -exec grep -il string {} \;| more
/Weblogic/apps/weblogic10.3/wlserver_10.3/samples/server/medrec/modules/common/src/com/bea/medrec
/common/naming/NamingClient.java
/weblogic10.3/wlserver_10.3/samples/server/medrec/modules/common/src/com/bea/medrec
/common/naming/CachingNamingClientDecorator.java
/weblogic10.3/wlserver_10.3/samples/server/medrec/modules/common/src/com/bea/medrec
/common/naming/NamingException.java
5) find . -type f -exec ls -s {} \; | sort -n -r | head -5 -- which searches for a file and prints top 5 based on size of the file.
6)find . -name *.* | xargs grep "oldip" ---- which is used to serch a word in a file
VI Editor:
ctrl+b -- move screen backward
ctrl+f -- move screen forward
shift+g -- go to end of line in the file
0 --- begining of the current line
$ -- end of the line
:0 -- begining of the file
:$ -- end of the file
:n -- Go to partiicular file.
?String -- forward search use n or N
N-- backword search
n-- forward search
SORT:
1) sort -n -t
n -- used to sort numerical values.
r -- ascending or descending order
t -- delemiter
LS:
1) ls -l /etc -- list all the file in etc directory
2) ls -altr /etc -- list all the files with permissions links owner group size lastmodifieddate name
3) ls -ld /etc -- gives complete details of the files in a directory.
4) ls -lt -- gives the file with last modified first
5) ls -ltr -- displays files in reverse order( recently modified last)
Netstat:
Netstat –anP tcp | grep ipaddress | wc –l to grep the number of connections to the web server
$netstat -rn
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
192.168.1.0 192.168.1.11 U 1 1444 le0
224.0.0.0 192.168.1.11 U 1 0 le0
default 192.168.1.1 UG 1 68276
127.0.0.1 127.0.0.1 UH 1 10497 lo0
netstat -an | grep LISTEN | grep xxxx to grep for the port number
VMSTAT:
Vmstat reports virtual memory statistics of process, virtual memory, disk, trap,
and CPU activity.
On multicpu systems, vmstat averages the number of CPUs into the output. For perprocess
statistics .Without options, vmstat displays a one-line summary of the virtual
memory activity since the system was booted.
Example% vmstat 5
procs 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 11456 4120 1 41 19 1 3 0 2 0 4 0 0 48 112 130 4 14 82
0 0 1 10132 4280 0 4 44 0 0 0 0 0 23 0 0 211 230 144 3 35 62
0 0 1 10132 4616 0 0 20 0 0 0 0 0 19 0 0 150 172 146 3 33 64
0 0 1 10132 5292 0 0 9 0 0 0 0 0 21 0 0 165 105 130 1 21 78
Identifying the bottlenecks:
1.) If the number of processes in run queue (procs r) are consistently greater than the
number of CPUs on the system it will slow down system as there are more processes then
available CPUs .
2.) If this number is more than four times the number of available CPUs in the system
then system is facing shortage of cpu power and will greatly slow down the processess on
the system.
3.) If the idle time (cpu id) is consistently 0 and if the system time (cpu sy) is double the
user time (cpu us) system is facing shortage of CPU resources. The system time should
not be more than the user time at any give instance.
4.) Memory bottlenecks are determined by the scan rate (sr) . The scan rate is the pages
scanned by the clock algorithm per second. If the scan rate (sr) is continuously over 200
pages per second then there is a memory shortage. Scan rate and page out should be zero
or 1.
PSRINFO:
To determine the number of processors in the system and their speed, use the
psrinfo -v command. In Solaris 10, -vp prints additional information.
# psrinfo -v
Status of processor 0 as of: 05/16/08 04:34:25
Processor has been on-line since 08/04/07 20:10:53.
The sparcv9 processor operates at 900 MHz ,
and has a sparcv9 floating point processor.
Status of processor 1 as of: 05/16/08 04:34:25
Processor has been on-line since 08/04/07 20:10:53.
The sparcv9 processor operates at 900 MHz,
and has a sparcv9 floating point processor.
Status of processor 2 as of: 05/16/08 04:34:25
Processor has been on-line since 08/04/07 20:10:53.
The sparcv9 processor operates at 900 MHz,
and has a sparcv9 floating point processor.
Status of processor 3 as of: 05/16/08 04:34:25
Processor has been on-line since 08/04/07 20:10:43.
The sparcv9 processor operates at 900 MHz,
and has a sparcv9 floating point processor.
PRSTAT:
The most important command used to check the usage of the user was prstat
Typical headers of the prstat command.
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
PID – Process Id
USERNAME – Name of the user using the processor
SIZE – Process Size
RSS - Resident Set Size ( Size of the process on the memory)
STATE – State of the process / Cpu information
PRI - Priority
NICE – Nice value
TIME – Amount of time the process is running on the CPU
CPU PROCESS/NLWP – Command/Number of light weight processes / Threats
NPROC – Number of processes
USERNAME – Name of the User
MEMORY – Percentage of memory consumed.
Occassionally there are many small processes, each of which consumes a small piece of
the CPU. On a system such as a computing server that is shared by many users, prstat
can be used to determine which user (as opposed to which processes) is consuming the
most resources. If the user consuming the most resources on the system can be identified,
it is possible to move at least part of the work to another machine. To have prstat report
statistics about resource consumption by user, add the -a option to the prstat command
line.
Adding the -a option to any prstat command will identify how many processes each
user is using, what percent of the CPUs, and how much memory, they are using on a
system, as shown above. The command prstat -s cpu -a 8 asks for the top 8
processes consuming the CPU and a list of resource consumption statistics for each user
prstat
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
1685 rsd 758M 575M cpu3 0 10 4:07.11 12% java/95
828 root 2339M 1302M sleep 28 10 0:00.31 0.1% java/66
719 root 4312K 3848K sleep 55 0 0:00.00 0.0% mibiisa/12
7067 root 1776K 1408K cpu0 58 0 0:00.00 0.0% prstat/1
6743 root 669M 198M sleep 58 0 0:17.25 0.0% java/20
598 root 13M 8808K sleep 58 0 0:31.25 0.0% jre/10
21847 root 667M 386M sleep 58 0 0:00.00 0.0% java/21
prstat -a will give number of processors the users are owned too.
Scripting Sites:
http://www.softpanorama.org/Tools/xargs.shtml
Monitoring Commands:
prstat -a -n 15 - to get first 15 hign process used commands.
vmstat - to find the virtualmemory utilization.
mpstat - to find the percentage of cpu.
top is for physical memory.
./MemUtil -- to find percentage of physical memory utilised.
n -- used to sort numerical values.
r -- ascending or descending order
t -- delemiter
LS:
1) ls -l /etc -- list all the file in etc directory
2) ls -altr /etc -- list all the files with permissions links owner group size lastmodifieddate name
3) ls -ld /etc -- gives complete details of the files in a directory.
4) ls -lt -- gives the file with last modified first
5) ls -ltr -- displays files in reverse order( recently modified last)
Netstat:
Netstat –anP tcp | grep ipaddress | wc –l to grep the number of connections to the web server
$netstat -rn
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
192.168.1.0 192.168.1.11 U 1 1444 le0
224.0.0.0 192.168.1.11 U 1 0 le0
default 192.168.1.1 UG 1 68276
127.0.0.1 127.0.0.1 UH 1 10497 lo0
netstat -an | grep LISTEN | grep xxxx to grep for the port number
VMSTAT:
Vmstat reports virtual memory statistics of process, virtual memory, disk, trap,
and CPU activity.
On multicpu systems, vmstat averages the number of CPUs into the output. For perprocess
statistics .Without options, vmstat displays a one-line summary of the virtual
memory activity since the system was booted.
Example% vmstat 5
procs 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 11456 4120 1 41 19 1 3 0 2 0 4 0 0 48 112 130 4 14 82
0 0 1 10132 4280 0 4 44 0 0 0 0 0 23 0 0 211 230 144 3 35 62
0 0 1 10132 4616 0 0 20 0 0 0 0 0 19 0 0 150 172 146 3 33 64
0 0 1 10132 5292 0 0 9 0 0 0 0 0 21 0 0 165 105 130 1 21 78
Identifying the bottlenecks:
1.) If the number of processes in run queue (procs r) are consistently greater than the
number of CPUs on the system it will slow down system as there are more processes then
available CPUs .
2.) If this number is more than four times the number of available CPUs in the system
then system is facing shortage of cpu power and will greatly slow down the processess on
the system.
3.) If the idle time (cpu id) is consistently 0 and if the system time (cpu sy) is double the
user time (cpu us) system is facing shortage of CPU resources. The system time should
not be more than the user time at any give instance.
4.) Memory bottlenecks are determined by the scan rate (sr) . The scan rate is the pages
scanned by the clock algorithm per second. If the scan rate (sr) is continuously over 200
pages per second then there is a memory shortage. Scan rate and page out should be zero
or 1.
PSRINFO:
To determine the number of processors in the system and their speed, use the
psrinfo -v command. In Solaris 10, -vp prints additional information.
# psrinfo -v
Status of processor 0 as of: 05/16/08 04:34:25
Processor has been on-line since 08/04/07 20:10:53.
The sparcv9 processor operates at 900 MHz ,
and has a sparcv9 floating point processor.
Status of processor 1 as of: 05/16/08 04:34:25
Processor has been on-line since 08/04/07 20:10:53.
The sparcv9 processor operates at 900 MHz,
and has a sparcv9 floating point processor.
Status of processor 2 as of: 05/16/08 04:34:25
Processor has been on-line since 08/04/07 20:10:53.
The sparcv9 processor operates at 900 MHz,
and has a sparcv9 floating point processor.
Status of processor 3 as of: 05/16/08 04:34:25
Processor has been on-line since 08/04/07 20:10:43.
The sparcv9 processor operates at 900 MHz,
and has a sparcv9 floating point processor.
PRSTAT:
The most important command used to check the usage of the user was prstat
Typical headers of the prstat command.
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
PID – Process Id
USERNAME – Name of the user using the processor
SIZE – Process Size
RSS - Resident Set Size ( Size of the process on the memory)
STATE – State of the process / Cpu information
PRI - Priority
NICE – Nice value
TIME – Amount of time the process is running on the CPU
CPU PROCESS/NLWP – Command/Number of light weight processes / Threats
NPROC – Number of processes
USERNAME – Name of the User
MEMORY – Percentage of memory consumed.
Occassionally there are many small processes, each of which consumes a small piece of
the CPU. On a system such as a computing server that is shared by many users, prstat
can be used to determine which user (as opposed to which processes) is consuming the
most resources. If the user consuming the most resources on the system can be identified,
it is possible to move at least part of the work to another machine. To have prstat report
statistics about resource consumption by user, add the -a option to the prstat command
line.
Adding the -a option to any prstat command will identify how many processes each
user is using, what percent of the CPUs, and how much memory, they are using on a
system, as shown above. The command prstat -s cpu -a 8 asks for the top 8
processes consuming the CPU and a list of resource consumption statistics for each user
prstat
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
1685 rsd 758M 575M cpu3 0 10 4:07.11 12% java/95
828 root 2339M 1302M sleep 28 10 0:00.31 0.1% java/66
719 root 4312K 3848K sleep 55 0 0:00.00 0.0% mibiisa/12
7067 root 1776K 1408K cpu0 58 0 0:00.00 0.0% prstat/1
6743 root 669M 198M sleep 58 0 0:17.25 0.0% java/20
598 root 13M 8808K sleep 58 0 0:31.25 0.0% jre/10
21847 root 667M 386M sleep 58 0 0:00.00 0.0% java/21
prstat -a will give number of processors the users are owned too.
Scripting Sites:
http://www.softpanorama.org/Tools/xargs.shtml
Monitoring Commands:
prstat -a -n 15 - to get first 15 hign process used commands.
vmstat - to find the virtualmemory utilization.
mpstat - to find the percentage of cpu.
top is for physical memory.
./MemUtil -- to find percentage of physical memory utilised.