Commonly used unix commands
Commonly used unix commands

redirection commands= 	
   > output stdout
	< input  stdin
   2> output stderr
In ksh: redirect stdout and stderr: cmd > file 2>&1

run a command in the background= use & at the end of the command.  Ex: rm -r -f &
flags can be coded as: -f -g -w or -fgw

; is used as a command separator when you want to issue more than one command on the same line.

setting an environment variable:
in ksh:
export VAR
or: VAR=value; export VAR

in csh:
setenv VAR value

Initialization files:
sh and ksh: /etc/profile and .profile
set -o 


envoking a shell:
#!/bin/csh              ## c shell
#!/bin/ksh              ## korn shell

	/bin=contains executable binary programs
	/dev=contains device drivers
	/etc=unix admin files + info
	/home=files unique for a specific user
	/lib=library of functions and procedural libraries
	/lost+found=files lost due to failure, etc.
	/net=shortcuts for accessing other computers on the network
	/nmt=mounted external devices
	/sys=system configuration files
	/tmp=temp file storage space
	/usr=user related commands

some files=
    /etc/rc.config.d/netconf = Network ip config file
    /etc/passwd = password file for the unix server
    /etc/.login = the initial machine wide defaults for csh.
    .cshrc = user defaults for csh 
    system messages on sun/solaris: /var/adm/messages
    /var/msg = system messages
    /etc/system = system parms
    /var/opt/oracle = oracle files like tnsnames.ora, listener.ora and oratab

	HOME=folder where a unix session starts for a user
	PATH=search path when running a program

file permissions=displayed as a 9 character string and is composed of:
	1=file type
		b=block-type special type
		c=character-type special file
		l=symbolic link
	2-4=permissions for owner of the file read,write,exec (rwx)
	5-7=permissions for group for the file read,write,exec (rwx)
	8-10=permissions for everyone else for the file read,write,exec (rwx)
	Typical permissions:
	--- no access allowed
	r--	read-only access
	r-x	read and execute access, for programs and shell scripts
	rw- read and write access, for files
	rwx All access allowed

	Typical for a directory:
	--- no access allowed
	r-x	read-only access, no modification allowed
	rwx all access allowed
shell scripts=unix command line macro facility, series of unix comands.  You must have
	read/execute permissions to be able to execute shell scripts.

at=at scheduler
    flags= -f filename
    examples: at -f filename 0630pm Sep 22
    			  at -f filename now
bc=Infix calculator

bdf=Lists all the logical volumes
    flags=	-l=

cal[month][year]=Outputs a calendar of a month and a year

cat[filename...]=Concatenate and display the contents of file(s).

catman=Formats the pages for the man command.

cc=C compiler (do man for all switches)

cd[path]=Change directory
	arguments=[]=change dir to the value of the HOME environment variable
			  [path]=change dir to specified path

chgrp[NewGroup][filenames|directories]=Changes the group of a file or directory.
	You must be a member of the new group for the command to work.

chmod[permissions][filename|dir]=Change the specific set of permissions for any files or directories.
	Symbolic notation=
		u=user		+=add		r=read
		g=group		-=remove	w=write
		o=others	==set		x=execute
		example= chmod g+wx donut   to add write and exec for the group for the file donut
	Numeric notation=
		---------   000            0=---  1=    4=r-- 6=rw- 7=rwx
		r--------	400
		r--r--r--	444
		rw-------	600
		example= chmod 600 donut   to set rw------- for the file donut

chown[NewOwner][filenames|directories]=Changes the ownership of file(s) or directories
	You can also change the group at the same time:  chown oracle:dba filename
compress[filename]=Shrinks the size of any files or set of files
	output=.Z is appended to the file name of the compressed file
	flags=	-v=verbose on, shows compression information

cp [flags] [fromfiles] [tofiles]=Copies files.
	flags=   -r= Recursive.  cp will copy the directory and  all  its files,  including any subdirectories 
                and their files to target.
            -p= Preserve ownership and permissions of source file.

-l list entries
-e edit
	minute (0-59),
   hour (0-23),
   day of the month (1-31),
   month of the year (1-12),
   day of the week (0-6 with 0=Sunday)
07 05 * * 0-6 csh /db01/app/oracle/csh/orastart_DBSTAR >>/db01/app/oracle/admin/DBSTAR/logbook/batch.log
00 19 * * 0 csh /db01/app/oracle/csh/orastart_DBSTAR >>/db01/app/oracle/admin/DBSTAR/logbook/batch.log

crypt=Encrypts a file based on a secret key
	requires < input    and    > output

date=Outputs current date and time.

dc=Postfix calculator.

df=Outputs the disk space available (disk free).

du=Outputs the disk space used (disk usage) in o/s blocks and all subdirectories
	with their space usage.
	flags=	-a=also lists the files
                -h=in gigabytes
		-s=will only display the total space usage
		-o=don't add up amounts of sub-directories
		-k=in kilobytes instead of o/s blocks
                --max-depth=N print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as

   examples: du -ks *
             du -h --max-depth=1
echo[string...]=Display a message to the screen.

env[variable]=Displays all or specific environment variables for a user.

exit=To exit a shell, when its the last shell you are logged off from the server.

file[filename...]=Identifies the type of a file.

