Monday, March 10, 2008

Unix Commands - Syntax

Some basic unix command usage examples


To delete files (with extension .dbf) in a folder which are older than 7 days. This may be put inside a shell script for executing as a cron job


#!/bin/ksh
$ find /u02/ora/archives -type f -mtime +7 -name \*.dbf -print -exec rm {} \;

Example usages link

To delete ALL files owned by a user:
$ find . -user USERID awk '{print "rm "$NF}' ksh

'find' command links

To Copy files matching certain criteria to another directory (just to practice grep, printf and awk features...)

$ ls -altr grep "Jul 3" grep -v ^d awk '{printf("cp %s ./new_dir/%s\n",$9,$9)}' sh

$ for mystatement in `cat myfile.dat awk '{print $1}'`; <<EOF!
do sqlplus / as sysadmin mystatement ;
EOF!

$ chown oracle:dba * : to change owner and group of all files in current dir

$ ps -ef grep 234 awk '{print $2}' xargs kill

$ ps -ef egrep 'pmonsmonlgwrdbwarc' grep -v grep

$ ls -altr

$ ptrace [processid]

$ pfiles [processid]

$ ptree [processid]

$ truss -p [processid]

$ top

$ sort -t: +2n -3 /etc/passwd
-t : separator
+2n : begin - nth occurance of separator
-3 : end

$ who sort +4n

$ vmstat interval 6

$ mpstat - for multiprocessor

$ sar

$ iostat

$ uname -a

$ at 8:15

$ uucp

$ du -h : Disk usage

$ bdf . : to find the disk free space on a particular mount volume (in %)

$ df : to find the disk free space on a particular mount volume

$ tail -100 filename.ext

$ tnsping INSTNAME

$ which top

$ bc : calculating arithmatics from command line

$ id -a : user id and group id

$ su - : switch to root user i.e. superuser

$ tar -cvvf tarfile.tar *.* for creating tarfile
$ tar -xvvf tarfile.tar for extracting from existing tarfile
$ tar -xvvzf tarfile.tar.gz for uncompress

$ rcp -r user@sourcehostname:sourcefileordir user@desthostname:destfileordir

$ gzip filename for compressing the file replaces the file with filename.gz
$ gzip -dvf zipfile.gz for uncompressing a .gz file


Useful link : Shell Programming

No comments: