system administration introduction to unix session 2 – fri 02 nov 2007
DESCRIPTION
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007. Reference: chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN 0-13-937681-X Albert Lingelbach, Jr. [email protected]. History of Unix. Begun in 1969 at Bell Labs - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/1.jpg)
System AdministrationIntroduction to Unix
Session 2 – Fri 02 Nov 2007 Reference:
chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN 0-13-937681-X
Albert Lingelbach, [email protected]
![Page 2: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/2.jpg)
History of Unix Begun in 1969 at Bell Labs
Timesharing / MultiuserOne computer, many terminals
Programming Typesetting Group Communication
![Page 3: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/3.jpg)
Architecture Kernel Windowing System
Gnome Shell Programs
![Page 4: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/4.jpg)
The shell environment tty (teletype) / terminal
text only 24 lines, 80 columns
default shell: Bourne shell to open a tty:
right-click on desktop, choose “Open Terminal” echo
print text to the tty try: echo Hello
what shell is running ?echo $0
![Page 5: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/5.jpg)
Simple commands bash
compatible with sh, added features: command history with up arrow editable command line backspace (vs. delete)
date system date and time
who what users are on the system
![Page 6: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/6.jpg)
Flow Control characters
ctrl-C stop a running command try: troff
ctrl-S / ctrl-Q pause/unpause output try: countdown 1000
end input ctrl-D
![Page 7: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/7.jpg)
Command Arguments / Parameters
mis-typed command gold: not found
command arguments / parameters try: who am i try: gold coins
![Page 8: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/8.jpg)
User Communication news
get local system news (written by the system administrator)
try: news write
write messages to another user on the system; like IM but local
try: pair off using who, find userid of your partner write userid
(and your partner does same)exchange messages
![Page 9: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/9.jpg)
Manual Pages You have seen the following commands:
date who news write sh bash
How to find more about them ? command -?
often returns a short command synopsis man command
returns the complete manual page reference for the command
![Page 10: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/10.jpg)
Files As in any computer system, data is stored in
files Most Unix files are (ASCII) text Many Unix commands manipulate text files
![Page 11: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/11.jpg)
File Naming case sensitive spaces are problematic dot and underscore are useful separators
![Page 12: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/12.jpg)
File Commands – 1 current (“working”) directory pwd
print the working directory ls
list the files in the working directory cd path
change the working directory
![Page 13: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/13.jpg)
File Paths 1
filenames without a path default to the current directory example: myfile.txt
/ is the root or top of the file system tree a file path contains directories
separated by “/”(not “\” as in DOS/windows) example: /home/export/staff/alingelb/file.txt
![Page 14: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/14.jpg)
File Paths 2 relative paths (not starting with “/”)
start at the current directory current directory (.) parent directory (..)
relative to any preceding directory examples:
./file.txt (the same as file.txt)
../../student/kate/file.txt in general, any command that takes a file as
an argument, will accept a path + file (path/file)
![Page 15: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/15.jpg)
File Commands - 2 touch filename
create an empty file example: touch myfile.txt
rm filename delete a file (forever – be careful!) example: rm myfile.txt
cp original_file new_file copy a file example: cp myfile.txt copy_of_myfile.txt
![Page 16: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/16.jpg)
File Commands - 3 mv original_file new_filename mv original_file new_location
new_location must already exist file keeps same name
mv original_file new_location/new_filename move a file examples: mv myfile.txt newname.txtmv myfile.txt ..mv myfile.txt /usr/bin/students.txt
![Page 17: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/17.jpg)
File Commands - 4 cat file cat file1 file2 ...
display the contents of the file(s) on the screen more file
display the contents of the file on the screen, on screenful at a time (press space for the next screen, return to advance one line)
gedit file edit the file in the gnome graphical editor
![Page 18: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/18.jpg)
Directory Commands
mkdir dirname mkdir path/dirname
create the directory rmdir dirname
remove the directory (it must be empty)
![Page 19: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/19.jpg)
Shell filename wildcards 1 it can be useful to match filenames by
pattern: * matches any set of characters (or no
characters) ? matches one character
examples: *file*
matches any filename containing “file” *.txt
matches any filename that ends in “.txt” this*
matches any filename that starts with “this”
![Page 20: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/20.jpg)
Shell filename 2 wildcards More examples:
Sample file names
pattern file1.txt file10.txt file.txt file.tmp.txt file.bmp oldfile.txtfile*.txt * = 1 * = 10 * = [nothing] * = .tmp no match no matchfile?.txt ? = 1 no match no match no match no match no match*file.txt no match no match no match no match no match * = old
![Page 21: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/21.jpg)
Shell filename wildcards 3 More examples:
cat chapter*.txtwill output to the screen all files that start in chapter and end in .txt
ls *.txtwill list all files that end in .txt
mv *.txt /export/home/alingelbwill move all files ending in .txt to the directory /export/home/alingelb
![Page 22: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/22.jpg)
More useful (text) file commands 1
grep pattern filesearch for the pattern in the file, and output the line(s) containing the pattern
sort filesort the lines of the file in alphabetical order
head filedisplay the first 10 lines of the file
![Page 23: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/23.jpg)
More useful (text) file commands 2
tail filedisplay the last 10 lines of the file
wc filecount the number of lines, words, and characters in the file
diff file1 file2display the differences between the two files
![Page 24: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/24.jpg)
File permissions 1 Every file has read, write, and execute
permissions (RWX) These are set by the owner, for the owner,
the group, and everyone else; so there are 9 permissions total (plus a few special ones to be discussed later).
![Page 25: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/25.jpg)
File permissions 2 ls -l
will display file permissions, along with the group and owner example:
$ ls -ltotal 3-rwxr-xr-x 2 alingelb staff 512 Nov 2 10:38 Desktopdrwxr-xr-x 3 alingelb staff 512 Oct 16 11:15 Documents-rw------- 1 alingelb staff 40 Nov 2 12:13 foonly.txt
![Page 26: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/26.jpg)
File permissions 3 chmod ### file
is used to change file permissions the first # is owner permissions the second # is group permissions the third # is everyone else permissions the # is composed of
(add the numbers): 4 for read 2 for write 1 for execute
![Page 27: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/27.jpg)
File permissions 4 chmod example:
chmod 744 file sets owner to read/write/execute sets group to read sets everyone else to read
![Page 28: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/28.jpg)
Shell theory The shell is a command interpreter It interfaces between the user and programs
and the kernel It has its own syntax In addition to providing access to programs
and to the kernel, the shell has some powerful features of its own, including wildcards I/O redirection scripting
![Page 29: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/29.jpg)
I/O management 1 Every process has 3 channels of information:
“standard” input “standard” output error output
These can be controlled by the shell: command > file
sends the standard output of the command to a file command < file
sends the contents of a file to the standard input of the command
command >> file appends the standard output of the command to the
end of a file
![Page 30: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/30.jpg)
std I/O management Examples
ls > listing.txt echo “this is a test” > test.txt echo “the test continues” >> test.txt echo “6 + 6” > math.txt bc < math.txt
![Page 31: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/31.jpg)
more I/O management More I/O redirection
There is a special empty file/dev/null
it discards all output command 2> /dev/null
discards all error output example:touch testfilechmod 000 testfilecat testfile 2> /dev/null
command1 | command2 send the output of command1 as the input of
command 2 example: ls | wc
![Page 32: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/32.jpg)
I/O management: pipe Advanced example of pipe
wanted: list of users on system. build it incrementally using pipe.
who gives list of users, but there are duplicates (because user appears once for each session);also, who gives too much information
using cut to remove extraneous information:who | cut -d\ -f1gives list of users, still with duplicates
who | cut -d\ -f1 | sortsorts list, putting duplicates together
who | cut -d\ -f1 | sort | uniqremoves duplicates; this is the desired list
![Page 33: System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007](https://reader035.vdocuments.mx/reader035/viewer/2022062810/56815e03550346895dcc4b62/html5/thumbnails/33.jpg)
Review Concepts
Unix history, multiuser/timesharing, kernel, shell, man pages, file permissions
Flow control ctrl-C, ctrl-S, ctrl-Q, ctrl-D
Commands: echo, bash, date, who, pwd, ls, cd, touch, rm, cp,
mv, cat, more, gedit, mkdir, rmdir, grep, sort, head, tail, wc, diff, chmod, bc
File paths & wildcards *, ?
I/O management >, >>, <, |, 2>