find [startingPath]=Performs an ordered search through the file system. 
    flags=  -name [name of file]=name of the file to find.  If using * put string in double 
               quotes: "*ora".  
			   -exec [command]
    example: 	find / -name install.log -exec rm{}\;
                find . -print -name grants_select.sql | grep grants_select.sql
		find . -print -name grants_select.sql 2>/dev/null | grep grants_select.sql
		find / -print -name oraenv 2>/dev/null | grep oraenv

        find files older than 15 days
                find /u01/app/oracle/oradata -type f -mtime +15
        remove files older than x days, in this example 30 days in current directory: 
                find . -mtime +30 -exec rm {} \;

fuser [filename]=Lists processes that are using a file.

grep [string]=Pipe that will display a line of a file if the specified string is found on that
    example: ls -l | grep oracle    ps -ef | grep oracle

    Or, find a string in files, example find all files that contain the string ctime
    grep ctime *
    This will in addition search for subdirectories:
    find . -name "*" | xargs grep "\-ctime"
head[filename] -NumberOfLinesToDisplay=Displays the first x lines of a file.  Can be used as a 
    example: who | head -5.

hostname=Outputs the computer name the user is logged on to.  Also see /etc/hosts.

id=Outputs information about the user currently logged on including the security group the user belongs to.

ioscan=Displays the I/O devices.
    flags=  -f=
ipcs=info on memory and semaphores.
    flags=  -a=

ipcrm=remove memory and semaphore segments.
-m 118403  memory segment
-s 111     semaphore segment
jobs=Displays what tasks are running.

kill [pid]=kills a process id.
    flags=  -9=process immediately.
last=Displays information about the last user to logon.

ln file newfile = links a file to a new filename.
   ln -s /db01/app/oracle/admin/DBSTAR/pfile/initDBSTAR.ora initDBSTAR.ora 

ll=in HP-UX equals ls -l

lp=Queues files to be printed.

lpr=Sends a print request to a printer.

lpstat=Displays print queue.
	flags=	-t=adds printer information

ls=Lists names of files and sub-directories.
	flags=	-1=forces single-column output on listings
			-a=list all files, including any . (dot) files
			-C=forces multiple-column output on listings
			-CF=of your own top-level directory
			-d=forces ls to list directories rather than their contents
			-F=indicates file types by adding suffix
				output=	*=program
						@=symbolic link
						.=hidden files (dot must be on first character)
						with a suffix of rc it usually means the config file
						of a program
			-l=displays files and directories in a long listing format 
			-lg=adds a group column to the long listing format, some unix flavors already
				display this column when using the -l flag
			-m=lists all files separated by a comma
			-r=to reverse any sorting order
			-R=lists sub-directories recursively and their contents
			-s=shows size of files, in blocks (typically 1 block=1024 bytes) also
			   shows space used for the whole directory but not doesn't include sub-directories
			-t=sort by most-recently accessed to least-recently-accessed
			-x=sorts horizontally on a row basis instead of vertically by columns

mail=Electronic mail utility.

mailx=Sends electronic mail.

man[keyword]=help screen for a unix keyword      

mkdir=Creates a new directory.

more=Pipe to display a file, one page at a time.

mount [device] [MointPoint]=Mount a device to a mount point. 
            -F cdfs=
            example for mounting a CDROM: mount -r /dev/dsk/c1t2d0 /cdrom

mv [fromfiles] [tofiles]=Moves or renames files.

passwd=Changes passwords.

printenv=Same as env.

pwd=Displays the present working directory.

ps=Displays what processes are running.
            -e=displays all processes
            -f=displays long listing format       
            -u [user]=displays the processes associated with a specific user

rm[file|dir]=Removes a file or files.
     flags= -r=recursively remove subdirectories

rmdir=Removes a directory.

shutdown=Shuts down the unix server.
	flags= -r=reboot the server after shutdown
		   -h=halt the system
		    t=grace period
		   -y=prompt for answers  

sar -c [interval] [nbr of times]
	-c is the format and columns that will be displayed
	-d is for disk access
scp ex: scp oracle@targetserver:/tmp

su - oracle=switch user
    ^b to exit shell         

sudo ex: sudo -i -u oracle

tar=Tape file archiver.

time=Outputs CPU time since command interpreter was brought up, you'll never use this command.

top=Displays top cpu users

touch=Creates an empty file if the file doesn't exist.  If the file exists the last
	modified date is updated.

umount [mountpoint]=unmount a mountpoint from a device.  ex: umount /cdrom.

umask[mask value]=Controls the file permissions that new files are given upon creation.

uname=gives you information on the configuration of the unix box.
   -a= version of unix

uncompress[filename]=Uncompresses a previously compressed file.
	example: uncompress exp_full.dmp
				uncompress *    (uncompresses all files of a directory)

users=Outputs the userid's of users currently logged on.

who=Outputs different information about the users currently logged on.

whoami=Outputs the userid of user currently logged on.

who am i=Outputs information about the user currently logged on.

write=Sends a message to another user.

in ksh: set -o vi
remote command
rcp file  
remsh remote "uname"
rlogin remote -l oracle8

Unzipping and untarring (an Oracle patchset for instance):
cd to the directory and then:
gunzip <| tar xvf -