Вы находитесь на странице: 1из 28

Man ual command.

man man This is help command, and will explains you about online manual pages you can also use man in conjunction with any command to learn more about that command for example. man ls will explain about the ls command and how you can use it. man -k pattern command will search for the pattern in given command.

Banner command.
banner prints characters in a sort of ascii art poster, for example to print wait in big letters. I will type banner wait at unix command line or in my script. This is how it will look.
# # # # # # # ## # ## ## # # ## # # ###### # # # # # # # # # # # # ##### # # # # #

Cal command
cal command will print the calander on current month by default. If you want to print calander of august of 1 !". That#s eightht month of 1 !". cal $ 1 !" will print following results.
August 1965 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Clear command
clear command clears the screen and puts cursor at beginning of first line.

Calendar command
calendar command reads your calendar file and displays only lines with current day. %or example in your calendar file if you have this
12/20 1/15 1/20 Test new software Test new!" #e$e!o%e# 3270 %ro#u&t 'nsta!! (e(or" on )* 9000 (a&h+ne

&n dec '(th the first line will be displayed. you can use this command with your crontab file or in your login files.

Nohup command.
nohup command if added in front of any command will continue running the command or process even if you shut down your terminal or close your session to machine. %or exmaple, if I

want to run a job that takes lot of time and must be run from terminal and is called update)entries)tonight . nohup update)entries)tonight will run the job even if terminal is shut down in middle of this job.

Tty command
Tty command will display your terminal. *yntax is tty options

