Professional Documents
Culture Documents
A:Basic Commands:
1.PATH:
The Sequence of Directories that the shell searches to look for a command is specified in its own PATH variable. If you evaluate the value of this variable, youll find a directory list separated by colons: $echo $PATH /bin:/usr/bin:/usr/local/bin:/usr/ccs/bin:.
2.Man :
Getting Help,The Unix manual, usually called man pages, is available on-line to explain the usage of the Unix system and commands. To use a man page, type the command "man" at the system prompt followed by the command for which you need information. Syntax: man [options] command_name Common Options
-k -M -a keyword list command synopsis line for all keyword matches path path to man pages show all matching man pages (SVR4)
Examples:You can use man to provide a one line synopsis of any commands that contain the keyword that you want to search on with the "-k" option, e.g. to search on the keyword password, type:
% man -k password passwd (5) - password file passwd (1) - change password information
The number in parentheses indicates the section of the man pages where these references were found. You can then access the man page (by default it will give you the lower numbered entry, but you can use a command line option to specify a different one) with:
% man passwd PASSWD(1) USER COMMANDS PASSWD(1) NAME passwd - change password information SYNOPSIS passwd [ -e login_shell ] [ username ] DESCRIPTION passwd changes (or sets) a user's password. passwd prompts twice for the new password, without displaying it. This is to allow for the possibility of typing mistakes. Only the user and the super-user can change the user's password. OPTIONS:-e Change the user's login shell.
Here weve paraphrased and truncated the output for space and copyright concerns. Page 1 of 36
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
4.Printf:
The printf, formatted print, command is an enhanced echo. It is a limited variant of the C language printf() library function, and its syntax is somewhat different. printf format-string... parameter... This is the Bash builtin version of the /bin/printf or /usr/bin/printf command. See the printf manpage (of the system command) for in-depth coverage. This an alternative to echo.
5.Script:
Recording your session, When executed it creates a file named typescript and saves all the tasks performed within that session, to close the script use exit. If again the script is initiated the process will be done instead it wont create another new file indeed the same file will be overwritten. $script Script started, file is typescript $_ Later when given exit $exit Script done, file is typescript.
8.who
who $who #who -a #who -b Page 2 of 36 - show who is logged on ->Lists who logged on ->display all information abt the users and system. ->time of last system boot
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
9.whoami
Print the user name associated with the current effective user id. $whoami
10.date - current date and time:date displays the current data and time. A superuser can set the date and time. Syntax
date [options] [+format]
Common Options
-u + %a %h %j %n %t %y %D %H %M %S %T use Universal Time (or Greenwich Mean Time) format specify the output format weekday abbreviation, Sun to Sat month abbreviation, Jan to Dec day of year, 001 to 366 <new-line> <TAB> last 2 digits of year, 00 to 99 MM/DD/YY date hour, 00 to 23 minute, 00 to 59 second, 00 to 59 HH:MM:SS time
Page 3 of 36
Options
(none) report the terminal settings all (or -a) report on all options echoe echo ERASE as BS-space-BS dec set modes suitable for Digital Equipment Corporation operating systems (which distinguishes between ERASE and BACKSPACE) (Not available on all systems) kill set the LINE-KILL character erase set the ERASE character intr set the INTERRUPT character
Examples You can display and change your terminal control settings with the stty command. To display all (-a) of the current line settings:
$stty -a speed 38400 baud, 24 rows, 80 columns parenb -parodd cs7 -cstopb -hupcl cread -clocal -crtscts -ignbrk brkint ignpar -parmrk -inpck istrip -inlcr -igncr icrnl -iuclc ixon -ixany -ixoff imaxbel isig iexten icanon -xcase echo echoe echok -echonl -noflsh -tostop echoctl -echoprt echoke opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel erase kill werase rprnt flush lnext susp intr quit stop eof ^H ^U ^W ^R ^O ^V ^Z/^Y ^C ^\ ^S/^Q ^D
You can change settings using stty, e.g., to change the erase character from ^? (the delete key) to ^H:
$stty erase ^H
This will set the terminal options for the current session only. To have this done for you automatically each time you login, it can be inserted into the .login or .profile file that well look at later.
13.cd [dir]
Change the current directory to dir. The variable HOME is the default dir. Ex:Without specifying any directory it will take us to user home directory $cd ->Takes to home directory of the user. $cd . ->To current Directory. $cd .. ->To parent directory. Page 4 of 36
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
14.mkdir
Create the DIRECTORY(ies), if they do not already exist. $mkdir dirname->Makes directory with default 755 permission. $mkdir -m 777 dirname ->This is used to set permissions of the directory. $mkdir -p /pdir/dir ->This is used to create parent directories if they does not present previously.
15.rmdir
Remove empty directories. Contents of the files should be removed first to use this command. $rmdir dirname ->Removes an empty directory. $rmdir -p /pdir/dir->Equalent to removing individual directories.
16.ls
List directory contents. Usage:It has a rich set of options,Important ones are. #ls ->Lists all directory contents without recursively going into contents of its subdirectories. #ls -R ->List subdirectories recursively. #ls -a ->Shows hidden files also. #ls -ltc ->Sort the contents of dir #ls -r ->Reverse order while sorting #ls -d ->list directory entries instead of contents #ls -l ->Long listing format will be displayed. ->Equalent to short form ll. #ls -1 ->shows contents one per line. #ls -S ->sort by file size. To get a long listing: $ls -al
total 24 drwxr-sr-x 5 workshop acs 512 Jun 7 11:12 .
Page 5 of 36
17.rm
remove files or directoriesIt removes each specified file. By default, it does not remove directories. #rm -i, --interactive -> Prompt before any removal #rm -r or -R ->Remove the contents of directories recursively
18.more
File perusal filter for controlled viewing. More is a filter for paging through text one screenful at a time. Usage:#more filename->shows contents of a file one screen at a time. #ls | more ->Shows the output of ls one at a time. Note:Command's output may be sent to more for viewing specifically. | symbol is called a filter which filters input from one command to other.
19.cp
cp [OPTION]... SOURCE DEST Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. #cp -i Source Dest ->Prompt before overwrite. #cp -l Source Dest ->Link files instead of copying. #cp -R or -r Source Dest ->Copy directories recursively. #cp -s Souce Dest->Make symbolic links instead of copying. #cp -u Source Dest ->Copy only when the SOURCE file is newer than destination file or when the destination file is missing. #cp -b Source Dest ->Make a backup of each existing destination file.
the
20.mv
Move (rename) files mv [OPTION]... SOURCE DEST mv [OPTION]... SOURCE... DIRECTORY. Page 6 of 36
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
21.cat
Concatenate FILE(s), or standard input, to standard output. #cat filename ->Displays contents of a file. #cat > filename ->This is used to write into the file at std input. For exit from writing mode,type CTRL+c or d.If we repeat this on existing file contents will be overridden. For appending,We use the following command. # cat >> filename For copying one file contents to other following command is used. #cat filename1 > filename2 For appending #cat filename1 >> filename2 For merging more than one file into another or appending more than one file to other # cat file1 file2 > file3 #cat file4 file5 file6 >> file7 #cat -n filename ->Shows contents by assigning numbers to lines.
22. Wc:
when used counts the number of words, characters and lines in a file. Options: -w counts number of words -c counts number of characters -l counts number of lines.
23.ln
Make links between files ln [OPTION]... TARGET [LINK_NAME] ln [OPTION]... TARGET... DIRECTORY Create a link to the specified TARGET with optional LINK_NAME. If LINK_NAME is omitted, a link with the same basename as the TARGET is created in the current directory. When using the second form with more than one TARGET, the last argument must be a directory; create links in DIRECTORY to each TARGET. Create hard links by default, symbolic links with --symbolic. When creating hard links, each TARGET must exist. Usage:#ln filename1 filename2 ->Assigning filename2 a link to filename1. # ln -s file1 file2 ->Creating a symbolic link.(By defaut there will be a hard link). Page 7 of 36
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
Page 8 of 36
3.Undo Command
u undo the last command.
4.Screen Commands
CTL/l Reprints current screen. CTL/L Exposes one more line at top of screen. CTL/E Exposes one more line at bottom of screen. CTL/F Pages forward one screen. CTL/B Pages back one screen. CTL/D Pages down half screen. CTL/U Pages up half screen.
Page 9 of 36
j Moves cursor down one line, same column. k Moves cursor up one line, same column. h Moves cursor back one character. l Moves cursor forward one character. RET Moves cursor to beginning of next line. 0 Moves cursor to beginning of current line. $ Moves cursor to end of current line. SPACE Moves cursor forward one character. nG Moves cursor to beginning of line n. Default is last line of file. 0 Moves the cursor to the first character of the line. :n Moves cursor to beginning of line n. b Moves the cursor backward to the beginning of the previous word. e Moves the cursor backward to the end of the previous word. w Moves the cursor forward to the next word. /pattern Moves cursor forward to next occurrence of pattern. ?pattern Moves cursor backward to next occurrence of pattern. n Repeats last / or ? pattern search.
Page 10 of 36
8.Changing Commands
cw Changes characters of current word until stopped with escape key. c$ Changes text up to the end of the line. C, cc Changes remaining text on current line until stopped by pressing the escape key.
Page 11 of 36
11.Exiting vi
ZZ Exits vi and saves changes. :wq Writes changes to current file and quits edit session. :q! Quits edit session (no changes made).
Page 12 of 36
2.chown
Change file owner and group. chown [OPTION]... OWNER[:[GROUP]] FILE... chown [OPTION]... :GROUP FILE... chown changes the user and/or group ownership of each given file, according to its first non-option argument, which is interpreted as follows. If only a user name (or numeric user ID) is given, that user is made the owner of each given file, and the files group is not changed. If the user name is followed by a colon or dot and a group name (or numeric group ID), with no spaces between them, the group ownership of the files is changed as well. If a colon or dot but no group name follows the user name, that user is made the owner of the files and the group of the files is changed to that users login group. Usage:#chown username filename->This changes owner of the file to username. #chown username: filename->This changes ownership to username and group name to user default groupname. #chown username:groupname filename ->This changes both username and Groupname. # chown -R username dirname -> Operate on files and directories recursively.
Page 13 of 36
4. touch
Update the access and modification times of each FILE to the current time. Usage:#touch filename ->This creates new empty file with time stamp. #touch -a filename ->This changes only access time of the file. #touch -m filename ->Changes the modified time.
2.Mount: Mounting filesystems:mount [options] devicename on pathname all files accessible in a unix system are arranged in a one big tree, the file hierarchy rooted at / these files can be spread out over several devices. The mount command servers to attach file systems found on some device to the big file tree. It uses t option to specify the type of the filesystem, -a option to mount all filesystems that are listed in configuration file. And to be clear it is a super user command. $mount t /dev/cdro /mnt/cdrom $mount /dev/fd0 /mnt/floppy
Common Options
-l -k local file systems only (SVR4) report in kilobytes (SVR4)
Examples
$ df Filesystem /dev/sd0a /dev/sd0h /dev/sd1g /dev/sd1a kbytes 20895 319055 637726 240111 used 19224 131293 348809 165489 avail 0 155857 225145 50611 capacity 102% 46% 61% 77% Mounted on / /usr /usr/local /home/guardian
Common Options
-a -s -k display disk usage for each file, not just subdirectories display a summary total only report in kilobytes (SVR4)
6.ps
Report a snapshot of the current processes.This command is used to know the current process's process id . $ps To see every process on the system using standard syntax: ps -e ps -ef ps -eF ps -ely To see every process on the system using BSD syntax: ps ax ps axu To print a process tree: ps -ejH ps axjf Page 15 of 36
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
7.kill - terminate a process:kill sends a signal to a process, usually to terminate it. Syntax
kill [-signal] process-id
Common Options
-l displays the available kill signals:
Examples
$ kill -l
HUP INT QUIT ILL TRAP IOT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM URG STOP TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ VTALRM PROF WINCH LOST USR1 USR2
The -KILL signal, also specified as -9 (because it is 9th on the above list), is the most commonly used kill signal. Once seen, it cant be ignored by the program whereas the other signals can. $ kill -9 15599 [1] + Killed emacs unixgrep.txt
10.find
Search for files in a directory hierarchy. Syntax:- find path_list selection_criteria action Usage:#find /root/linux.txt ->searches and finds that matches path. #find /home -user usernmame ->Finds all files of the user in home. #find /usr -name *spec ->finds all files which contains spec #find /var/spool -mtime +40 ->Entries of spool which are above machine time by 40 sec.
$find / -name a.out print
Page 17 of 36
E.networking commands:
1.W:
The w command is slower than the who command because it returns more information such as details about what programs people are running. It also returns a line containing the number of users and the system load average. The load average is the average number of processes ready to be run by the CPU and is a rough way of estimating how busy a system is. $w 6:25pm up 7 day(s), 3:54, 70 users, load average: 1.56, 1.66, 1.70 User tty login@ idle JCPU PCPU what rem pts/0 16Aug 00 3:28 1 jsh wjzhou pts/2 Sat12am 1:35 13 -csh Page 18 of 36
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
bash$ finger bozo Login: bozo Name: Bozo Bozeman Directory: /home/bozo Shell: /bin/bash Office: 2355 Clown St., 543-1234 On since Fri Aug 31 20:13 (MST) on tty1 1 hour 38 minutes idle On since Fri Aug 31 20:13 (MST) on pts/0 12 seconds idle On since Fri Aug 31 20:13 (MST) on pts/1 On since Fri Aug 31 20:31 (MST) on pts/2 1 hour 16 minutes idle No mail. No Plan.
3.TELNET and FTP - remote login and file transfer protocols TELNET and FTP are Application Level Internet protocols. The TELNET and FTP protocol specifications have been implemented by many different sources, including The National Center for Supercomputer Applications (NCSA), and many other public domain and shareware sources. The programs implementing the TELNET protocol are usually called telnet, but not always. Some notable exceptions are tn3270, WinQVT, and QWS3270, which are also TELNET protocol implementations. TELNET is used for remote login to other computers on the Internet. The programs implementing the FTP protocol are usually called ftp, but there are exceptions to that too. A program called Fetch, distributed by Dartmouth College, WS_FTP, written and distributed by John Junod, and Ftptool, written by a Mike Sullivan, are FTP protocol implementations with graphic user interfaces. Theres an enhanced FTP version, ncftp, that allows additional features, written by Mike Gleason. Also, FTP protocol implementations are often included in TELNET implementation programs, such as the ones distributed by NCSA. FTP is used for transferring files between computers on the Internet. rlogin is a remote login service that was at one time exclusive to Berkeley 4.3 BSD UNIX. Essentially, it offers the same functionality as telnet, except that it passes to the remote computer information about the user's login environment. Machines can be configured to allow connections from trusted hosts without prompting for the users Page 19 of 36
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
telnet and tn3270 allow you the option of specifying a port number to connect to on the remote host. For both commands it defaults to port number 23, the telnet port. Other ports are used for debugging of network services and for specialized resources. Examples
telnet oscar.us.ohio-state.edu tn3270 ohstmvsa.acs.ohio-state.edu ftp magnus.acs.ohio-state.edu
The remote machine will query you for your login identification and your password. Machines set up as archives for software or information distribution often allow anonymous ftp connections. You ftp to the remote machine and login as anonymous (the login ftp is equivalent on many machines), that is, when asked for your "login" you would type anonymous. Once you have successfully connected to a remote computer with telnet and rlogin (and assuming terminal emulation is appropriate) you will be able to use the machine as you always do. Once you have successfully connected to a remote computer with ftp, you will be able to transfer a file "up" to that computer with the put command, or "down" from that computer with the get command. The syntax is as follows:
put local-file-name remote-file-name get local-file-name remote-file-name
Other commands are available in ftp as well, depending on the specific "local" and "remote" FTP
Page 20 of 36
4.ftp
Use ftp to connect to a remote machine, then upload or download files. See also: ncftp Example 1: We'll connect to the machine fubar.net, then change director to mystuff, then download the file homework11: % ftp solitude Connected to fubar.net. 220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready. Name (solitude:carlson): jeremy 331 Password required for jeremy. Password: 230 User jeremy logged in. ftp> cd mystuff 250 CWD command successful. ftp> get homework11 ftp> quit Example 2: We'll connect to the machine fubar.net, then change director to mystuff, then upload the file collected-letters: % ftp solitude Connected to fubar.net. 220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready. Name (solitude:carlson): jeremy 331 Password required for jeremy. Password: 230 User jeremy logged in. ftp> cd mystuff 250 CWD command successful. Page 21 of 36
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
5.arp:
Manipulate system arp catch. Arp [-v] d hostname Arp manipulates the kernels cache in various ways the primary options are clearing an address mapping in tree manually setting up one. In all places where hostname is expected one can also enter an IP address dotted decimal notation. Options: -n shows numerical address -a [hostname] displays host name -d [hostname] delete host name
2.tail
Output the last part of files. Usage:#tail filename ->Prints last 10 lines of the file. #tail -n filename ->Prints last n number of lines specified in the command.
3.SORT:
sort - sort file contents The sort command is used to order the lines of a file. Various options can be used to choose the order as well as the field on which a file is sorted. Without any options, the
Page 22 of 36
Common Options
-b ignore leading blanks (<space> & <tab>) when determining starting and ending characters for the sort key -d dictionary order, only letters, digits, <space> and <tab> are significant -f fold upper case to lower case -k keydef sort on the defined keys (not available on all systems) -i ignore non-printable characters -n numeric sort -o outfile output file -r reverse the sort -t char use char as the field separator character -u unique; omit multiple copies of the same line (after the sort) -c check if given files already sorted, do not sort. -m merge already sorted files, do not sort. +pos1 [-pos2] (old style) provides functionality similar to the "-k keydef" option.
For the +/-position entries pos1 is the starting word number, beginning with 0 and pos2 is the ending word number. When -pos2 is omitted the sort field continues through the end of the line. Both pos1 and pos2 can be written in the form w.c, where w is the word number and c is the character within the word. For c 0 specifies the delimiter preceding the first character, and 1 is the first character of the word. These entries can be followed by type modifiers, e.g. n for numeric, b to skip blanks, etc. The keydef field of the "-k" option has the syntax:
start_field [type] [ ,end_field [type] ]
where: start_field, end_field define the keys to restrict the sort to a portion of the line type
modifies the sort, valid modifiers are given the single characters (bdfiMnr) from the similar sort options, e.g. a type b is equivalent to "-b", but applies only to the specified field
Page 23 of 36
A particularly useful sort option is the -u option, which eliminates any duplicate entries in a file while ordering the file. For example, the file todays.logins:
sphillip jchen jdoe lkeres jmarsch ageorge lkeres proy jchen
shows a listing of each username that logged into the system today. If we want to know how many unique users logged into the system today, using sort with the -u option will list each user only once. (The command can then be piped into "wc -l" to get a number):
% sort -u todays.logins ageorge jchen jdoe jmarsch lkeres proy
Page 24 of 36
5.Uniq:
uniq - remove duplicate lines uniq filters duplicate adjacent lines from a file. Syntax
uniq [options] [+|-n] file [file.new]
Common Options
-d -u +n -s -n -f -c -D -I one copy of only the repeated lines select only the lines not repeated(unique) ignore the first n characters n same as above (SVR4 only) skip the first n fields, including any blanks (<space> & <tab>) fields same as above (SVR4 only) count all repeated print only duplicate lines. ignore case
Note: its discards all but one successive identical lines from INPUT, by default uniq prints lines in a sorted file , optionally it can instead show only lines that appear exactly once or lines that appear more than once. -here it must be sorted. - if no input file is specified uniq writes to standard output.
Examples Consider the following file and example, in which uniq removes the 4th line from file and places the result in a file called file.new.
$ cat file 1236 4536 7890 7890 $ uniq file file.new $cat file.new
Page 25 of 36
Below, the -n option of the uniq command is used to skip the first 2 fields in file, and filter out lines which are duplicates from the 3rd field onward.
$uniq -2 file 1236 7890
6.grep
This section provides an introduction to the use of regular expressions and grep. The grep utility is used to search for generalized regular expressions occurring in Unix files. Regular expressions, such as those shown above, are best specified in apostrophes (or single quotes) when specified in the grep utility. The egrep utility provides searching capability using an extended set of meta-characters. The syntax of the grep utility, some of the available options, and a few examples are shown below. Syntax
grep [options] regexp [file[s]]
Common Options
-i ignore case -c report only a count of the number of lines containing matches, not the matches themselves -v invert the search, displaying only lines that do not match -n display the line number along with the line on which a match was found -s work silently, reporting only the final status: 0, for match(es) found 1, for no matches 2, for errors -l list filenames, but not lines, in which matches were found
Page 26 of 36
Now well use the "-c" option to count the number of lines matching the search criterion:
$grep -c '15' num.list 2
Here well be a little more general in our search, selecting for all lines containing the character 1 followed by either of 1, 2 or 5:
$ grep '1[125]' num.list 1 15 fifteen 4 12 twelve 5 11 eleven 11 5 five 12 4 four 15 1 one
This example will search for any instances of t followed by zero or more occurrences of e:
$grep 'te*' num.list 1 15 fifteen 2 14 fourteen 3 13 thirteen 4 12 twelve 6 10 ten 8 8 eight 13 3 three 14 2 two
This example will search for any instances of t followed by one or more occurrences of e:
$grep 'tee*' num.list 1 15 fifteen 2 14 fourteen 3 13 thirteen 6 10 ten
We can also take our input from a program, rather than a file. Here we report on any lines output by the who program that begin with the letter l.
$ who | grep '^l' lcondron ttyp0 Dec 1 02:41 (lcondron-pc.acs.)
$ grep E [aA]gg?arwal emp.lst $grep E sengupta|dasgupta emp.lst $grep E (sen|das)gupta emp.lst Here, + matches one or more occurrences of the previous character ? matches zero or one occurrence of the previous character.
Page 27 of 36
Common Options
-c -d -f character_list character positions to select (first character is 1) delimiter field delimiter (defaults to <TAB>) field_list fields to select (first field is 1)
Both the character and field lists may contain comma-separated or blank-characterseparated numbers (in increasing order), and may contain a hyphen (-) to indicate a range. Any numbers missing at either before (e.g. -5) or after (e.g. 5-) the hyphen indicates the full range starting with the first, or ending with the last character or field, respectively. Blank-character-separated lists must be enclosed in quotes. The field delimiter should be enclosed in quotes if it has special meaning to the shell, e.g. when specifying a <space> or <TAB> character. Examples In these examples we will use the file users:
jdoe lsmith pchen jhsu sphilip John Laura Paul Jake Sue Doe Smith Chen Hsu Phillip 4/15/96 3/12/96 1/5/96 4/17/96 4/2/96
If you only wanted the username and the user's real name, the cut command could be used to get only that information:
$cut -f 1,2 users jdoe John Doe lsmith Laura Smith pchen Paul Chen jhsu Jake Hsu sphilip Sue Phillip
The cut command can also be used with other options. The -c option allows characters to be the selected cut. To select the first 4 characters:
$cut -c 1-4 users
This yields:
jdoe lsmi pche jhsu sphi
thus cutting out only the first 4 characters of each line. $cut c 6-22,24-32 shiva $cut d \| -f 2,3 shiva|tee cutlist $cut d | f 1,4- shiva>cutlist2 $who |cut d f1
Page 28 of 36
Common Options
-d -s list list of delimiting characters concatenate lines
The list of delimiters may include a single character such as a comma; a quoted string, such as a space; or any of the following escape sequences:
\n <newline> character \t <tab> character \\ backslash character \0 empty string (non-null character)
It may be necessary to quote delimiters with special meaning to the shell. A hyphen (-) in place of a file name is used to indicate that field should come from standard input. Examples Given the file users:
jdoe lsmith pchen jhsu sphilip John Laura Paul Jake Sue John Laura Paul Jake Sue Doe Smith Chen Hsu Phillip Doe Smith Chen Hsu Phillip 4/15/96 3/12/96 1/5/96 4/17/96 4/2/96
the paste command can be used in conjunction with the cut command to create a new file, listing, that includes the username, real name, last login, and phone number of all the users. First, extract the phone numbers into a temporary file, temp.file:
% cut -f2 phone > temp.file 555-6634 555-3382 555-0987 555-1235 555-7623
The result can then be pasted to the end of each line in users and directed to the new file, listing:
% paste users temp.file > listing jdoe John Doe 4/15/96 lsmith Laura Smith 3/12/96 pchen Paul Chen 1/5/96 jhsu Jake Hsu 4/17/96 sphilip Sue Phillip 4/2/96 237-6634 878-3382 888-0987 545-1235 656-7623
Page 29 of 36
Common Options
-a -i append the output to the files ignore interrupts
Examples In this first example the output of who is displayed on the screen and stored in the file users.file:
$ who | tee users.file condron ttyp0 Apr 22 14:10 (lcondron-pc.acs.) frank ttyp1 Apr 22 16:19 (nyssa) condron ttyp9 Apr 22 15:52 (lcondron-mac.acs)
In this next example the output of who is sent to the files users.a and users.b. It is also piped to the wc command, which reports the line count.
brigadier: condron [57]> who | tee users.a users.b | wc -l 3
In the following example a long directory listing is sent to the file files.long. It is also piped to the grep command which reports which files were last modified in August.
brigadier: condron [60]> ls -l | tee files.long |grep Aug 1 drwxr-sr-x 2 condron 512 Aug 8 1995 News/ 2 -rw-r--r-- 1 condron 1076 Aug 8 1995 magnus.cshrc 2 -rw-r--r-- 1 condron 1252 Aug 8 1995 magnus.login
Page 30 of 36
Options more
-c -w -lines +/pattern
less
-c -i default +/pattern
pg
-c default -lines +/pattern
Action
clear display before displaying ignore case dont exit at end of input, but prompt and wait # of lines/screenful search for the pattern
The skip numbers are the number of bytes to skip in each file before starting the comparison. Common Options
-l -s report on each difference report exit status only, not byte differences
The default it to report only the first difference found. This command is useful in determining which version of a file should be kept when there is more than one version.
Page 31 of 36
Common Options
-b -i -w -e -r ignore trailing blanks ignore the case of letters ignore <space> and <tab> characters produce an output formatted for use with the editor, ed apply diff recursively through common sub-directories
Examples For the mon.logins and tues.logins files above, the difference between them is given by:
$diff mon.logins tues.logins 2d1 < bsmith 4a4 > jdoe 7c7 < mschmidt --> proy
Note that the output lists the differences as well as in which file the difference exists. Lines in the first file are preceded by "< ", and those in the second file are preceded by "> ".
14.Comm.:
Compare two sorted files line by line. Syntax: Comm. [option] LEFT-FILE RIGHT-FILE Return type: Normal completion 0 Error 1 Options: -1 -2 -3
supress lines unique to LEFT-FILE supress lines unique to RIGHT-FILE Supress lines unique to both FILES.
Page 32 of 36
With no options the characters in string1 are translated into the characters in string2, character by character in the string arrays. The first character in string1 is translated into the first character in string2, etc. A range of characters in a string is specified with a hyphen between the upper and lower characters of the range, e.g. to specify all lower case alphabetic characters use [a-z]. Repeated characters in string2 can be represented with the [x*n] notation, where character x is repeated n times. If n is 0 or absent it is assumed to be as large as needed to match string1. Characters can include \octal (BSD and SVR4) and \character (SVR4 only) notation. Here "octal" is replaced by the one, two, or three octal integer sequence encoding the ASCII character and "character" can be one of:
b f n r t v back space form feed new line carriage return tab vertical tab
The SVR4 version of tr allows the operand ":class:" in the string field where class can take on character classification values, including: alpha alphabetic characters lower lower case alphabetic characters upper upper case alphabetic characters Common Options
-c -d -s complement the character set in string1 delete the characters in string1 squeeze a string of repeated characters in string1 to a single character
Examples The following examples will use as input the file, a list of P. G. Wodehouse Jeeves & Wooster books.
The Inimitable Jeeves [1923] Carry On, Jeeves [1925] Very Good, Jeeves [1930] Thank You, Jeeves [1934] Right Ho, Jeeves [1934] The Code of the Wors [1938] Joy in the Morning [1946] The Mating Season [1949] Ring for Jeeves [1953] Jeeves and the Feudal Spirit [1954] Jeeves in the Offing [1960] Stiff Upper Lip, Jeeves [1963] Much Obliged, Jeeves [1971] Aunts Aren't Gentlemen [1974]
To translate all lower case alphabetic characters to upper case we could use either of:
tr [a-z] [A-Z] or tr [:lower:] [:upper:]
Since tr reads from stdin we first cat the file and pipe the output to tr, as in:
$cat wodehouse | tr [a-z] [A-Z] THE INIMITABLE JEEVES [1923] THE MATING SEASON [1949]
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
Page 33 of 36
16.awk:
The most powerful native text manipulation utility of the Unix system. It combines features of several filters, though its report writing capability is the most useful. Syntax: awk options selection criteria {action} field(s)
awk is not just a command, but a programming language too, it uses an unusual syntax that uses two components and requires single quotes and curly braces. For eg:$awk F| `/sales/{print $2,$3,$4,$5` emp.lst Awk uses a contiguous sequence of spaces and tabs as a single delimiter, $1,$2,$3,$4,$5 indicates the fields -F used for an delimiter and $0 indicates the entire line. Awk extracts the field from its input, something we could do only with cut. Here we use an address to select lines, which is a built-in-variable called NR to specify line numbers: $awk F| `NR==3,NR==6{print NR, $2,$3,$6}` emp.lst
17.Cpio:Copy the files to and from archive. Cpio has 3 operation modes. 1. copy-out-mode: cpio copies files into an archive. It reads a list of filenames, one per line, from the input and writes the archive to the standard output. 2. copy-in-mode:cpio copies files out of an archive or lists the archive contents. It reads the archive from the standard input. 3. copy-pass-mode: cpio copies files from one directory tree to another, combine copy-out and copy-in steps without actually using an archive. Options: -I -o Page 34 of 36
input output
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE
2.gcc
C and C++ language's compiler inbuilt with LINUX. Usage:#Same as cc.
3.g++
C and C++ language's compiler inbuilt with LINUX. Usage:#Same as cc and gcc.
4.php
This command is used to execute php file from command line. Usage:#php filename.php #php -h filename.php ->This will compile without showing information(version,.. etc) header
5.psql
psql - PostgreSQL interactive terminal psql [ option... ] [ dbname [ username ] ] psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results.
Page 35 of 36
6.pg_dump
This command is used to dump the database to a file which can be reinstalled on other systems.Mostly used for backup purposes. Usage:#pg_dump -U postgres databasename > filename.sql ->This dumps database into a file. #pg_dump -U postgres or username databasename < filename.sql This is used to dump file into database.
7.javac
Java Compiler. Usage:#javac filename.java
8.java
Java interpretor Usage:#java filename(not . extension)
9.gcj
Ahead-of-time compiler for the Java language Inbuilt java compiler for Linux. As gcj is just another front end to gcc, it supports many of the same options as gcc. This manual only documents the options specific to gcj. Usage:#gcj filename.java
10.mysql
Text-based client for mysqld, a SQL-based relational database daemon. Usage:#mysql (Before this command is issued,service of mysql should bestarted >service mysqld restart)
11.flex
Fast lexical analyzer generator
12.yacc
an LALR(1) parser generator.
13.lex
Fast lexical analyzer generator. This manual describes flex, a tool for generating programs that perform pattern-matching on text. The manual includes both tutorial and reference sections: Page 36 of 36
Prepared by M.Shiva Kumar.M.Tech.Ph.D,MISTE