Linux Common Queries

Lot of readers asked me to post on Linux hence first post on Linux covers common queries from Apps DBA’s w.r.t. Linux.

 If you use any command in Linux/Unix very frequently and wish to share with our readers please leave it as comment

Q: How to delete files older than N number of days ? (Useful in delete log, trace, tmp file )
find . -name ‘*.*’ -mtime +[N in days]  -exec rm {} \;   ( This command will delete files older then N days in that directory, always good to use it when you are in applcsf/ tmp,out,log directory)

Q: How to list files modified in last N days
find . -mtime -<ndays> -exec ls -lt {} \;

So to find files modified in last 3 days
find . -mtime -3 -exec ls -lt {} \;

Q: How to sort files based on Size of file ? ( useful to find large files in log directory to delete in case disk is full )
ls -l | sort -nrk 5  | more

Q: How to find files changed in last N days (Solaris)
find <dir_name> -mtime -N -print

Q: How to extract cpio file
cpio -idmv < file_name   (Don’t forget to use sign < before file name)

Q: How to find CPU & Memory detail of linux
cat /proc/cpuinfo  (CPU)
cat /proc/meminfo (Memory)

Q: How to find if Operating system in 32 bit or 64 bit ?
For solaris use command
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
32-bit sparc applications
above means your o.s. is 64 bit & can support both 32 & 64 bit applications

Q: How to find if any service is listening on particular port or not ?
netstat -an | grep {port no}
  
For example if you know that OID is running on 389 port so to check if OID services is listening or not then use
netstat -an | grep 389

Q: How 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 command
lsof | grep {port no.}  (lsof should be installed and in path)

Q: How to change a particular pattern in a file ?
Open file using vi or any other editor, go in escape mode (by pressing escape) and use

:1,$s/old_pattern/new_parameter/gc   ( g will change globally, c will ask for confirmation before changing )

Q: How to find a pattern in some file in a directory ?
grep pattern file_name
  ( to find pattern in particular file )
grep pattern * ( in all files in that directory )
If you know how to find a pattern in files in that directory recursively please answer that as comment

Q:  How to create symbolic link to a file ?
ln -s  pointing_to  symbolic_name

e.g. If you want to create symbolic link from a -> b
ln -s b a   
(Condition:you should have file b in that directory & there should not be any file with name a)

Q: How to setup cronjob  (cronjob is used to schedule job in Unix at O.s. Level )
crontab -l( list current jobs in cron)
crontab -e ( edit current jobs in cron)

_1_  _2_  _3_  _4_  _5_  executable_or_job
Where
1 – Minutes (0-59)
2 – Hours ( 0-24)
3 – day of month ( 1- 31 )
4 – Month ( 1-12)
5 – A day of week ( 0- 6 ) 0 -> sunday 1-> monday

e.g.  0  3  * * 6  Means run job at 3AM every saturday

This is useful for scheduling ftp, rman backup or removed old log files regularly.
 

More unix/linux commands coming soon ….

About the Author Atul Kumar

Oracle ACE, Author, Speaker and Founder of K21 Technologies & K21 Academy : Specialising in Design, Implement, and Trainings.

follow me on:

Leave a Comment:

17 comments
Hyder says December 12, 2007

Hi Atul,

It excellent commands for regular use.

hyder

Reply
Mohamed says January 29, 2008

Hi Atul

you asked about using grep command recursively
and this is the answer

-r or -R option like

grep -r err /var/log

thaks atul for this blog

Reply
omofuma says May 29, 2008

I am a DBA, Faculty with NIIT ABUJA NIGERIA. How do I become a member of onlineapplication DBA.I enjoy what DBAs are doing in that forum.

Thank You
OMOFUMA CHARLES

Reply
Ahmed Khan says June 7, 2008

Hi

i am trying to install a package called lesstif-0.89.9-2.i386.rpm but its giving me the below error,Actually i want to install a package called Motif Window Manager but for that first i ahve to apply lesstif-0.89.9-2.i386.rpm and then lesstif-client and at last i ahve to apply the Motif Window manager,Please find the error below.

[oratest@Linux2 patches]$ rpm -ivh lesstif-0.89.9-2.i386.rpm
warning: lesstif-0.89.9-2.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
error: Failed dependencies:
lesstif <= 0.92.32-6 conflicts with openmotif-2.2.3-10.RHEL4.5.i386
[oratest@Linux2 patches]$

Reply
lakshmikanthan says June 11, 2008

Hi
Really very usful these commands
Thanks
lakshmi

Reply
lakshmikanthan says June 11, 2008

hi,
I need some important linux command usage:

chattr,
cksum ,
du,
file ,
fsck , fuser ,lsattr, split.

useful of these commands and how to use command.
Thank u
lakshmi

Reply
lakshmikanthan says June 25, 2008

Hi,

I need automate CVS process script anyone help to me please.

Thanks
lakshmikanthan

Reply
arjun meru says July 31, 2008

very very very good forum… this is for all oracle and oracle apps dba s.

I am going to learn more and more from this…………thanks for atul……..

Reply
Sanjay says August 6, 2008

Hi Atul,

Thanks a lot for unix commands.
Can we get some advance commands mainly used in apps evn.

Regards
Sanjay

Reply
Muneer says November 6, 2008

here is a small shell script to remove temp files from /var/tmp or any other temp location.

cd /var/tmp

for i in `ls *.TMP *.t *.tmp`
do
x=`/usr/sbin/fuser -u $i`
if [ -z “$x” ]
then
rm $i
fi
done

Regards

Muneer Dar

Reply
pejisim says February 22, 2009

Very good site for all core and apps dba. The things you learn you, you can learn from reading voluminous books. omofuma charles, please drop me an email or two; I am interested in know some opportunities in Nigeria.

Reply
Paul says September 1, 2009

Hi Atul,
Is there any way on Unix (or any unix command) to find out if the file is Binary or ASCII?

Appreciate your time.

Thanks.

Reply
Atul Kumar says September 2, 2009

@ Paul

file

example if file name is abc.txt

file abc.txt

Reply
sudhakarketha says July 27, 2010

Hi Atul,

I am working as oracle apps dba consultant in Keane India, Chennai. I want to become the member of Online Apps DBA Team. Can you please suggest me on this.

Thanks

Sudhakar

Reply
Atul Kumar says July 28, 2010

@ Sudhakar,
This site is free to use but if you wish to join us to share your knowledge with other readers then admin can create account account for you and mail details to your email ID.

Please confirm by sending mail to admin @ onlineappsdba.com and one of us will contact you.

Reply
rajeev999 says November 20, 2014

implementation for the requirements given below in linux using EPOLL? if any other possibility also accepted..

-> Create 2 test threads:

-> One thread creates the event flag object and then wait for an event, And when the event occurs, it should go back waiting for the event again.

-> The 2nd thread should then send an event.

-> Compile and test that the 1st thread is suspended for waiting for the event.

-> After the 2nd thread has sent the event, the 1st should resume. Repeat and this time, send another event to the 1st thread

please respond Quickly..

thank you

Reply
Add Your Reply

Not found