Wednesday 24 December 2014

Basic Linux Commands

To check the Size of RAM in Unix

HP-UX

swapinfo –tm
Linux
free –m
free -g
AIX
lsdev -C|grep mem
Solaris
prtconf|grep -i mem

To Check number of CPU’s in the Server

Linux
cat /proc/cpuinfo | grep “processor”|wc –l
HP-UX
ioscan -C processor | grep processor | wc –l
SUN Solaris
psrinfo -v|grep “Status of processor”|wc –l
AIX
lsdev -C|grep Process|wc –l
To identify High Disk I/o using Unix command
/usr/bin/ps -eo pid,user,pcpu,args | grep -v %CPU |  sort -nbk 3 | tail -25
To report the current CPU Activity
sar -u 1 5
sar utility can be used to provide various information about the server resources.
In the above example the parameters used and the details are as mentioned below
-u option is for CPU related information
1 is the frequency of execution of the command in seconds
5 is the number of times the command should be executed.
So the command displays the CPU information every 1 second for 5 times.
It reports the CPU related usage by the user(%usr), system(%sys), the CPU Wait for I/O(%wio) and the Idle Percentage(%idle).
Sample Output
14:08:17    %usr    %sys    %wio   %idle   physc
14:08:18      25        0          0           75       4.00
14:08:19      25        0          0           74       4.00
14:08:20      25        0          0           75       4.00
14:08:21      25        0          0           75       4.00
14:08:22      25        0          0           75       4.03
Average       25        0          0           75       4.01

Finding files in Unix based on specific criteria

FIND FILES THAT WERE MODIFIED/ACCESSED WITHIN A SPECIFIED TIME
            $   find  /<your path>  -mtime   1  -type   f 
This command would return files modified  in the last 24 hours .
You can use -mtime option to return a list of files that were last modified N*24 hours ago. For example to find a file in last month (30 days) you would need to use -mtime +30 options.
  • -mtime +30   means you are looking for a file modified 30 days ago.
  • -mtime -30    means less than 30 days.
  • -mtime 30      If you skip + or – it means exactly 30 days
      -type f      searches only for files and not directories
To list the files in the directory tree that were modified within the past five minutes, type
$  find /<your path>  -mmin -5
To return a list of files that were accessed in the last 24 hours you would need to use the–atime option.
$  find  /<your path>   -atime   1  -type   f  ******************************************************************
FINDING FILES WITH A SPECIFIC EXTENTION WITHIN A DIRECTORY
         $  find   /<your path>   -name  “*.cfg”
The command –name matches the file names with the specified pattern
*****************************************************************
FINDING FILES BASED ON THE FILE-PERMISSIONS
Files with execute permission for group :
$ find /<your path>  -perm g=x   -type f 
Files with execute permission for others:
$ find /<your path>  -perm  o=x   -type f
Where ‘g’ denotes groups and ‘o’ denotes others. denotes execute permission.
*****************************************************************
KILLING ACTIVE UNIX PROCESSES FOR SPECIFIC COMPONENTS
ps -ef |grep applmgr |grep <Component Name> |grep -v grep |awk ‘{print $2}’ |xargs kill -9For example to kill all active forms processes, we can use the following command:
ps -ef |grep applmgr |grep frm | grep -v grep |awk '{print $2}' |xargs kill -9
ps -ef | grep FNDLIBR | grep -v grep | awk '{print $2}' | xargs kill -9        -- to kill all FNDLIBR


Linux commands:
to check the load average :
$ cat  /proc/loadavg
2.70 2.45 2.13 1/450 6959
Use the below command to check the number of CPU cores on the server.
$ grep 'process' /proc/cpuinfo | wc -l
32
[oracle@UATORADB2 ~]$ cat /proc/cpuinfo |grep core|wc -l
48
[oracle@UATORADB2 ~]$ cat /proc/cpuinfo |grep proc|wc -l
24
--To check process count by each user
ps hax -o user | sort | uniq -c
Finding the processes that are causing high I/O
iotop
to check the proccess reads and writes:
cat /proc/16528/io
Finding what files are being written too heavily:
lsof -p 16528



No comments:

Post a Comment