Unix Brief
-
Upload
satish-kumar -
Category
Documents
-
view
223 -
download
2
description
Transcript of Unix Brief
![Page 1: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/1.jpg)
Introduction to UNIX
![Page 2: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/2.jpg)
What is UNIX?
An Operating System (OS) Mostly coded in C Machine independence It provides a number of facilities:
management of hardware resources directory and file system loading / execution / suspension of
programs
![Page 3: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/3.jpg)
History (Brief)
1969 First UNIX at Bell Labs The MULTICS Kernighan, Ritchie,
Thompson 1970’s
Bell Labs makes UNIX freeware
Berkeley UNIX (BSD) Bill Joy vi editor, C
Shell
1980’s System V release 4 TCP/IP Sun Microsystems
Solaris Microsoft Xenix, SCO MIT X-Windows
1990’s GNU, LINUX Stallman, Torvalds
![Page 4: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/4.jpg)
Why Use UNIX?
multi-tasking / multi-user lots of software networking capability graphical (with command line) easy to program portable (PCs, mainframes,
super-computers)
continued
![Page 5: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/5.jpg)
free! (LINUX, FreeBSD, GNU) popular profitable
1996 Sales: US$34.5 Billion, up 12% not tied to one company active community
![Page 6: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/6.jpg)
Your Account
Each user has their own space called their account.
Type your login ID and password to enter your account.
Only if the login ID and password match will you be let in.
![Page 7: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/7.jpg)
Login to your Account
login: ad You type your ID and RETURN.
Password: You type your password and RETURN. It does not appear.
$ The UNIX prompt (or similar). You can now enter commands.
![Page 8: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/8.jpg)
Logout from your Account
logout
or
^D Press CONTROL and D together
orexit
![Page 9: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/9.jpg)
On-line Help
man Manual pages Spacebar to go on; ^C to
stopman gnuchess
man man
apropos topic Lists commands related to topic
apropos game
apropos help
![Page 10: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/10.jpg)
UNIX Books
The Unix Programming Environment, Brian W. Kernighan and Rob Pike. Prentice Hall, Inc., 1984.
Sumitabha Das, "Unix : Concepts and Applications"
A Student’s Guide to UNIX, Harley Hahn, McGraw-Hill, 1993
A Practical Guide to the UNIX System, Mark G. Sobell, Benjamin-Cummings, 3rd Edition, 1995
![Page 11: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/11.jpg)
Hardware
Kernel
Compilers
Inte
rne
t To
ols
Unix
Comm
ands
Databas
e Package
s
Other A
pplicatio
n/
System Softw
are
Shell
Shell
Shell
Shel
lUser
Use
r Use r
User
Kernel-Shell Relationship
![Page 12: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/12.jpg)
The Shell
The UNIX user interface is called the shell. The shell does 4 jobs repeatedly:
displayprompt
executecommand
processcommand
readcommand the shell
![Page 13: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/13.jpg)
Typing Commands
Try these:date
cal 3 2005
who
ls -a
man cal
clear
![Page 14: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/14.jpg)
Changing your Password
The command is:passwd
It will ask you for the new password twice.
![Page 15: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/15.jpg)
Date Commands
date Gives time and date
cal Calendarcal 1997
cal 3
cal 7 1962
cal 9 1752
![Page 16: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/16.jpg)
You and the System
uptime Machine’s ‘up’ time hostname Name of the machine
whoami Your name who
![Page 17: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/17.jpg)
Calculators
expr e Simple arithmeticexpr 3 + 5 + 7
bc Programmable Calculator
![Page 18: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/18.jpg)
Some General Purpose CommandsSome General Purpose Commands
date date locatelocatecal cal moremorewhowho passwdpasswdls ls echoechomanman bannerbannerclearclear tty tty uptimeuptime uname uname
hostnamehostname tput tput
quotaquota spell spell
whoamiwhoami ispell ispell aproposapropos catcatwhatiswhatis sortsortwhichwhich pwdpwd
![Page 19: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/19.jpg)
Redirection, pipes , processes Output can be redirected to a file with‘>‘:
ls > dir.txtcal 2004 > year2004
Output can be appended to a file with ‘>>‘cal 2004 > yearscal 2005 >> years
Pipes : sending the output of one program to the input of the otherls | sort
who | sort
Processes : Running two commands sequentially
locate mj > xxx; date
locate usr > xxx &
![Page 20: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/20.jpg)
The UNIX File System
![Page 21: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/21.jpg)
The File
Ordinary Files
Directory Files
Device Files
![Page 22: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/22.jpg)
The Parent Child Relationship
A simplified UNIX directory/file system:
/
etc bin usr1
faculty
dev tmp
date cal. . .. . . . . .. . .
mj
![Page 23: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/23.jpg)
Some System Directories
/ root directory
/bin commands
/etc system data files(e.g. /etc/passwd)
/dev files representing I/O devices
![Page 24: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/24.jpg)
Pathnames
A pathname is a sequence of directory names (separated by /’s) which identifies the location of a directory.
There are two sorts of pathnames absolute pathnames relative pathname
![Page 25: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/25.jpg)
Absolute Pathnames
The sequence of directory names between the top of the tree (the root) and the directory of interest.
For example:/bin/etc/terminfo/export/user/home/ad/export/user/home/s3910120/proj1
![Page 26: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/26.jpg)
Relative Pathnames
The sequence of directory names below the directory where you are now to the directory of interest.
If you are interested in the directory proj1:proj1 if you are in s3910120s3910120/proj1 if you are in homehome/s3910120/proj1 if you are in user
![Page 27: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/27.jpg)
Commands and Pathnames
Commands often use pathnames.
For example:/usr/games/fortune
cat /etc/passwd List the password file
![Page 28: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/28.jpg)
Moving between Directories
s3910120’s home directory:
s3910120
hobby.c proj1
. . .
proj2
. . .
![Page 29: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/29.jpg)
If you are in directory s3910120 how do you move to directory proj1?cd proj1
You are now in proj1. This is called the current working directory.
![Page 30: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/30.jpg)
pwd Print name of current working directory
Move back to directory s3910120 (the parent directory):cd ..
![Page 31: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/31.jpg)
When in proj1, move to proj2 with one command:cd ../proj2
../proj2 is a relative pathname
![Page 32: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/32.jpg)
Special Directory Names
/ The root directory . The current working
directory .. The parent directory
(of your current directory)
![Page 33: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/33.jpg)
Examples
cd / Change to root directory cd ~ Change to home directory cd (Special case; means cd ~)
cd ../.. Go up two levels.
![Page 34: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/34.jpg)
Investigate the System
Use cd cat file List file
cd /etc
cat passwd
ls Directory listingls List current dir.
ls /etc List /etc
![Page 35: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/35.jpg)
Making / Deleting / Renaming Directories
Usually, you can only create directories (or delete or rename them) in your home directory or directories below it.
mkdir Make a directory
rmdir Delete a directory
mv Rename a directory
![Page 36: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/36.jpg)
Permissions
ls –l /etc/passwd-rw-r--r-- 1 root root 2365 Jul 28 16:19 /etc/passwd
read, write, execute (r w x) - rw- r-- r-- directory owner group everyone
chmod -w, +w ….
![Page 37: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/37.jpg)
Commands to work with files
cat > filename less head tail cp mv rm wc grep spell ispell
![Page 38: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/38.jpg)
Communicating with People
![Page 39: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/39.jpg)
Information on Others
users Who else is logged on?
who Information on current users
ps What are people doing?ps -au
![Page 40: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/40.jpg)
w What are people doing?w -sh A shorter report
Examine password info:more /etc/passwd
grep s38 /etc/passwd
![Page 41: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/41.jpg)
Fingering People
finger Info. on current usersfinger -l Longer information
finger user Information on user (need not be logged
in)finger ad
![Page 42: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/42.jpg)
finger @machine-name User info. for that machine
finger @catsix
finger @ratree.psu.ac.th
ping machine-name Is machine alive (on)?
ping catsix (^C to stop)
![Page 43: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/43.jpg)
Your Finger Information
chfn Change your finger entry
finger also prints the contents of the .plan and .project files in your home directory. List ‘.’ files with:ls -a
![Page 45: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/45.jpg)
write user Send a message to user
on this machinewrite ad
mesg n Switch off talk / write acceptance.
mesg y Switch on
![Page 46: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/46.jpg)
Sending E-mail
Send mail :
mail Add Subject: Shoe ProblemWhat colour are my shoes? I cannot see them at the moment because of my desk.- Jim^D
![Page 47: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/47.jpg)
The vi Editor
Two modes Insert i Command <ESC>
Append a Replace character r, Replace word R ….. Deleting character x, Deleting line dd Exit
Goto command mode press :wq……
![Page 48: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/48.jpg)
Filters
The UNIX programs that read some input, perform a simple transformation on it and write some output.
grep, egrep, fgrep tr, dd, sort Sed, awk – programmable filters
![Page 49: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/49.jpg)
grep
grep options pattern format filename(s)
Some option -c Counting number of occurrences -n Line numbers along with lines grep Mamata –e mamata database grep [Mm]amata database
![Page 50: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/50.jpg)
grep : Regular Expressions
Character sets [mM] , [aeiou] , [a-zA-Z0-9]
Immediately preceeding character G*, [gG]*
Matching a single character 2… A four character pattern starting with 2 .* A number of characters or none
![Page 51: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/51.jpg)
grep : RE
Specifying pattern boundaries ^r pattern beginning
with expression r
^[^r] pattern not beginning with expression r
r$ pattern ending with expression r
c Any non-special character c matches
\c Turn off any special meaning of character c
^ Beginning of line
$ End of line
. Any single character
[…] Any one of character in …; ranges like a-z are legal
[^…] Any single character not in …; ranges are legal
r* Zero or more occurrences of r
r1r2 RE r1 followed by RE r2
![Page 52: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/52.jpg)
egrep : Regular Expressions
r+ : one or more occurrences of r r? : zero or more occurrences of r r1|r2 : r1 or r2 (r) : nested r
![Page 53: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/53.jpg)
fgrep
Searches for multiple patterns Does not accept regular expression Multiple patterns are separated by new
line character.
The disadvantage of grep family is that none of them has a separate facility to identify fields.
![Page 54: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/54.jpg)
sort
-f : eliminates distinction between uppercase and lowercase letters.
-n : numeric comparison - r : largest to smallest +m : comparison skips first m fields +0 : beginning of the line -u : discard duplicates
![Page 55: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/55.jpg)
comm
File comparison command Gives three columns of the output
Lines that occur only in file 1 Lines that occur only in file 2 Lines that occur in both
One or more columns can be suppressed Comm –12 f1 f2
![Page 56: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/56.jpg)
tr
Transliteration of character in the input tr a-z A-N
Mostly used for character conversion
![Page 57: Unix Brief](https://reader036.fdocuments.us/reader036/viewer/2022062323/563dbbc2550346aa9ab007b3/html5/thumbnails/57.jpg)
Assignment
1. Try all the UNIX commands. Store the output in a file appropriately using redirection operators.
2. Read a word from the terminal and check if the spelling is correct. Suggest few alternatives.
3. Create a file using Vi. Store few names in the file. Search all the names containing the letter M or m.
4. Create another file using cat command5. Compare both the files to find the differences6. Use calculator commands to compute 5
arithmetic expressions.