&ptions -l will print the synchronous line number. -s will return only the codes+ ( ,a terminal-, 1 ,not a terminal-, ' ,invalid options- ,good for scripts-

File Management commands.


cat,cd, cp, file,head,tail, ln,ls,mkdir ,more,mv, pwd, rcp,rm, rmdir, wc.

Pwd command.
pwd command will print your home directory on screen, pwd means print working directory.
/u0/ss,/san#ee%

is output for the command when I use pwd in .u(.ssb.sandeep directory.

Ls command
ls command is most widely used command and it displays the contents of directory.

options

ls will list all the files in your home directory, this command has many options. ls -l will list all the file names, permissions, group, etc in long format. ls -a will list all the files including hidden files that start with . . ls -lt will list all files names based on the time of creation, newer files bring first. ls -%xwill list files and directory names will be followed by slash. ls -/will lists all the files and files in the all the directories, recursively. ls -/ 0 more will list all the files and files in all the directories, one page at a time.

Mkdir command.
mkdir sandeep will create new directory, i.e. here sandeep directory is created.

Cd command.
cd sandeep will change directory from current directory to sandeep directory. 1se pwd to check your current directory and ls to see if sandeep directory is there or not. 2ou can then use cd sandeep to change the directory to this new directory.

Head command.
head filename by default will display the first 1( lines of a file.

If you want first "( lines you can use head -"( filename or for 34 lines head -34 filename and so forth.

Tail command.
tail filename by default will display the last 1( lines of a file. If you want last "( lines then you can use tail -"( filename.

More command. more command will display a page at a time and then wait for input which is
spacebar. %or example if you have a file which is "(( lines and you want to read it all. *o you can use more filename

Wc command
wc command counts the characters, words or lines in a file depending upon the option.

Options

wc -l filename will print total number of lines in a file. wc -w filename will print total number of words in a file. wc -c filename will print total number of characters in a file.

File command.
%ile command displays about the contents of a given file, whether it is a text ,5scii- or binary file. To use it type file filename. %or example I have cal.txt which has ascii characters about calander of current month and I have resume1.doc file which is a binariy file in microsoft word. I will get file resume.doc
resu(e1 #o&#ata as&++ te.t

file cal.txt
&a! t.t-

Cp command.
cp command copies a file. If I want to copy a file named oldfile in a current directory to a file named newfile in a current directory. cp oldfile newfile If I want to copy oldfile to other directory for example .tmp then cp oldfile .tmp.newfile. 1seful options available with cp are p and r . -p options preserves the modification time and permissions, -r recursively copy a directory and its files, duplicating the tree structure.

!cp command.
rcp command will copy files between two unix systems and works just like cp command ,-p and -i options too-. %or example you are on a unix system that is called Cheetah and want to copy a file which is in current directory to a system that is called lion in /usr/john/ directory then you can use rcp command rcp filename lion+.usr.john 2ou will also need permissions between the two machines. %or more infor type man rcp at command line.

M" command.
mv command is used to move a file from one directory to another directory or to rename a file.

Some examples:

mv oldfile newfile will rename oldfile to newfile. mv -i oldfile newfile for confirmation prompt. mv -f oldfile newfile will force the rename even if target file exists. mv 6 .usr.bajwa. will move all the files in current directory to .usr.bajwa directory.

Ln command.
Instead of copying you can also make links to existing files using ln command. If you want to create a link to a file called coolfile in .usr.local.bin directory then you can enter this command. ln mycoolfile .usr.local.bin.coolfile

Some examples:

ln -s fileone filetwo will create a symbolic link and can exist across machines. ln -n option will not overwrite existing files. ln -f will force the link to occur.

!m command.
To delete files use rm command.

Options:

rm oldfile will delete file named oldfile. rm -f option will remove write-protected files without prompting. rm -r option will delete the entire directory as well as all the subdirectories, very dangerous command.

!mdir command.
rmdir command will remove directory or directories if a directory is empty.

Options:

rm -r directory)name will remove all files even if directory is not empty.

rmdir sandeep is how you use it to remove sandeep directory. rmdir -p will remove directories and any parent directories that are empty. rmdir -s will suppress standard error messages caused by -p.

Comparison and #earching


diff,dircmp, cmp, grep, find.

$i%% command.
diff command will compare the two files and print out the differences between. 7ere I have two ascii text files. fileone and file two. Contents o% %ileone are
Th+s th+s th+s th+s th+s +s +s +s +s +s f+rst f+!e se&on# !+ne th+r# !+ne #+fferent as/!0#1f not #+fferent

%iletwo contains
Th+s th+s th+s th+s th+s +s +s +s +s +s f+rst f+!e se&on# !+ne th+r# !+ne #+fferent .......as/!0#1f not #+fferent

diff fileone filetwo will give following output


4&4 2 th+s +s #+fferent 333 4 th+s +s #+fferent as/!0#1f .......as/!0#1f

Cmp command.
cmp command compares the two files. %or exmaple I have two different files fileone and filetwo. cmp fileone filetwo will give me
f+!eone f+!etwo #+ffer- &har 805 !+ne 4

if I run cmp command on similar files nothing is returned. -s command can be used to return exit codes. i.e. return ( if files are identical, 1 if files are different, ' if files are inaccessible. This following command prints a message #no changes# if files are same cmp -s fileone file1 88 echo #no changes# .
no &hanges

$ircmp 9ommand.
dircmp command compares two directories. If i have two directories in my home directory named

dirone and dirtwo and each has "-1( files in it. Then dircmp dirone dirtwo will return this
6e& 9 16-06 1997 #+rone on!" an# #+rtwo on!" *age 1 /fourth t.t /r(t t.t /te t.t /th+r# t.t

/&a! t.t /#oha7aar t.t /four t.t /1un0 t.t /test t.t

&rep 9ommand
grep command is the most useful search command. 2ou can use it to find processes running on system, to find a pattern in a file, etc. It can be used to search one or more files to match an expression. It can also be used in conjunction with other commands as in this following example, output of ps command is passed to grep command, here it means search all processes in system and find the pattern sleep. ps -ef 0 grep sleep will display all the sleep processes running in the system as follows.
o%s #.+ o%s o%s o%s #.+ o%s #.+ o%s o%s ss, %10 12964 12974 12941 12847 12894 13067 13046 12956 12965 12989 13069 27049 25853 15640 25688 25812 25834 27253 25761 13078 25737 25778 26758 3353 0 0 0 0 0 2 0 0 0 0 2 0 16-12-24 16-12-25 16-12-21 16-11-59 16-12-12 16-12-48 16-12-44 16-12-23 16-12-24 16-12-28 16-12-49 15-20-23 tt"A8/AA8S tt"A)/AA)* tt"A8/AA8t tt"A)/AA)6 tt"A8/AA89 tt"A8/A:8; tt"A8/AA80 tt"A</AA<= tt"A8/AA8% tt"A)/AA)$ tt"A)/AA)s > 0-00 0-00 0-00 0-00 0-00 0-00 0-00 0-00 0-00 0-00 0-00 0-00 s!ee% 60 s!ee% 60 s!ee% 60 s!ee% 60 s!ee% 60 s!ee% 1 s!ee% 60 s!ee% 60 s!ee% 60 s!ee% 60 gre% s!ee% s!ee% 3600

Options:

-b option will precede each line with its block number. -c option will only print the count of matched lines. -i ignores uppercase and lowercase distinctions. -l lists filenames but not matched lines.

other associated commands with grep are egrep and %grep. egrep typically runs faster. for more information type man egrep or man fgrep in your system.

Find command.
%ind command is a extremely useful command. you can search for any file anywhere using this command provided that file and directory you are searching has read write attributes set to you ,your, group or all. %ind descends directory tree beginning at each pathname and finds the files that meet the specified conditions. 7ere are some examples.
Some Examples:

find :7&;< -print will lists all files in your home directory.

find .work -name chapter1 -print will list all files named chapter1 in .work directory. find . -type d -name #man6# -print will list all manpage directories. find . -si=e ( -ok rm >? @A will remove all empty files on system.

conditions of find

atime 'n ( n( n will find files that were last accessed more than n or less than -n days or n days. ctime 'n or n will find that were changed Bn -n or n days ago. depth descend the directory structure, working on actual files first and then directories. 2ou can use it with cpio command. e)ec commad *+ ,- run the 1nix command on each file matched by find. Cery useful condition. print print or list to standard output ,screen-. name pattern find the pattern. perm nnnfind files whole permission flags match octal number nnn. si.e n find files that contain n blocks. type c %ind file whole type is c. 9 could be / or block, c 9haracter special file, d directory, p fifo or named pipe, l symbolic link, or % plain file.

Te)t processing
cut,paste, sort, uniD,awk,sed,vi.

Cut command.
cut command selects a list of columns or fields from one or more files. &ption -c is for columns and -f for fields. It is entered as cut options EfilesF for example if a file named testfile contains
th+s +s f+rst!+ne th+s +s se&on#!+ne th+s +s th+r#!+ne

<xamples+ cut -c1,G testfile will print this to standard output ,screents ts ts

It is printing columns 1 and G of this file which contains t and s ,part of this-.

Options:

-c list cut the column positions identified in list. -f list will cut the fields identified in list. -s could be used with -f to suppress lines without delimiters.

Paste 9ommand.
paste command merge the lines of one or more files into vertical columns separated by a tab. for example if a file named testfile contains
th+s +s f+rst!+ne

and a file named testfile' contains


th+s +s testf+!e2

then running this command paste testfile testfile' H outputfile will put this into outputfile
th+s +s f+rst!+ne th+s +s testf+!e2

it contains contents of both files in columns. who ( paste - - will list users in two columns.

Options:

-d#char# separate columns with char instead of a tab. -s merge subseDuent lines from one file.

#ort command.
sort command sort the lines of a file or files, in alphabetical order. for example if you have a file named testfile with these contents
777 aaa 1234 "uer wer ?ww wwe

Then running sort testfile will give us output of


1234 aaa ?ww wer wwe "uer 777

Options:
-b ignores leading spaces and tabs. -c checks whether files are already sorted. -d ignores punctuation. -i ignores non-printing characters. -n sorts in arithmetic order. -ofile put output in a file. BmE-mF skips n fields before sorting, and sort upto field position m. -r reverse the order of sort. -u identical lines in input file apear only one time in output.

0ni1 command.
uniD command removes duplicate adjacent lines from sorted file while sending one copy of each second file.

Examples
sort names ( uni1 d will show which lines appear more than once in names file.

Options:

-c print each line once, counting instances of each. -d print duplicate lines once, but no uniDue lines. -u print only uniDue lines.

2wk and Iawk command.


awk is more like a scripting language builtin on all unix systems. 5lthough mostly used for text processing, etc. 7ere are some examples which are connected with other commands.

3)amples4
d% t ( awk 5B3&6N *tot78+ 9: 77 ;total; *tot7tot'9<+ 3N$ *print =tot>?<:@A<888888+5 Jill give total space in your system in megabytes. 7ere the output of command df -t is being passed into awk which is counting the field 1 after pattern KtotalK appears. *ame way if you change :1 to :G it will accumulate and display the addition of field G which is used space. for more information about awk and nawk command in your system enter man awk or man nawk.

#ed command.
sed command launches a stream line editor which you can use at command line. you can enter your sed commands in a file and then using -f option edit your text file. It works as sed EoptionsF files
options:

-e #instruction# 5pply the editing instruction to the files. -f script 5pply the set of instructions from the editing script. -n suppress default output.

for more information about sed, enter man sed at command line in your system.

Bi editor.
vi command launches a vi sual editor. To edit a file type vi filename vi editor is a default editor of all 1nix systems. It has several modes. In order to write characters

you will need to hit i to be in insert mode and then start typing. ;ake sure that your terminal has correct settings, vt1(( emulation works good if you are logged in using pc. &nce you are done typing then to be in command mode where you can write.search. you need to hit +w filename to write and in case you are done writing and want to exit +wL will write and exit.

options:

i for insert mode. o I inserts text at the curson o 5 appends text at the end of the line. o a appends text after cursor. o & open a new line of text above the curson. o o open a new line of text below the curson. + for command mode. o MescapeH to invoke command mode from insert mode. o +Lsh to run unix commands. o x to delete a single character. o dd to delete an entire line o ndd to delete n number of lines. o d: to delete from cursor to end of line. o yy to copy a line to buffer. o N to paste text from buffer. o nyy copy n number of lines to buffer. o 4CsAstring2Astring/ Ag to replace string5 with stringO in whole file. o P to go to last line in file. o 1P to go to the first line in file. o w to move forward to next word. o b to move backwards to next word. o : to move to the end of line. o Q join a line with the one below it. .string to search string in file. n to search for next occurence of string.

#hell and programming


*hell programming,bourne shell, ksh, csh, echo,line,sleep, test,cc compiler.

#hell programming concepts and commands.


*hell programming is integral part of 1nix operating systems. *hell is command line userinterface to 1nix operating system, 1ser have an option of picking an interface on 1nix such as ksh, csh, or default sh., these are called shells,interface-. *hell programming is used to automate many tasks. *hell programming is not a programming language in the truest sense of word since it is not compiled but rather an interpreted language. 1nix was written in 9 language and thus c language is integral part of unix and available on all versions. *hells, like ksh and csh are popular shells on unix although there are " or ! different shells available but I will only be

discussing ksh and csh as well as sh. 9ommon features among all shells are job control, for example if I am running a processes which is searching the whole system for .R files and output is directed to a file named compressedfiles.
example:

find . -name 6.R -print H compressedfiles then after entering this command hitting Mcontrol =H key will suspend this job, then entering bg at command line will put this job in background, entering fg will put this job in foreground. <ntering jobs at command line will show me all my concurrent jobs that are running. &ther common features
o o o o o o o o o o o o o o o o o o o o o

H will redirect output from standard out ,screen- to file or printer or whatever you like. HH filename will append at the end of a file called filename. M will redirect input to a process or commnand. 0 pipe output, or redirect output, good for joining commands, i.e. find command with cpio, etc. 8 at the end of command will run command in background. A will separate commands on same line. 6 will match any characters in a file or directories. junk6 will match all files with first G letters S will match single characters in a file. EF will match any characters enclosed. ,- execute in subshell. T T to run a command inside another command and use its output. K K partial Duote for variables. # # full Duote for variables. U begin comment ,if U.bin.ksh or csh or sh is entered at first line of script it runs script in that shellbg background execution. break break from loop statements. continue /esume a program loop. Vill pid number will terminate running jobs stop will stop background job. suspend will suspend foreground job. wait will wait for a background job to finish.

Bourne #hell ,sh shell-.


sh or Oourne shell is default shell of 1nix operating systems and is the most simplest shell in 1nix systems.

<xamples+ cdA ls execute one after another. =date-who-pwd@D logi%ile will redirect all the output from three commands to a filenamed logfile. sort %ile ( lp will first sort a file and then print it. alias EoptionsF EnameE75command5FF will let you create your own commands. i.e. o alias ll7;ls la; will execute Tls -laT command whenever ll is entered. let expressions is syntax of let statement. o let iWiB1 will work as a counter with i incrementing each time this statement is encountered. for xEin listF do &o((an#s done is syntax for for do loop. function na(e >commandsA? is the syntax of a function which can be called from anywhere in program. i% condition1 then commands1 eli% condition' then commands' ... ... ... else commands3 %i

Gsh shell ,Vorn-.


Vsh or Vorn shell is widely used shell.

Csh or 9 shell
csh is second most used shell.

3cho command
echo command in shell programming.

Line command.
line command in shell programming.

#leep command.
sleep command in shell programming.

Test 9ommand.
test command in shell programming.

CC compiler ,c programming language compiler-.


*ince 1nix is itself written in 9 programming language, most 1nix operating systems come with c compiler called cc. back to top of *hell programming. back to top of page

Communications
cu,ftp,login, rlogin,talk,telnet, vacation and write .

Cu command.
cu command is used for communications over a modem or direct line with another 1nix system. *yntax is cu options destination

&ptions -bn process lines using n-bit characters ,4 or $-. -cname *earch 119N#s device file and select local area network that matches name. -d Nrints diagnostics. -e sends even parity data to remote system -lline communicate on this device ,lineW.dev.tty((1, etc-n prompts for a telephone number. -sn set transmission rate to n,e.g 1'((,'G((, !((, ON*Xestination telno is the telephone number of the modem to connect to. system is call the system known to uucp. aadr is an address specific to Y5I.

Ftp command ,protocol-.


ftp command is used to execute ftp protocol using which files are transferred over two systems. *yntax is ftp options hostname

options -d enable debugging. -g disable filename globbing. -i turn off interactive prompts. -v verbose on. show all responses from remote server.

ftp hostname by default will connect you to the system, you must have a login id to be able to transfer the files. Two types of files can be transferred, 5*9II or Oinary. bin at ftpH prompt will

set the transfer to binary. Nractice %TN by ftping to nic.funet.fi loggin in as anomymous with password being your e-mail address.

Login command.
login command invokes a login session to a 1nix system, which then authenticates the login to a system. *ystem prompts you to enter userid and password.

!login command.
rlogin command is used to log on to remote 1nix systems, user must have permissions on both systems as well as same userid, or an id defined in .rhosts file. *yntax is rlogin options host

options -$ will allow $ bit data to pass, instead of 4-bit data. -e c will let you use escape character c. -l user will let you to login as user to remote host, instead of same as local host.

Talk command.
talk command is used to invoke talk program available on all unix system which lets two users exchange information back and forth in real time. *yntax is talk useridZhostname

Telnet command.
Telnet command invokes a telnet protocol which lets you log on to different unix, vms or any machine connected over T9N.IN protocol, INx protocol or otherwise. *yntax is telnet hostname

Bacation command.
vacation command is used when you are out of office. It returns a mail message to sender announcing that you are on vacation. to disable this feature, type mail F ; ; . syntax is vacation options

&ptions -d will append the date to the logfile. -% user will forward mail to user when unable to send mail to mailfile. -l logfile will record in the logfile the names of senders who received automatic reply. -m mailfile will save received messages in mailfile.

Write command will initiate an interactive conversation with user. *yntax is


write user tty back to top of communications commands back to top of page

#torage commands
compress uncompress, cpio,dump,pack, tar, mt.

Compress command.
9ompress command compresses a file and returns the original file with .= extension, to uncompress this filename.R file use uncompress filename command. syntax for compress command is compress options files

Hptions -bn limit the number of bits in coding to n. -c write to standard output ,do not change files-. -f compress conditionally, do not prompt before overwriting files. -v Nrint the resulting percentage of reduction for files.

0ncompress command.
1ncompress file uncompresses a file and return it to its original form. syntax is uncompress filename.Z this uncompresses the compressed file to its original name.

&ptions -c write to standard output without changing files

Cpio command.
cpio command is useful to backup the file systems. It copy file archives in from or out to tape or disk, or to another location on the local machine. Its syntax is cpio %lags EoptionsF

It has three flags, iI oI p cpio -i EoptionsF EpatternsF o cpio -i copy in files who names match selected patterns. o If no pattern is used all files are copied in. o It is used to write to a tape. cpio -o

9opy out a list of files whose name are given on standard output. cpio -p

copy files to another directory on the same system. &ptions

o o o o o o o o o o o o o o

-a reset access times of input files. -5 append files to an archive ,must use with -o-. -b swap bytes and half-words. Jords are G bytes. -O block input or output using "1'( bytes per record. -c /ead or write header information as 5scii character. -d create directories as needed. -l link files instead of copying. -o file direct output to a file. -r rename files interactively. -/ ID reassign file ownership and group information to the user#s login IX. -C print a dot for each file read or written. -s swap bytes. -* swap half bytes. -v print a list of filenames. 3)amples

o o o

find . -name K6.oldK -print 0 cpio -ocvO H .dev.rst$ will backup all 6.old files to a tape in .dev.rst$ cpio -icdv KsaveKK M .dev.rst$ will restore all files whose name contain KsaveK find . -depth -print 0 cpio -padm .mydir will move a directory tree.

$ump command is useful to backup the file systems.


dump command copies all the files in filesystem that have been changed after a certain date. It is good for incremental backups. This information about date is derived from .var.adm.dumpdates and .etc.fstab . syntax for 7N-1[ dump is .usr.sbin.dump Eoption Eargument ...F filesystemF

Hptions (- This number is dump level. ( option causes entire filesystem to be dumped. b blocking factor taken into argument. d density of tape default value is 1!((. f place the dump on next argument file instead of tape. This example causes the entire file system ,.mnt- to be dumped on .dev.rmt.c(t(d(O<*T and specifies that the density of the tape is !'"( ONI. o .usr.sbin.dump (df !'"( .dev.rmt.c(t(d(O<*T .mnt for more info type man dump at command line.

Pack command.
pack command compacts each file and combine them together into a filename.= file. The original file is replaced. Ncat and unpack will restore packed files to their original form. *yntax is Nack options files

&ptions Nrint number of times each byte is used, relative freDuency and byte code. -f %orce the pack even when disk space isn#t saved. To display Nacked files in a file use pcat command pcat filename.. To unpack a packed file use unpack command as unpack filename.. .

Tar command.
tar command creates an archive of files into a single file. Tar copies and restore files to a tape or any storage media. *ynopsis of tar is tar [options] [file]

Examples:
tar cvf .dev.rmt.( .bin .usr.bin creates an archive of .bin and .usr.bin, and store on the tape in .dev.rmt(. tar tvf .dev.rmt( will list the tape#s content in a .dev.rmt( drive. tar cvf - #find . -print# H backup.tar will creates an archive of current directory and store it in file /ackup.tar.

Functions:

c creates a new tape. r append files to a tape. t print the names of files if they are stored on the tape. x extract files from tape.

Options:

b n use blocking factor of n. l print error messages about links not found. Y follow symbolic links. v print function letter ,x for extraction or a for archive- and name of files.

Mt command
;t command is used for tape and other device functions like rewinding, ejecting, etc. It give commands to tape device rather than tape itself. ;t command is O*X command and is seldom found in system C unix versions.

syntax is mt E-t tapenameF command EcountF


mt for 7N-1[ accept following commands eof write count <&% marks. fsf %orward space count files. fsr %orward space count records. bsf Oackward space count files. bsr Oackward space count records. rew /ewind tape. offl /ewind tape and go offline. eod *eek to end of data ,XX* and \I9 drives only-. smk Jrite count setmarks ,XX* drives only-. fss %orward space count setmarks ,XX* drives only-. bss Oackward space count setmarks ,XX* drives only-. <xamples o mt -t .dev.rmt.(mnb rew will rewind the tape in this device. o mt -t .dev.rmt.(mnb offl will eject the tape in this device.

back to top of storage commands back to top of page

#ystem #tatus
at, chmod,chgrp, chown,crontab,date, df,du, env, finger, ps,ruptime, shutdwon,stty, who.

2t command.
at command along with crontab command is used to schedule jobs. at options time [ddate] [+increment] is syntax of at command. for example if I have a script named usersloggedin which contains.
#@/,+n/0sh who A w& 3! e&ho Bare tota! nu(,er of %eo%!e !ogge# +n at th+s t+(e B

and I want to run this script at $+(( 5;. *o I will first type at $+(( ]ltAenterH usersloggedin ]ltAenterH I will get following output at $+(( 5;
30 are tota! nu(,er of %eo%!e !ogge# +n at th+s t+(e

&ptions+ -f file will execute commands in a file. -m will send mail to user after job is completed. -l will report all jobs that are scheduled and their jobnumbers. -r jobnumber will remove specified jobs that were previously scheduled.

Chmod command.
chmod command is used to change permissions on a file. for example if I have a text file with calender in it called cal.txt. initially when this file will be created the permissions for this file depends upon umask set in your profile files. 5s you can see this file has !!! or -rw-rw-rw attributes. ls -la cal.txt
3rw3rw3rw3 1 ss, #.+#e$ 135 6e& 3 16-14 &a! t.t

In this line above I have -rw-rw-rw- meaning respectively that owner can read and write %ileI mem/er o% the owner5s group can read and write this %ile and anyone else connected to this system can read and write this %ile.I ne)t ss/ is owner o% this %ile d)ide" is the group o% this %ileI there are <J? /ytes in this %ileI this %ile was created on $ecem/er J at time<K4<L and at the end there is name o% this %ile. Yearn to read these permissions in binary, like this for example Xecimal !GG which is 11( 1(( 1(( in binary meand rw-r--r-- or user can read,write this file, group can read only, everyone else can read only. *imilarly, if permissions are 4"" or 111 1(1 1(1 that means rwxr-xr-x or user can read, write and execute, group can read and execute, everyone else can read and execute. 5ll directories have d in front of permissions. *o if you don#t want anyone to see your files or to do anything with it use chmod command and make permissions so that only you can read and write to that file, i.e. chmod !(( filename.

Chgrp command.
chgrp command is used to change the group of a file or directory. 2ou must own the file or be a superuser. chgrp EoptionsF newgroup files is syntax of chgrp. Iewgroup is either a group Id or a group name located in AetcAgroup .

&ptions+ -h will change the group on symbolic links. -/ recursively descend through directory changing group of all files and subdirectories.

Chown command.
chown command to change ownership of a file or directory to one or more users. *yntax is chown options newowner files

&ptions -h will change the owner on symbolic links. -/ will recursively descend through the directory, including subdirectories and symbolic links.

Cronta/ command.
crontab command is used to schedule jobs. 2ou must have permission to run this command by unix 5dministrator. Qobs are scheduled in five numbers, as follows.
Minutes 0-59 Hour Day of month month Day of week 0-23 1-31 1-12 0-6 (0 is sunday)

so for example you want to schedule a job which runs from script named backup)jobs in .usr.local.bin directory on sunday ,day (- at 11.'" ,''+'"- on 1"th of month. The entry in crontab file will be. 6 represents all values.
25 22 15 C 0 /usr/!o&a!/,+n/,a&0u%D1o,s

The 6 here tells system to run this each month. *yntax is crontab file *o a create a file with the scheduled jobs as above and then type crontab filename .This will scheduled the jobs.

$ate command.
Xate displays todays date, to use it type date at prompt.
Sun 6e& 7 14-23-08 8ST 1997

is similar to what you should see on screen.

$% command.
df command displays information about mounted filesystems. It reports the number of free disk blocks. Typically a Xisk block is "1' bytes ,or 1.' Vilobyte-. syntax is df options name

&ptions -b will print only the number of free blocks. -e will print only the number of free files. -f will report free blocks but not free inodes. -% type will report on an umounted file system specified by type. -k will print allocation in kilobytes. -l will report only on local file systems. -n will print only the file system name type, with no arguments it lists type of all filesystems

$u command.
du command displays disk usage.

3n" command.
env command displays all the variables.

Finger command.
finger command.

P# command
ps command is probably the most useful command for systems administrators. It reports information on active processes. ps options

options. -a Yists all processes in system except processes not attached to terminals. -e Yists all processes in system. -f Yists a full listing. -j print process group IX and session IX.

!uptime command.
ruptime command tells the status of local networked machines. ruptime options

options. -a include user even if they#ve been idle for more than one hour. -l sort by load average. -r reverse the sort order. -t sort by uptime. -i sort by number of users.

#hutdown command.
*hutdown command can only be executed by root. To gracefully bring down a system, shutdown command is used.

options. -gn use a grace-period of n seconds ,default is !(-. -ik tell the init command to place system in a state k. o s single-user state ,defaulto ( shutdown for power-off. o 1 like s, but mount multi-user file systems. o " stop system, go to firmware mode. o ! stop system then reboot. -y suppress the default prompt for confirmation.

#tty command
stty command sets terminal input output options for the current terminal. without options stty reports terminal settings. stty options modes M device

options -a report all options. -g report current settings. ;odes ( hang up phone. n set terminal baud. erase keyname, will change your keyname to be backspace key.

Who command
who command displays information about the current status of system. who options file Jho as default prints login names of users currently logged in.

&ptions -a use all options. -b /eport information about last reboot. -d report expired processes. -7 print headings. -p report previously spawned processes. -u report terminal usage.

2d"ance uni) command concepts


Nut advance commands utilities, redirection, etc here. cal H cal.txt To create a new file called cal.txt that has calendar for current month. H sign redirects output from stdout ,screen- to a file.

C#C3 MN< 0ni) $ata Manipulation

Xata ;anipulation 9ommands under 1nix o Yine oriented nature of commands o %ilters o <ditors vi W ex -v ex scripts cut, paste+ programs for manipulating columns in files *ed - stream oriented editor o Ciewers.*earchers grep family od ,octal dump find - a program for searching a directory,and moreo Testers.;anipulators diff, cmp - programs for comparing two files sort o *cripting Yanguages 5wk - 5ho, Jeinberger, and Vernighan *hells - primarily .bin.sh, bash perl Tcl.Tk

ex commands review+ d, s ex scripts o 9onsider $4 data sets gathered for image processing research with headers such as+
o o o o o o o o o o o o o o o o o o o @ Th+s #ata set was gathere# 6/19/96 at 10-30 @ 't was o,ta+ne# us+ng the Suther!an# f+!ter w+th stan#ar# seg(entat+on

7ow do we remove the $4 headers that vary in length from ' to " linesS Jith ex.vi we could delete the headers by hand ,$4 times-. Je can place the editing commands in a script file ex*cr1 as shown below+
15/EFE@G/31# w t(% ?

Then execute with Kex dat(1 M ex*cr1K %inally after testing we could place this in a shell script loop
#@/,+n/sh # She!! s&r+%t for a%%!"+ng e#+t+ng s&r+%t to re(o$e hea#ers fro( #ata sets for f +n #atC // These &o((ents are not %art of the f+!e #o // #atC +s e.%an#e# to the !+st // of a!! f+!es that (at&h the %attern e. Hf 2 e.S&r1 // for ea&h f+!e we a%%!" e.S&r1 ($ t(% Hf out // an# then ($ t(% to #at>> out #one

Iotes on this example


11 11

*hell script is in a file sh*cr1 it can be excuted with Ksh sh*cr1K or by first changing the mode ,as in chmod Bx sh*cr1- then just issue the command Ksh*cr1K

/egular expressions - pattern used to match strings 0ni) !egular 3)pressions !egular 3)pression . r1 r' r6 r1 0 r' rS rB ,rE ... F E^ ... F El-=F Matches matches any single character matches r1 followed by r' matches =ero or more occurrences of the pattern r matches if either r1 or r' matches matches =ero or one occurrence of the pattern r matches one or more occurrences of the pattern r matches r, the parentheses are just for grouping matches any single character contained between the brackets matches any single character not contained between the brackets matches the range of characters from l to =

^ : @>n, m @?

matches the start of a line matches the end of a line matches n to m occurences of the previous pattern

@x matches the single character x, ,@ W Duote<xamples o city, *tate 5bbreviation RIN o *ocial-security number o Telephone number o Xollar amounts o blank lines o entire lines o one or more spaces Testing examples of regular expressions with grep I.O. *hells filename expansions do not really use regular expressions o 6 matches any string not Vleene closure

*<X - The *tream &riented <ditor &peration first a single line is read into the pattern space ,bufferthen a list of editing commands are matched against the buffer if they match then the commands are applied finally the buffer is written to the standard output another line is read and the process repeats <xecution of sed commands
1 2 3 4 5

sed commands are of the form address-pattern editing-command In all but the simpliest cases the editing commands are placed in a file, ,a sed scripto <xample+ sed -e #.^:.d# M ds1 o &r placing the command .^:.d in the file sed*cr1 we can execute it as sed -f sed*cr1 M ds1 *<X 5ddressing o (,1 or ' addresses are specified o types+ line number, pattern, or line symbol o Io address means the command should be applied to every line o &ne address means the command should be applied to every line that matches the pattern o Two address means the command should be applied to every line between the first line that matches the first pattern and the first following line that matches the second pattern ,inclusive of the lines that match-. o addr L means the command should be applied to the lines that do not match addr <xamples o Xelete mail header o change .usr.mail to .usr'.mail throughout file
o o

o Xeformat nroff man page *ed ;ultiYine 9ommands+ I ,join-, X ,delete upto first embedded @n-

5JV 5ho, Jeinberger, and Vernighan of Oell Yabs 5nother tool for manipulating files 5JV treats a file as Ka collection of lines of fieldsK where *<X treats a file as Ka collection of lines of charactersK 5n 5JV program is a seDuence of pattern { procedure 5JV variables o :1 :', :3 ... o :( o I% o I/ o %* o /* o O<PII o <IX *ome *imple awk examples o awk #>print Khello, worldK?# test1 o awk #>print?# ds1 o awk # O<PII>print Khello, worldK? <IX >print KbyeK?# ds 1 o rearranging fields awk -%+ #>print :3, :1?# M .etc.passwd o summing up a field
o o o o o o o o o o o o o o o o o

J &at aw0su( // Su( u% a f+e!# fro( a f+!e e.a(%!e :8<'K L M;SMMN0 O // The %attern :8<'K (at&hes ,efore the f+rst !+ne L M;SMM N M;SMM = PH3 OPP 8K6 L %r+nt BThe Su( of F+e!# 3 +s B5 M;SMM/ %r+nt BThe nu(,er of re&or#s +s B5 KQ O // The %attern 8K6 (at&hes after the !ast !+ne J &"%-aw0 3F- 3f aw0su( /et&/%assw# The Su( of F+e!# 3 +s 338992 The nu(,er of re&or#s +s 540

I I

I I

The 5JV Nrogramming ;odel Nattern ;atching o 5wk prgram to recogni=e integers, strings, and blank lines .E(- FB:. >print KThat line ends with an integer.K? .E5-Ra-=FB. >print KThat line contains a string.K? .^:. >print KThat line is a blank line.K? <xample+ Olocklist.awk 9ontrol *tructures o if if ,ave H $ - grade W K5K

I I I I I I I I I I I I I I I I I

if - else while ,conditionaction o for , set!counter " test!counter" incr!counter - action for ,i W I%A i HW 1A i--- print :i 5verage 7J grades
o o su( N 0 for R+ N 2/ + 2N KF/ ==+S su( =N H+ a$erage N su( /RKF 3 1S

5ssociative 5rrays 5/PC, 5/P9, <ICI/&I


:8<'KL for R+ N 0/ + 2 AQ<T/ ==+S %r+ntRAQ<UF+GS %r+nt AQ<T forRen$ +n 8KU'QVKS %r+nt en$ BNB 8KU'QVKFen$G

%unctions+ printf, rand, srand, tolower,s-, toupper,s*tring %unctions+ index,s,t-, length,s-, split,s,a,sep-, sprintf

*hell
o o o

;etacharacters for filename expansion+ 6,S,EF, I.& redirection+ 0 H M HH H8 'H MM shell variables

I I I I

set var W value in csh var W value in sh :var in subseDuent commands replaced by value of var o predefined variables *hell Nrogramming o *pecial variables+ :U, :6 o 9ontrol structures for test if while case Nerl - read a book tcl - Tool command language tcl.tk - graphics interfaces /eal Xata ;anipulation Nroblem o &nline advisement appointments o 7T;Y form, perl cgi o Xatabases+ Nassword o Xatabases+ Nrior 9ourses o ;* <xcel - Cisual Oasic *cripts - 7ostexplorer &bjects

I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I

dropaddG data
H (ore 6:F00 T9T 6QV*A664 457012330 200041 KF5 T)AQW'8 :QVWK XQ 1 VF 1

ST) 435 TW 5 MAX 108< Q8S Q TQS 01 )Q 003 SK'K6 <QA6T8QM 68<1 68<2 SMS*'K6AS1 Q8<STATS A ' ) AS2 6AT83T;*8 68*T TQS8 S8T TQ <Q6 S8SS * < K ' ST)86 MTWTFSV T'M8 *QVF8SSVQ 08152000 A TST8 590 002 03 T002 569740 9 9 0400* FAQYAS

MS<10 'KZM'Q; TVM*W8T8/ATT'U8 6: 33333333333333333333333333333333333333333333333333333333333333333333333 33333333 3 43 2 Sess31 129 252 45 13 6TT*0359 # 6QV*A664 642073504 200041 5 :'< :V; 1 VF 1 KF68<1

ST) 435 TW 5 MAX 456< Q8S K TQS 05 )Q 012 SK'K6 <QA6T8QM 68<2 SMS*'K6AS1 Q8<STATS A ' ) AS2 6AT83T;*8 68*T TQS8 S8T TQ <Q6 S8SS * < K ' ST)86 MTWTFSV *QVF8SSVQ 08012000 A TST8 510 001 03 T002 534460 9 9 MATT)8WS 07282000 A TST8 516 001 03 T002 535300 9 MVKTA<M8 08312000 5 TST8 590 001 03 W T002 W 535360 9 9 9 UAWTVQTA 07172000 A TST8 822 001 03 T002 554140 9 9 UAQ<AS

T'M8 0530* 0530* 1010A 1230*

<x script o delete unwanted lines


o

I I I I I I I I I I I

5wk *cript
H (ore #ro%a##4Aw0S&r / 6QV*A664/ L'6NH2/ se(esterNH3/ na(eNH5 O /E ST) /L s&hoo! N H2/ (a1orNH6/O /E F039GF039GF039GF039GF039GF039GF039GF039G/ L +f RH7 NN BT002BSL%r+nt '65 se(ester5 H35 H45 H6/ Oe!seL %r+nt '65 se(ester5 H35 H45 H65 H7/ O O

Вам также может понравиться