Linux Usefull commands

df -kh
free -m
cat /proc/cpuinfo | grep processor | wc -l
cat /etc/redhat-release
ps -ef|grep mysql

Check number of CPU’s

–$cat /proc/cpuinfo

Check memory information

–cat /proc/meminfo

Check swap

–$swapon -s

Kernel parameter

–#/sbin/sysctl -a
cat /etc/sysctl.conf

System error log


Nic configuration

–ifconfig -a

Directory Commands – mkdir

To create a new directory below current directory:

–$ mkdir new-dir-name

To create multiple versions of directory:

–$ mkdir -p dir1/dir2/dir3

Creates dir1 first. Creates dir2 under dir1. Creates dir3 under dir2
To create a directory with given permissions:

–$ mkdir -m 754 new-dir

new-dir will be created with 754 permissions

Directory Commands – rmdir

To remove a directory:

–$ rmdir dir-name

rmdir can remove only empty directories
To remove directory along parent directory:

–$rmdir -p dir1/dir2/dir3

Deletes all the directories

Directory Commands – cd

Stands for change directory
Used to navigate among directories

–$ cd dir1

Takes to dir1 directory

–$ cd

Takes to the home directory
Can give full-path-name or relative-path-name as argument

Linux Macine:

–# uname -m

File Backup using ‘tar’ command
The “tar” command stands for tape archive that generally used by system/database administrator to
write archives directly to tape devices or can use it to create archives files on disk.
The ‘tar’ program is easy to use and transportable having limits on file name size,
won’t backup special files, does not follow symbolic links, and doesn’t support multiple volumes.
The main advantage is that ‘tar’ is supported every where or can be moved easily from one disk to another disk or machine to machine.
It is also useful for copying directories.

The ‘tar’ program takes one of three function command line arguments:

c – to create a tar file

t – table of contents (see the name of all files)

x – extract (restore) the contents of the tar file.

In addition to above function command line argument these argument are useful:

f – Specifies filename

z – Use zip/unzip to compress the tar file or to read from a compressed tar file.

v – Verbose output, show the file being stored into or restored from tar file.


To tar all .arc and .ctf files into a tar file named data.tgz use:

–tar cvzf data.tgz *.arc *.ctf

This will creates (c) a compressed tar file name data.tgz (f) and shows the file being stored into the tar file (v). The .tgz suffix is a convention for gzipped tar file.

To extract files from tar file

–tar –xvf filename.tar

To tar up all files and directories under current directories or under PROD1 directory and writes files to filename.tar.

–tar cvzf data.tgz shahid123

–tar -cvf /tmp/filename.tar .

–tar -cvf /tmp/filename.tar PROD1

It is often more useful to tar a directory (which tar all files and subdirectories recursively unless you specify other option)

To see a tar file table of contents

–tar tzf data.tgz

To display only the content in tar binary file

–tar –tvf filename.tar

When file size is too large (more than 8GB), use –E option.

–tar -cvfE /data/oradata/tars/PROD1/large_file_blob.tar

Retrieve Oracle version information

SQL> select * from v$version where banner like ‘Oracle%’;

Other Commands

As a DBA you need to use frequent OS command or alt least how to query the OS and its hardware.
Usually we do it before fresh install upgrade, migrate of database/operating system. Here is some of the useful frequently
used day to day OS command for DBA.

To find and delete files older than N number of days:
find . -name ‘*.*’ -mtime +[N in days] -exec rm {} ;
Example : find . -mtime +5 -exec rm {} ;
The above command is specially useful to delete log, trace, tmp file

To list files modified in last N days:
find . -mtime – -exec ls -lt {} ;
Example: find . -mtime +3 -exec ls -lt {} ;1
The above command will find files modified in last 3 days

To sort files based on Size of file:
ls -l | sort -nk 5 | more
useful to find large files in log directory to delete in case disk is full

To find files changed in last N days :
find -mtime -N –print
Example: find -mtime -2 -print

To find CPU & Memory detail of linux:
cat /proc/cpuinfo (CPU)
cat /proc/meminfo (Memory)

Linux: cat /proc/cpuinfo|grep processor|wc -l

HP: ioscan -fkn -C processor|tail +3|wc -l

Solaris: psrinfo -v|grep “Status of processor”|wc –l

psrinfo -v|grep “Status of processor”|wc –l

lscfg -vs|grep proc | wc -l

To find if Operating system in 32 bit or 64 bit:

