You are on page 1of 5

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 m ight 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 gr ep "ora_" grep -v grep * To give a short name to big command: alias listoraprocess="ps -ef grep "or a_" grep -v grep" * To kill all oracle process: ps -ef grep "ora_" grep -v grep grep $ORACLE_S ID 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 . -pr int 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 "sch eduled 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 $SH ELL $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 f ile): 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: o cat - View files in their entirety o more - View files one page at a time o less - View files one page at a time. Ability to move backwards by p

* * * * * * * * *

\n" kris 31 * To enter "y" to a interactive shell program by default: yes my_interacti ve_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 . used space. and free space on all disk partition: df -h find size. o head . $4}' myf ile * 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: s ed 's/red/blue/g' myfile * To print contents of myfile skipping lines 2 to 5: sed '2. compare two directories recursively: diff -r dir1 dir2 compare two file ignoring case: diff -i file1 file2 compare tabular sorted file skipping 2nd column : comm -2 file1 file2 point out the first diffrence in similar files: cmp file1 file2 print 32 byte checksum.View files with their lines numbered * To continuously tail a log file: tail -f mylog.3d' myfile * To substitute all occurance of NAME with Kris and AGE with 31 in myfile: m4 -DNAME=Kris -DAGE=31 myfile * * * * * * * * y * To format output display string: printf "User %s is %d years old.%s To To To To To To To To find size. and free space current directory: df .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 file name * To * To -print * To * To * To le * To iq * To * To ommand: print size of files: du file1 file2 print all filenames begining with myfile: find / -type f -name myfile* print all directories begining from current: find . used space.View the first lines of a file o tail . -type d -print print lines containg myword in a file myfile: grep myword myfile print lines which doesn't contain myword in myfile: grep -v myword myfi display only unique lines in sorted order from a file: sort myfile un count duplicate lines: sort myfile uniq -c display command out and also write into a file simultaneously use tee c who tee who_output sort * To print 2nd and 4th word in each line in myfile: awk '{print $2.View the last lines of a file o nl .ressing b. useful to check downloaded files: md5sum file1 print name of the terminal device associated with the current shell: tt .

example. * To download a file from internet: wget http://www.yahoo.com:/home/otherhome/otherfile . 5 times: sar -u 5 5 * To run sar command non interactively to check later: nohup sar -o output.ar gs sort -k 1 -r head -5 To To To To To find details about your computer: uname -a print your host name: hostname print details of computer's default network interfaces: ifconfig display details of computer's all network interfaces: ifconfig -a display details of a hostname from internet directory: whois hotmail.profile or .bashrc file PS1="`hostname`*\${ORACLE_SID}-\${PWD} * To display memory segments: ipcs * To display all cpu status: mpstat -P ALL * To display cpu utilization every 5 seconds.com:/home/otherhome/ * To scp otherfile from other machine with id other id to current machine: scp otherid@remote. 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 * * * * * m * To print network path from your machine to a host: traceroute yahoo.example.pid.f ile 12 8 >/dev/null 2>&1 & * To display highest CPU utilizing process and user: ps -eo pcpu.user.htm * To display useful prompt for oracle box: Put the following in .com/index.com * To scp myfile from current machine to othermachine using id otherid: scp myfile otherid@remote.co .* 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 t o 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 jobnam e 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: r enice +15 23456 * To find details about user environment like login id.

how long the system is ru nning and the amount of load into the system: uptime * To reset terminal when backspace and delete keys produce junk: o stty erase Delete o stty intr Ctrl+c * To change the group file belongs to: chgrp admingroup imp.log & (command output goes to nohup.* To display i/o status every 5 seconds 5 times: iostat -xtc 5 5 * To display virtual memory status every 5 seconds: vmstat 5 * To find files larger than 10KB: find .tar .myhost. -size +10240 print * To echo quotes: echo 'Single quotes "protect" double quotes' or echo "Well .txt piece o more piece* * To split a file based on size in KB or MB: o split -b 10k long piece o split -b 10m long piece * To add user smith : useradd -d /home/smith -s /bin/bash -g users smith * To delete user smith: userdel smith * To change user home directory: usermod -d /u01/smith smith * To change smith password: passwd smith * To find user details: finger smith * To change name and other finger details of smith: chfn smith * To change shell for smith: chsh smith * To find all the available shells in the system: chsh -l * To switch to super user with directory change to /root: su -l or su * To switch to super user with current shell and current directory: su * To print group information of smith: groups smith * To add new group: groupadd -f newgroup * To delete group: groupdel group1 * To change group name: groupmod -n newgroupname oldgroupname * To set hostname: hostname me.out ) * To split a file based on lines: o split -l 100 long. isn't that \"special\"?" * To display command output in echo: echo "You have `ls wc -l` files in `p wd`" * To display variable value in echo: echo "The value of \$x is $x" * To sort page and print a file: sort file pr -3 lp * To redirect standard output to standard error: echo "Usage error: see admi nistrator" 1>&2 * To send command output to one file and error to another file: find / -prin t > fileOne 2>fileTwo * To remember a directory and use it later: o pushd /var/dirme ----execute other commands even change directory o popd * To create a patch file by using diff between files: diff fileOld fileNew > patchfile * To apply patch to a file: patch fileOld patchfile * To create a patch file between directories: diff -Naur prestinedir modifie ddir > patchfile * To apply patch to a directory: o cd prestinedir o patch -p1 < patchfile * To put the most recent command suspended using Ctrl+z in background: bg * To put a command in background using process number: bg %3 * To find background job number: jobs * To bring a background process to foreground: fg %4 * To prevent a process being killed when you exit the shell: o nohup lpr -Phod /var/access.com * To display current time. number of users logged.

ESC :%s.s/ foo/bar/g * To subsitute all matches of the word foo in the file with bar.linux. ESC :. ESC : 1. Ignore case in searches.* To log into new group you belong.java` * To edit previous command using vi: fc -e vi . ESC :%s/foo/bar/g * To subsitute all matches of the microsoft with the linux. This will set the group to new group wit hout running chgrp: o newgrp admingrp Vi editor tips: * To delete all occurance of DEBUG.8s/<[^>]*>//g * To substitute all occurences of foo on the current line with bar.microsof t/. ESC :%s/* DEBUG //g * To delete everything between <> including <> in line numbers 1 to 8. ESC :%s/* DEBUG //g * To delete all occurance of "DEBUG ".g * To edit files found by grep: vi `grep -l ifdef *.