Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Text Book
3/9/2012
Samia Riaz
Unix History
1969 origin of Unix, inspired by Ken Thompson First version written by Thompson in one month with assembly language. 1970 Rewritten by Thompson and Dennis Ritchie in B (a scaled down version of BCPL) for a PDP-11 (included line editor ed, text rendering programs). The first user was Bell's Patent Department. First edition of Unix Programmer's Manual by Thompson and Ritchie (dated Nov. 3, 1971) included over 60 commands like: b (compile b program), boot,cat, chdir, chmod, chown, cp, ls, mv, wc.
3/9/2012
Samia Riaz
Unix History
1972-1973 B rewritten into new language called C,Thompson creates pipes as mechanism for connecting output of one program to input of another (groundwork for Unix philosophy), Unix rewritten in C University of Toronto on the first mailing list in 1975. Software Tools User Group formed in 1978 Berkeley Software Distribution grew out of collecting and distributing bug fixes. (Led to FreeBSD, NetBSD) Today: many different (proprietary) versions UNIX is trademark administrated by X/Open
Superset of POSIX specifications actively developed by IEEE
UNIX like system Commercial (Solaris) and free (freeBSD & Linux)
3/9/2012
Samia Riaz
Why Unix?
Available on a number of platforms. Multi-user, multi-programmed. Shares computer resources sensibly. Permits manipulation of files, devices,processes, and programs. Allows inter-process and inter-machine communication. Permits access to its operating features. A core technology of the Internet.
3/9/2012 Samia Riaz 5
UNIX Philosophy
The designers of UNIX used the following maxim while writing the new operating system.
Make each program do one thing well. These simple programs would be called "tools. Expect the output of every program to be the input to another program. Don't stop building new "tools" to do a job. The library of tools should keep increasing.
3/9/2012
Samia Riaz
UNIX Philosophy
Simplicity Focus Reusable Components Filters Open File Formats Flexibility
3/9/2012
Samia Riaz
3/9/2012
Samia Riaz
3/9/2012
Samia Riaz
Linux
Developed by Linus Torvalds at University of Helsinki A Unix-like system, sources not derived from Unix source but interfaces intentionally like Unix. Linux & UNIX programs are similar Linux is actually just a kernel Open source: source code is freely available, can be freely modified Linux Systems
Many distributions Fedora, Suse,Debians, RedHat, Slackware etc
Linux Community supports the concept of free software (GNU General Public License) Free Software Foundation
Richard Stallman, the author of GNU Emacs
3/9/2012
Samia Riaz
10
Linux or UNIX
Two types of executables i,e programs and scripts No special type of formats like DOS, exe, com etc Path /bin: /usr/bin: /usr/local/bin: /sbin: . : /usr/sbin: /opt gcc, cc, g++, c89 (type info gcc) Header Files /usr/include and /usr/include/sys or
/usr/include/linux /usr/lib /usr/lib/libc (.a and .so or .sa)
3/9/2012
Samia Riaz
11
Programming languages
Here's a partial list of programming languages available to the UNIX programmer:
3/9/2012
Samia Riaz
12
Linux Basics
Kernel Shell (BASH, CSH,KSH)
Shell is an command language interpreter that executes commands read from the standard input device $ echo $SHELL
Linux Shell
3/9/2012
Samia Riaz
13
pr {filename}
shutdown ps
3/9/2012
Samia Riaz
14
Pipes Pipe is used to connect the output of one program to the input of another program without any temporary file
15
Shell Scripting
3/9/2012
Samia Riaz
16
Filename Conventions
In UNIX, a file is the basic component for data storage.
UNIX considers everything it interacts with as a file, even attached devices such as monitors.
A file system is the UNIX systems way of organizing files on mass storage devices such as hard and floppy disks. Directory is merely a special type of file Some applications give the same name to all the output files they generate
3/9/2012
Samia Riaz
17
3/9/2012
Samia Riaz
18
3/9/2012
Samia Riaz
19
Links
a pointer to another file used like the file it points to similar to shortcuts in Windows, but better
Devices
access a device (like a soundcard, or mouse, or ...) like it is a file You can read and write the devices
3/9/2012 Samia Riaz 20
3/9/2012
Samia Riaz
21
/bin
binaries, or executables, which are the programs needed to start the system and perform other essential system tasks.
/dev
Files in /dev references system devices. They access system devices and resources such as hard disks, printers,
/etc
configuration files that the system uses when the computer starts, such as passwd (user info file), rc (scripts or directories of scripts)
3/9/2012
Samia Riaz
22
3/9/2012
Samia Riaz
23
Topic One
Listing files and directories Making Directories Changing to a different Directory The directories . and .. Pathnames
3/9/2012
Samia Riaz
24
3/9/2012
Samia Riaz
25
Making Directories
mkdir (make directory) mkdir dir_name
3/9/2012
Samia Riaz
26
3/9/2012
Samia Riaz
27
3/9/2012
Samia Riaz
28
Pathnames
pwd (print working directory) where you are in relation to the whole file-system pwd ~ (your home directory) To describe an object in the file system you specify a path. Paths are either absolute, starting with the root level:
/users/faculty/sarwar/courses/ee446
Or they are relative, staring with the current working directory or a users home directory
~/courses/ee446 ./courses/ee446
Exercise
ls ~ ? ls ~/.. ? What would be the out put?
3/9/2012 Samia Riaz 29
3/9/2012
Samia Riaz
30
Summary
ls
ls -a
mkdir cd directory cd cd ~ cd .. pwd
3/9/2012
Samia Riaz
31
Topic Two
Copying Files Moving Files Removing Files and directories Displaying the contents of a file on the screen Searching the contents of a file
3/9/2012
Samia Riaz
32
Copying Files
cp (copy) Syntax
cp file1 file2
cp [options] source target Common options: -i : interactive; prompts before overwriting an existing file -r : recursive; cp will copy the directory and all its files, including any subdirectories and their files to target Example cp goodies goodies.old
cp /vol/examples/tutorial/science.txt .
Exercise
Create a backup of your file1.txt file by copying it to a file called file1.bak
3/9/2012
Samia Riaz
33
Moving files
mv (move) Syntax
mv file1 file2
Examples
mv [-fi] source target_file
moves the file named by source to the destination specified by target_file.
Moving files
Examples: mv file1 file2
Rename the file named file1 in the current working directory to file2
mv file2 .. ?
3/9/2012
Samia Riaz
35
Exercise
Create a directory called tempstuff using mkdir , then remove it using the rmdir command
3/9/2012 Samia Riaz 36
3/9/2012
Samia Riaz
37
Filters
A filter is a command that takes data from standard in and performs some simple transformation on it, the result of which is sent on to standard out. Examples:
sort - sort standard in grep (and its derivatives) - search for keyword information head - send on only the front end tail - send on only the tail end wc - count words, lines, and/or characters crypt - encrypt standard in (use with caution!)
3/9/2012 Samia Riaz 38
Sort
sort (which does nothing more than sort a file)
Example: Sort B A C finally enter an EOF (<Ctrl> d) at which point the command will sort your input and output it to standard output.
3/9/2012
Samia Riaz
39
wc (word count)
wc -lwc myfile counts lines, words, and characters in the file. If any one of l, w, or c is omitted, that count is not provided.
3/9/2012
Samia Riaz
40
Head
head science.txt Then type $ head -5 science.txt What difference did the -5 do to the head command?
3/9/2012
Samia Riaz
41
Summary
cp file1 file2 mv file1 file2 rm file rmdir directory cat file more file
copy file1 and call it file2 move or rename file1 to file2 remove a file remove a directory display a file display a file a page at a time
head file
tail file grep 'keyword' file wc file
3/9/2012
Samia Riaz
42
Topic Three
Redirection Redirecting the Output Redirecting the Input Pipes Two commands can be executed from a single line; e.g.,
date; cal
3/9/2012
Samia Riaz
43
Redirection (Introduction)
standard output (terminal screen ) standard input (keyboard) standard error (by default, to the terminal screen) type
cat
abc
[Return] [Ctrl + d ]
Redirection
Redirection: is a means of instructing the shell to use something other than the default for standard input or standard output. The formats for standard in and standard out are:
<command> < <file-name>
for <command> to get its input from <file-name> rather than standard in.
3/9/2012
Samia Riaz
45
Eg
cat > topics
Copying Files Moving Files Removing Files and directories
^D (Control D to stop)
Eg
cat >> topics
Displaying the contents of a file on the screen Searching the contents of a file
^D (Control D to stop)
Exercise
use the cat command to join (concatenate) file1 and file2 into a new file (final.txt)
3/9/2012
Samia Riaz
46
Eg
sort
C A B
^D (Control D to stop)
Output will be
A B C
Exercise
Use sort to sort the contents of final.txt & redirect the output to a new file sorted.txt
3/9/2012
Samia Riaz
47
Pipes
Symbol used
vertical bar | <command-1> | <command-2> denote that standard out from <command-1> is to be piped <command-2> as standard in.
Eg
who (To see who is on the system with you ) How to get a sorted list of names?
Mehtod1
who > names.txt sort < names.txt
Exercise
Using pipes, print all lines of file1 and file2 containing the letter 'p', sort the result, and print to the printer.
3/9/2012 Samia Riaz 48
Summary
command > file command >> file command < file command1 | command2
cat file1 file2 > file0 sort who a2ps -Pprinter textfile lpr -Pprinter psfile
redirect standard output to a file append standard output to a file redirect standard input from a file pipe the output of command1 to the input of command2 concatenate file1 and file2 to file0 sort data list users currently logged in print text file to named printer print postscript file to named printer
Samia Riaz 49
3/9/2012
Topic Four
Wildcards Filename Conventions Getting Help Finding files Unix file times Generating calendar
3/9/2012
Samia Riaz
50
?
Will match exactly one character Eg
ls ?ouse will match files like house and mouse, but not grouse
[...] matches any one character between the braces; can use - to indicate arange of characters
Example: b[aei]t matches bat, bet, or bit, not baet Example: b[a-c]t matches bat, bbt, or bct, not bxt ls [abc]*.?
3/9/2012
Samia Riaz
51
Explanation:
3/9/2012
Samia Riaz
52
Getting Help
man wc whatis wc apropos keyword
3/9/2012
Samia Riaz
53
Finding files
find <path> <options> path is one or more directories in which find will begin to search Find will recursively search all sub-directories. options
name, perm, type, user, group, size, inum, atime, mtime, ctime, newer Many more
example: find all the *.c* and *.h* files in and below the current directory
find . name *.[ch]*
3/9/2012 Samia Riaz 54
Modification time
a change modifies the contents of the file
Note:
Reading a file updates its access time but not its change time or modification time These time attributes can also be used in the find command
3/9/2012 Samia Riaz 55
Generating calendar
Show a calendar for this month
cal
3/9/2012
Samia Riaz
56
Summary
*
man command
whatis command
apropos keyword
3/9/2012
Samia Riaz
57
Topic Five
File system security (access rights) Changing access rights Processes and Jobs Listing suspended and background processes Killing a process
3/9/2012
Samia Riaz
58
In the left-hand column is a 10 symbol string consisting of the symbols d, r, w, x, 1st d or The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of 3.
The left group of 3 gives the file permissions for the user that owns the file (or directory) (ee51ab in the above example); The middle group gives the permissions for the group of people to whom the file (or directory) belongs (beng95 in the above example); The rightmost group gives the permissions for all others.
3/9/2012 Samia Riaz 59
a file that everyone can read, write and execute (and delete). a file that only the owner can read and write - no-one else can read or write and no-one has execution rights (e.g. your mailbox file).
3/9/2012
Samia Riaz
61
o
a r w x + -
other
all read write (and delete) execute (and access directory) add permission take away permission
62
3/9/2012
Samia Riaz
More on chmod . . .
chmod ijk <name> sets permissions for
owner (i) group (j) all others (k)
where each of i, j, and k are octal digits (0-7). Viewed bitwise, 4 = read, 2 = write, 1 = execute. Since 7=4+2+1 E.g
chmod 700 <file-name> sets read, write, and execute permission for the file owner and for no one else
Suppose that you have a subdirectory named mywork in your current working directory. Then
chmod 700 mywork ????
3/9/2012 Samia Riaz 63
Background job:
runs concurrently with the parent shell and does not take control of the keyboard.
3/9/2012
Samia Riaz
64
3/9/2012
Samia Riaz
65
3/9/2012
Samia Riaz
66
Killing a process
kill (terminate or signal a process) kill a job running in the foreground
^C
ps (process status) to find out the PID then use it to kill a process
kill PID_number
3/9/2012
Samia Riaz
67
Summary
ls -lag chmod [options] file
list access rights for all files change access rights for named file run command in background kill the job running in the foreground suspend the job running in the foreground background the suspended job list current jobs foreground job number 1 kill job number 1 list current processes kill process number 26152
Samia Riaz 68
command &
^C ^Z bg jobs fg 1 kill 1 ps kill 26152
3/9/2012
Work to do
1. 2. Quota
Built in kernel utility that keeps you from exceeding values for disk space set by the Gurus who run your system how they are partitioned, how big they are, how much of that is used, and available disk usage expresses itself in Kbytes du -s to get a summary of all the files you own, underneath that point
df
3.
Du
4. 5. 6. 7. 8.
3/9/2012