ON Linux: uname -m
On 64-bit platform, you will get: x86_64 and on 32-bit patform , you will get:i686
On HP: getconf KERNEL_BITS
On Solaris: /usr/bin/isainfo –kv
On 64-bit patform, you will get: 64-bit sparcv9 kernel modules and on 32-bit, you will get: 32-bit sparc kernel modules. For solaris you can use
directly: isainfo -v
If you see out put like: “32-bit sparc applications” that means your O.S. is only 32 bit but if you see output like “64-bit sparcv9 applications”
that means youe OS is 64 bit & can support both 32 & 64 bit applications.

To find if any service is listening on particular port or not:
netstat -an | grep {port no}
Example: netstat -an | grep 1523

To find Process ID (PID) associated with any port:
This command is useful if any service is running on a particular port (389, 1521..) and that is run away process which you wish to terminate using kill
lsof | grep {port no.} (lsof should be installed and in path)

How to kill all similar processes with single command:
ps -ef | grep opmn |grep -v grep | awk ‘{print $2}’ |xargs -i kill -9 {}

Locating Files under a particular directory:
find . -print |grep -i test.sql

To remove a specific column of output from a UNIX command:
For example to determine the UNIX process Ids for all Oracle processes on server (second column)
ps -ef |grep -i oracle |awk ‘{ print $2 }’

Changing the standard prompt for Oracle Users:
Edit the .profile for the oracle user

Display top 10 CPU consumers using the ps command:
/usr/ucb/ps auxgw | head -11

Show number of active Oracle dedicated connection users for a particular ORACLE_SID
ps -ef | grep $ORACLE_SID|grep -v grep|grep -v ora_|wc -l

Display the number of CPU’s in Solaris:
psrinfo -v | grep “Status of processor”|wc -l

Display the number of CPU’s in AIX:
lsdev -C | grep Process|wc -l

Display RAM Memory size on Solaris:
prtconf |grep -i mem

Display RAM memory size on AIX:
First determine name of memory device: lsdev -C |grep mem
then assuming the name of the memory device is ‘mem0’ then the command is: lsattr -El mem0
Swap space allocation and usage:
Solaris : swap -s or swap -l
Aix : lsps -a

Total number of semaphores held by all instances on server:
ipcs -as | awk ‘{sum += $9} END {print sum}’
View allocated RAM memory segments:
ipcs -pmb

Manually deallocate shared memeory segments:
ipcrm -m ”

Show mount points for a disk in AIX:
lspv -l hdisk13

Display occupied space (in KB) for a file or collection of files in a directory or sub-directory:
du -ks * | sort -n| tail

Display total file space in a directory:
du -ks .

Cleanup any unwanted trace files more than seven days old:
find . *.trc -mtime +7 -exec rm {} ;

Locate Oracle files that contain certain strings:
find . -print | xargs grep rollback

Locate recently created UNIX files:
find . -mtime -1 -print

Finding large files on the server:
find . -size +102400 -print
Crontab Use:

To submit a task every Tuesday (day 2) at 2:45PM
45 14 2 * * /opt/oracle/scripts/ > /dev/null 2>&1

To submit a task to run every 15 minutes on weekdays (days 1-5)
15,30,45 * 1-5 * * /opt/oracle/scripts/ > /dev/null 2>&1

To submit a task to run every hour at 15 minutes past the hour on weekends (days 6 and 0)
15 * 0,6 * * opt/oracle/scripts/ > /dev/null 2>&1

UNIX Useful Commands

1) Find whether OS is 64/32 Bit Kernel in UNIX.

uname -a

2) Find free physical memory in UNIX.

free -m

3) Find CPU details in UNIX.

cat /proc/cpuinfo

4) Find files modified within specific time.

find . -mtime -3 (modified less than 3days ago)

5) command used to alter file permissions.

chmod 777 abc.txt

6) Command used to reset the Ownership.

chown oracle:dba abc.txt

7) command used to set, or reset, the users login password.

Passwd username

8) Kill specific process in UNIX.

Kill -9 processid

9) Command used for display last given lines of a file.

tail -n alert_PROD.log

10) Command used for intall a rpm package.

rpm -ivh packagename.rpm

11) Command used to querry about any rpm package

rpm -q packagename

12) Command to Check the server up time


13) Command to check the file versions

strings -a <filename> |grep ‘$Header’

14) Command will keep ‘n’ number of days files and remove rest of file.

find . -mtime +n -exec rm {} ; &

15) Basic commands for vi editor

i :- insert before cursor.

l : insert begining of the line.

a :- append after the cursor.

A :- Append at the end of the line.

o :- insert a blank line below the cursor.

O :- insert a blank line above the cursor position.

h :- from current position one char towards left .

I :- from current position one char towards right.

j :- from current position one line towards down.

