|












| | This command bulletin is
an unorganized list of command examples in Unix. These
examples are not explained in detail. If you have some idea as how the command
might look like, you can find it here easily using browser search (Ctrl+f). Some of these commands are bash
shell specific.
- To find hardware details of linux box: dmesg
|less
- To find linux version: cat /proc/version
- To find cpu info: cat /proc/cpuinfo
- To unzip gzip file: gunzip something.tar.gz
- To untar tar file: tar xvf something.tar
- To unzip and untar in one step: tar xvzf something.tar.gz
- To install a software from rpm: rpm -iv myapp_someversion.rpm
- To edit your bash shell environment edit ~/.bashrc file
- To set the java and ant class path add the following lines in your bashrc file
at home directory with appropriate java and ant directories:
export JAVA_HOME=/usr/java/jdk1.5.0_09
export ANT_HOME=/home/oracle/apache-ant-1.7.0
export PATH=$PATH:${JAVA_HOME}/bin:${ANT_HOME}/bin
export CLASSPATH=./:${JAVA_HOME}/lib/tools.jar:${JAVA_HOME}/lib/rt.jar:${ANT_HOME}/lib/ant.jar
- To list all the background running oracle process in the system: ps -ef|grep "ora_"|grep
-v grep
- To give a short name to big command: alias listoraprocess="ps -ef|grep "ora_"|grep
-v grep"
- To kill all oracle process: ps -ef|grep "ora_"|grep -v grep|grep $ORACLE_SID|awk
'{print $2}'|xargs kill -9
- To list all files in current directory: find . -print
- To search for string "error" in all files in current directory: find . -print|xargs
grep -i error
- To print time of execution for the bash script:
#!/usr/bin/env bash
curtime=`date +"%s"`
#Your bash script statements here
echo "Time of execution is `expr $(date +'%s') - $curtime` seconds"
- To reboot linux in 10 minutes with broadcast message: shutdown -h +10 "scheduled
maintenance"
- To find number of logged users: who | wc -l
- To check the type of a command: type cd , type who
- To echo System variables: echo $DISPLAY $HOME $MAIL $OLDPWD $PATH $PWD $SHELL
$TERM $USER
- To print shell's environment variables: env or printenv
- To set command line editing using vi: set -o vi
- To execute the last command which was executed begining with p: !p
- To execute a command as background job use &: ls -al &
- To list all pending jobs: jobs
- To create softlink (shortcut, deleting shoftlink doesn't delete original file):
ln -s myfile softlink
- To create hardlink (deleting hardlink deletes original file):ln -s myfile
softlink
- To find where the link is pointing to: ls -l linkname
- To simply view files use one of these commands:
- cat - View files in their entirety
- more - View files one page at a time
- less - View files one page at a time. Ability to move backwards by
pressing b.
- head - View the first lines of a file
- tail - View the last lines of a file
- nl - View files with their lines numbered
- To continuously tail a log file: tail -f mylog.log
- To update timestamp of a file ot create a empty file: touch filename
- To change the default editor set the following environment variables
$EDITOR=emacs
$VISUAL=emacs
$export EDITOR VISUAL
- To count number of byte words and lines in a file: wc filename
- To count only number of lines in a file: wc -l filename
- To list important attributes of a file like size device access : stat filename
- To print size of files: du file1 file2
- To print all filenames begining with myfile: find / -type f -name myfile* -print
- To print all directories begining from current: find . -type d -print
- To print lines containg myword in a file myfile: grep myword myfile
- To print lines which doesn't contain myword in myfile: grep -v myword myfile
- To display only unique lines in sorted order from a file: sort myfile | uniq
- To count duplicate lines: sort myfile | uniq -c
- To display command out and also write into a file simultaneously use tee
command:
who | tee who_output | sort
- To print 2nd and 4th word in each line in myfile: awk '{print $2, $4}' myfile
- To print all lines shorter than 50 characters in myfile: awk '{length($0) < 50}'
myfile
- To print contents of myfile with all occurance or red converted to blue: sed
's/red/blue/g' myfile
- To print contents of myfile skipping lines 2 to 5: sed '2,3d' myfile
- To substitute all occurance of NAME with Kris and AGE with 31 in myfile:
m4 -DNAME=Kris
-DAGE=31 myfile
- To find size, used space, and free space on all disk partition: df -h
- To find size, used space, and free space current directory: df .
- To compare two directories recursively: diff -r dir1 dir2
- To compare two file ignoring case: diff -i file1 file2
- To compare tabular sorted file skipping 2nd column : comm -2 file1 file2
- To point out the first diffrence in similar files: cmp file1 file2
- To print 32 byte checksum, useful to check downloaded files: md5sum file1
- To print name of the terminal device associated with the current shell: tty
- To format output display string: printf "User %s is %d years old.\n" kris 31
- To enter "y" to a interactive shell program by default: yes |
my_interactive_command
- To print current year business calendar with day number: cal -y -m
- To print current year business calendar with sequential numbers instead of date:
cat -y -m -j
- To print epoch seconds: date - %s
- To print last modified timestamp of a file: date -r myfile
- To print Hello every 10 seconds: sleep 10 && echo 'Hello'
- To check which files are newly added to current directory ever 20 seconds: watch
-n 20 ls -l
- To view your own process: ps -ux
- To view process started by user1: ps -U user1
- To view all occurance of a program name prg: ps -C prg
- To view all process in screen width with full command line: ps -efww
- To view all process in screen width with threads: ps -efH
- To find how long the system is running since last boot: uptime
- To display current process of all logged users: w
- To monitor most active processes with full command line: top -c [press q to exit
from top]
- To graphical display of system load (similar to task manager in windows) : xload
- To display memory usage in megabyte: free -mt [free -t for kilobytes]
- To run system intensive process with controlled priority 7: nice -7 jobname
jobargs > outfile [10 is default]
- To change the priority of a process id 1834 previously executed with nice: nice
-5 -p 1834
- To change the priority of a process previously executed by user usr1 with nice:
nice -5 -u usr1
- To change the priority of already running command by process id from PS:
renice +15 23456
- To find details about user environment like login id, last login etc:
logname : current login name
whoami : same as logname except if su is used to switch user
finger : user information
last : last login details
printenv : environment details
- To find details about your computer: uname -a
- To print your host name: hostname
- To print details of computer's default network interfaces: ifconfig
- To display details of computer's all network interfaces: ifconfig -a
- To display details of a hostname from internet directory: whois hotmail.com
- To print network path from your machine to a host: traceroute yahoo.com
- To scp myfile from current machine to othermachine using id otherid:
scp myfile
otherid@remote.example.com:/home/otherhome/
- To scp otherfile from other machine with id other id to current machine:
scp
otherid@remote.example.com:/home/otherhome/otherfile .
Put the following in .profile or .bashrc file
PS1="`hostname`*\${ORACLE_SID}-\${PWD}
Vi editor tips:
- To delete all occurance of DEBUG. ESC :%s/* DEBUG //g
- To delete all occurance of "DEBUG ". ESC :%s/* DEBUG //g
- To delete everything between <> including <> in line numbers 1 to 8. ESC
:1,8s/<[^>]*>//g
- To substitute all occurences of foo on the current line with bar. ESC :.s/foo/bar/g
- To subsitute all matches of the word foo in the file with bar. Ignore case in
searches.
ESC :%s/foo/bar/g
- To subsitute all matches of the microsoft with the linux. ESC :%s;microsoft/;linux;g
- To edit files found by grep: vi `grep -l ifdef *.java`
- To edit previous command using vi: fc -e vi
|