k :- from current position one line towards up.

Shift+g :- go to end of the file.

Shift+:1 :- go to top of the file.

dd –> delete the ful line.

:q! —> closing the file without saving any changes.

:wq! –> save the changes and force close.

:w –> to save the changes without closing the file.

UNIX Crontab Basics

A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
# Minute Hour Month Day Month Weekday Command
# 0-59 0-23 1-31 1-12 0-6 (0=Sunday)
* * * * * command to be executed
– – – – –
| | | | |
| | | | +—– day of week (1 – 7) (monday = 1)
| | | +——- month (1 – 12)
| | +——— day of month (1 – 31)
| +———– hour (0 – 23)
+————- min (0 – 59)
crontab -e Edit your crontab file, or create one if it doesn’t already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file.
To run the calendar command at 6:30 a.m. every Monday, Wednesday, and Friday, enter:

30 6 * * 1,3,5 /usr/bin/calendar

To run the calendar command every day of the year at 6:30, enter the following:

30 6 * * * /usr/bin/calendar

To run a script called maintenance every day at midnight in August, enter the following:

0 0 * 8 * /u/harry/bin/maintenance

Note : You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use,
crontab if your name does not appear in the file /usr/lib/cron/cron.deny. If only cron.deny exists and is empty


scp stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.

You can this way copy files from or to a remote server, you can even copy files from one remote server to another remote server, without passing through your PC.
scp [[user@]from-host:]source-file [[user@]to-host:][destination-file]

Description of options

from-host: Is the name or IP of the host where the source file is, this can be omitted if the from-host is the host where you are actually issuing the command

user: Is the user which have the right to access the file and directory that is supposed to be copied in the cas of the from-host and the user who has the rights to write in the to-host

source-file:Is the file or files that are going to be copied to the destination host, it can be a directory but in that case you need to specify the -r option to copy the contents of the directory

destination-file:Is the name that the copied file is going to take in the to-host, if none is given all copied files are going to maintain its names

-p Preserves the modification and access times,
as well as the permissions of the source-file in the destination-file
-q Do not display the progress bar
-r Recursive, so it copies the contents of the
source-file (directory in this case) recursively
-v Displays debugging messages


[oracle@testdb]$ scp java.tar.gz tamim@
The authenticity of host ‘ (’ can’t be established.
RSA key fingerprint is 23:b9:a4:b9:93:99:28:1f:4c:08:fa:8a:5f:d7:10:d0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘’ (RSA) to the list of known hosts.
tamim@’s password:
java.tar.gz 100% 35MB 11.7MB/s 00:03

File is successfully transfer to the host in home/tamim directory

To copy a directory user scp –r

Some useful Linux Command for DBA

ls: List files
cp: Copy files
mv: Move and rename files
mkdir: Make a directory
alias: Define command macros
rm: Remove files and directories
more: Page through output
head: Show beginning of file contents
tail: Show end of file contents
df: Display filesystem space usage
du: Display directory disk space usage
cat: Show and concatenate files
grep: Search for patterns in files
chmod: Change permissions of files
chown: Change owner of files
zip: Compress and package files together
gedit: A WYSIWYG text editor
export: Make environment settings global
ps: List running processes
touch: Change file time stamps
id: Show information about the current user
sudo: Execute commands as another user

Standard Measurement Tools
• Top Resource Consumers: top
• System Activity Reporter: sar
• Virtual Memory Statistics: vmstat
• I/O Statistics: iostat
• System Log files: /var/log/messages
Linux Tools
• X-based tools: xosview
• The /proc virtual file system
• Free and used memory: free
Tools for monitoring and tuning CPU include:
• top
• pstree and free
• vmstat
• Syntax: vmstat <interval> <count>
• Example : # vmstat 2 5
• mpstat –p All
• sar –u
• Syntax: #sar -B <frequency> <count>
#sar -R <frequency> <count>
• Example : #sar -B 2 3
#sar -R 2 3
• xosview
• xload
• System Monitor
Measuring Total Memory
• top
• free
• cat /proc/meminfo
Monitoring and Tuning I/O

• /proc file system
• sar -d
• I/O statistics by device [iostat –d]
Syntax : iostat -d <interval> <count>
Eample : #iostat -d 2 2
• I/O activity by partition
iostat –d -p <interval> <count>
• vmstat
• xosview

Check number of CPU’s

$cat /proc/cpuinfo

Check memory information

cat /proc/meminfo

Check swap

$swapon -s

Kernel parameter

#/sbin/sysctl -a
cat /etc/sysctl.conf

System error log


Nic configuration

ifconfig -a

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: