Ch01 - Parent Directory

Download Report

Transcript Ch01 - Parent Directory

PRIME VIEW, INC.
1
Useful links for this course.
History:
http://www.paralogos.com/DeadSuper/
http://www.computer50.org/mark1/photogallery.html
http://perso.wanadoo.fr/levenez/unix/
UNIX:
http://www.arch.su.edu.au/~doug/Unixhelp/DOStoUNIX_.html == DOS to UNIX, basic commands
http://www.itknowledge.com/reference/standard/0672315238/ewtoc.html == Sam's UNIX in 10 min.
http://www.isu.edu/departments/comcom/unix/workshop/unixindex.html - Idaho State Univ. Tutorial
http://wks.uts.ohio-state.edu/unix_course/ Ohio Univ. Course; book and slides
http://theory.uwinnipeg.ca/UNIXhelp/ == UNIXhelp from Univercity of Edinburg (can DOWNLOAD)
http://www.ugu.com/ == UNIX Guru Universe
http://www.ugu.com/sui/ugu/show?help.beginners -- Start here, check "Basics", "Fundamentals"
http://riceinfo.rice.edu/Computer/Documents/Unix/unix1.01.pdf -- Get reference card
http://riceinfo.rice.edu/Computer/Documents/Unix/unix1.pdf -- Get nicely formatted doc on basics
http://riceinfo.rice.edu/Computer/Documents/Unix/unix18.pdf -- UNIX scripts (csh, sh 15 pages each)
http://goforit.unk.edu/unix/part1_0.htm -- Learning UNIX by Brian Brown (Advanced): Acessments, Notes, TESTS)
http://www.usenix.org/sage/sysadmins/sysadmins.html -- Sysadmins site
http://www.uwsg.indiana.edu/usail/ -- Basic UNIX Tutorial used by many univercities (14 chapters)
http://www.oase-shareware.org/shell/index.html --- SHELLdorado = Scripts, scripts, scripts.
http://www.unixguide.net/ -- UnixGuide
http://www.elementkjournals.com/sun/ -- Inside Solaris
PRIME VIEW, INC.
2
Tests:
http://Brainbench.com/xml/bb/homepage.xml
http://www.uwsg.indiana.edu/usail/test/
http://www.smartcertify.net/default.asp?article=eb5 --> try UNIX and Network+ sections
Free shell access:
http://www.nether.net
http://www.shellyeah.org
UWIN ksh emulator for Windows:
http://www.research.att.com/sw/tools/ and
http://www.research.att.com/cgi-bin/access.cgi/as/vt/ext-software/www-ne-license-new.cgi?table.uwin_research.binary
get the file uwin_base_win32_i386.exe (8.8MB)
Or try http://sources.redhat.com/cygwin/ for Cygwin
PRIME VIEW, INC.
3
Chapter Objectives
In this chapter, you will learn about:
•Why and how UNIX is used in production environment
•Brief (very brief) history of UNIX
•What is UNIX and what are its main parts
•kernel
•configuration files
•shell
•utilities
•Different types of connection to UNIX host
•Login process
•Setting password
•Using UNIX commands
•Getting help on the system (man pages)
•Managing files and directories (ls, cd, mkdir,rmdir, rm, more, head, tail)
PRIME VIEW, INC.
4
Introduction. Why UNIX.
UNIX as one of the main tools to run daily business tasks.
- mainframe (MVS,COBOL, CICS, etc.)
- proprietary network, hardware, software (IBM)
- expensive
- reliable
- mid-range (mainly UNIX servers)
- many vendors (HP, Sun, IBM, Compaq, SGI…)
- “open” system (including source - BSD, Linux, Solaris 8 )
- Open network (TCP/IP). Internet.
- Less expensive but less reliable
- Windows and UNIX workstations and Terminals
- Cannot use server resources easily from Win workstation except for file
sharing. Not a problem in UNIX environment.
PRIME VIEW, INC.
5
Types of UNIX users:
UNIX sa (System Administrator). Some of the functions:
• Build the system (install the unix)
• Add new users
• Tune the system (hardware, software, performance)
Unix software developers
• Create new applications, modify existing
• C, C++, Java, perl, shell - programming
• Working mostly in UNIX environment
Unix users
• Working mostly in Windows (NT) environments
• VB, C, C++, Powerbuilder, Oracle Tools, etc.
• Using UNIX occasionally but NEED to KNOW
PRIME VIEW, INC.
6
Typical organizational structure of running business (IT view):
• Business lines
- define the business requirements
- sell the products, make money
• Application development
- map the business requirements to applications
- program development
- define production requirements
• Production support
- run the application (7X24)
- tune the system, administer Data Servers
• Data Center
- run computers, networks, do data entry
PRIME VIEW, INC.
7
Typical Production Cycles:
• Daily
- ON LINE transactions during the day
- nightly (batch) processing
- daily/nightly maintenance jobs (backup,error scan)
- cleanup, purge, archive
• Weekly, Monthly, Yearly cycles
- mostly batch jobs
- high volumes of data
- CPU requirements
- long term archiving
PRIME VIEW, INC.
8
UNIX: Getting Started
PRIME VIEW, INC.
9
History, a brief overview
•
•
•
•
•
•
•
•
written by Ken Thompson and Dennis Ritchie (Turing Award 1983)
developed at Bell Laboratories, USA, derived from multics (1969)
Thompson developed a new programming language 'B'
Ritchie enhanced 'B' to 'C' and helped develop 'UNIX'
Ran on DEC PDP-7
Two flavors,
SYSTEM V (Commercial, run by AT&T) and
BSD (Educational, run by Bell Labs)
Recent developments are graphical interfaces, MOTIF, X Windows, Open View
Major suppliers today
Sun Microsystems (SPARC)
Data General (AVION)
IBM (RS6000 AIX)
Hewlett Packard
Santa Cruz Organisation (SCO)
DEC
A free UNIX system called LINUX is also available for download from the Internet or
available on CD-ROM. More of UNIX history - see appendix.
PRIME VIEW, INC.
10
What is UNIX
UNIX is a multi-user multi-tasking multi-threaded highly portable time-sharing
networked operating system utilizing shared memory. The job of an operating system is
to orchestrate the various parts of the computer -- the processor, the on-board memory, the
disk drives, keyboards, video monitors, to perform useful tasks.
Main features:
• multi-user
more than one user can use the machine at a time
supported via terminals (serial or network connection)
• multi-tasking, more than one program can be run at a time
• hierarchical directory structure, to support the organisation and maintenance of files
• portability
only the kernel ( <10%) written in assembler. This meant the operating system
could be easily converted to run on different hardware platforms ranging from
PCs and Macs to Cray supercomputers
• tools for program development, a wide range of support tools (debuggers, compilers)
The philosophy behind the design of UNIX was to provide simple, yet powerful utilities
that could be pieced together in a flexible manner to perform a wide variety of tasks. The
UNIX operating system comprises three parts: The kernel, the shell and the standard
utility programs, and the system configuration files.
PRIME VIEW, INC.
11
Kernel
schedules programs
manages data/file access and storage
enforces security mechanisms
performs all hardware access
Today you can find several flavors of the UNIX operating system (also known as the
"kernel").
AT&T's original version evolved into System V (pronounced "system five").
The version that AT&T licensed to the University of California at Berkeley is called BSD
(Berkeley Software Distribution). It is now the de facto standard in the academic
community, (i.e., it's free).
Other versions are also available from commercial vendors: Sun's Solaris, SCO and
Microsoft's XENIX, IBM's AIX, DEC's ULTRIX, Apple's A/UX, and the free Intel-based
Linux. Kernel executable file is usually named unix (System V origin) or vmunix (BSD
origin).
Configuration files
The system configuration files are read by the kernel, and some of the standard utilities.
The UNIX kernel and the utilities are flexible programs, and certain aspects of their
behavior can be controlled by changing the standard configuration files. One example of
a system configuration file is the filesystem table "fstab" , which tells the kernel where to
find all the files on the disk drives. PRIME VIEW, INC.
12
Shell
Users rarely use UNIX directly, however. The utility
software that interprets a user's commands for the kernel is
called the shell. Here too, there are several flavors.
The original and most common shell is the Bourne shell (its
prompt is the "$").
The C shell ("%" or "") is newer and provides an extensive
command language similar to the C programming language.
The Korn shell (also "$") attempts to combine the best of
both earlier shells.
More than one shell is often available to users on a UNIX
system.
Utilities
file management (rm, cat, ls, rmdir, mkdir)
user management (passwd, chmod, chgrp)
process management (kill, ps)
printing (lp, troff, lpr)
program development tools
PRIME VIEW, INC.
13
Logging In
There are three main ways to connect to UNIX machine (node)
- direct terminal connection
- network terminal connection using dumb or X-terminal
- network terminal connection using a “smart” terminal (PC)
Terminal Emulator - a program running on your PC and representing it to UNIX server
as a terminal of known type. In our case we have NT application called “Reflections”
Once you are connected, UNIX will prompt you for your login name. Type your unique
userid (student1, student2, student3,... student0) assigned to you. At the password
prompt, type your password - all users have the same password: "nyc123". (Your
password will not be printed on the screen.)
Try different types of connection:
- telnet (windows standard tool in accessories)
- Reflection/telnet
- Reflection X11
- telnet from unix prompt
- ftp
Use "ps" command and "who" command to find out about connections.
PRIME VIEW, INC.
14
TTY
TTY
ftp
Reflections
Network
NT
UNIX machine
(Server)
Personal Computers
NT
telnet
Exceed
PRIME VIEW, INC.
15
Setting Passwords
If you are using a temporary password, you should change it immediately. It is also a good
idea to change your password periodically. Unlike your login name which may be known
by many people, only you should know your password. Make your password 6 to 8
characters long. Make it hard to break by combining capital letters, lowercase letters, and
punctuation. Avoid using family names, pet names, words found in dictionaries, birth
dates, anniversary dates, and obvious numbers (drivers license, license plate, phone). Do
not use common words, even if you add a number to the password (e.g., Gandalf, red3,
scottX, etc.).
Changing Your Password
To change your password, type: passwd. UNIX will prompt you for your old password, then your
new password. UNIX will then ask you to retype the new password to confirm it. Once you've
confirmed it, your new password will be in effect. Use it the next time you log in.
PRIME VIEW, INC.
16
Using UNIX Commands
UNIX commands follow the format:
command -flags arguments.
The commands are one-word, lower case. Optional flags are one-letter switches that
modify the way the command works. They follow the dash, are case-sensitive, and can
be combined. The optional argument usually specifies the file or directory that is the
target of the command's action. Hit RETURN after entering a command.
Getting Help (the Unix manual pages)
UNIX provides an online manual. To use it, enter man followed by the command for
which you need help.
For example, type man passwd to get help on the passwd command.
If you are unsure of the name of a command, you can use the -k flag to search the man
pages for a string. For instance, man - k print will get you a list of commands relating
to printing.
Hiiting RETURN adds one line. To show the next page - hit "space bar"
To quit from man utility type "q” (Linux) or CTRL-C (Solaris).
Try to get help on the following commands:
pwd, ls, cd, cat, cp, mv, echo, ps, head, tail
PRIME VIEW, INC.
17
Managing Files and Directories
UNIX files are organized in a hierarchy structured like an upside down tree. The top is the root
(written "/"). Beneath the root are files and directories. Files are of two types: data files (e.g., a
letter to your mother) and program files (e.g., the text editor you used to create a letter to your
mother). Directories are just like subdirectories on the PC or folders on the Mac, and may contain
files and other directories. Unlike PC or Mac users, you do not need to care what drives are
where. In UNIX, they appear simply as directories located anywhere in the file system.
Names
File and directory names can be up to 256 characters long!
They may contain upper and lower case letters, numbers, and punctuation.
Avoid using spaces, "" or "!" (these symbols make files difficult to manipulate).
Remember that case does make a difference, i.e., the name "Memo" refers to a different
file than "memo".
You can use the underscore (_) or the period (.) to separate words in a file name, for
example: vacation_memo. Extensions (.c, .txt, .dat) may be required by some utilities
(e.g., the C compiler), but are not required in general. In most cases you will see no
extentions.
PRIME VIEW, INC.
18
The full name for any file is the complete or absolute path to it, starting at the root, which
means you must include directory names.
The absolute path name for the file "memo" in the directory "john" that is within the
directory "users" which is under the root would be: /users/john/memo, (remember, the first
"/" is the directory root). You can also refer to files using their relative path, meaning
relative to your current position in directory hierarchy. For example, if you are in directory
/users/ann, then you can refer to file /users/john/memo as ../john/memo. “..” in UNIX (as
in DOS) denote parent directory to yours.
Try commands
pwd
ls
ls ../teach
While "." is a valid character, placing it as the first character in a name is not
recommended. Any file name that begins with a '.' is considered an "invisible" file, and
will not show up when you run the standard list files command (ls). Methods of seeing
these files are discussed later on.
Filenames containing metacharacters (like * or ? ) are legal, but hard to work with
PRIME VIEW, INC.
19
Change Directory
When you log on to UNIX, your present working directory is automatically set to your home
directory. To move to another directory, use the cd command followed by the name of that directory.
You can also use shortcuts for a directory name, i.e., type cd .. to move to the directory above your
current one. (Note: UNIX, unlike DOS, requires a space between the cd and the ..).
You can jump back to your home directory from anywhere in the directory tree by typing cd and
hitting RETURN.
Try the commands:
pwd
echo $HOME
ls –l
cd <dir name>
pwd
cd ..
pwd
cd <dir name>
pwd
cd
pwd
cd /usr
cd /
(determine which are directories)
PRIME VIEW, INC.
20
Present Directory
Use the pwd command to list the name of your present working directory.
You may refer to any files in your present directory without using their full path
names, provided that you set up your configuration files accordingly or system
administrator did it for you. Unlike your home computer, you will not have a UNIX
account that begins at the root directory. Most UNIX platforms have many users, and
each user has a small slice of the available hard drive space. Thus, instead of starting
out at the root of the drive, most user accounts will be somewhere down in the
directory tree, (usually off of a /home or /usr directory).
Try the command:
cat
/etc/passwd
One of the fields in this configuration file will setup home directory for your account.
PRIME VIEW, INC.
21
List Directory Contents
To list the normal files and subdirectories within your current working directory, use
the ls command. To list the files in another directory, such as "/users", include the
directory name in the command: ls /users. This command will list all files and
subdirectories (except "invisible files"--see below) in the directory you specify.
As mentioned earlier, adding flags to a UNIX command allows you to alter the
commands actions. Adding flags to the ls command alters how the directory is listed.
The command ls -a lists all files and subdirectories in the directory, including "invisible
files" (any file whose name begins with a period ".").
Typing ls -F puts a "/" at the end of directories in the listing and an "*" at the end of a
program (executable) file. This allows you to tell at a glance whether the item is a file,
a program, or another directory.
Typing ls -l displays a long list of directory contents and file attributes.
Try the command:
ls -al
PRIME VIEW, INC.
22
The output should look similar to this:
total 6
-rwxr-xr-x
drwxr-xr-x
drwxr-xr-x
-rw-r--r--rw-r--r--rw-r--r-lrwxr-xr-x
1
2
2
1
1
1
1
peterl
peterl
peterl
peterl
peterl
peterl
peterl
group1
group1
group1
group1
group1
group1
group1
441
96
96
0
805
805
10
Mar
Apr
Apr
Apr
Dec
Dec
Apr
15
15
15
15
16
16
15
15:16
16:15
16:15
16:15
14:54
14:55
16:16
a
bin
local
mdir.txt
rcp.sh
rcp2.sh
mlink1 -> ./mdir.txt
Long Listing Information
· The “total” shows the total number of disk blocks used
- Block size is system dependent: May be 512, 1024, 2048, … bytes
· In subsequent lines each line gives:
- The leftmost 10 characters give the file type and access permissions
- Number of links (number of names for the file)
- User (owner) name
- Group name (System V default; need ls -lg in BSD)
- Size in bytes
- Modification date and time (or year, if old)
- File name
PRIME VIEW, INC.
23
File Types
· First character is file type
d
l
m
b
c
p
s
- regular file
- Directory
- Symbolic link
- XENIX shared memory
- Block special (device) file
- Character special (device) file
- Named pipe (FIFO)
- BSD socket or XENIX semaphore
- Most files are regular files
- Contain text, binary data, or binary programs
· Symbolic link files "point to" other files
- ls -l shows the file pointed to, which need not exist!
· Directory files contain information about other files
PRIME VIEW, INC.
24
File Access Permission
· Following the type are three sets of three characters giving the access
permission (or mode) for
- User who owns the file
- Group members in the file's group
- Other users
-rw-r--r-· In each set of three characters
r
- Read permission
w
- Write permission
x
- Execute (or search) permission
· Symbolic links always have all permissions
- Permissions the "pointed to" files are what matter
PRIME VIEW, INC.
25
Viewing Files
To display the contents of a text file, use the more command followed by the file name.
more displays your file one screen at a time, and then pauses.
Hit RETURN to advance one line or the SPACEBAR to display the next screen.
To exit more, enter the letter q.
Another command to display the contents of the text file(s) is cat file1.txt file2.txt.
You can display part of the file in the beginning or at the end using head or tail command.
Both commands will default to 10 lines display if you do not provide any switches.
Otherwise you can specify number of lines to display like this:
head -20 myfile
tail -30 myfile
“+” sign before the option will make tail work like head, counting from the beginning of
the file. So,
head -15 myfile
tail +15 myfile
will display the same 15 lines.
One more very useful option for tail is “-f” (follow) switch (end with Ctrl-C). This way
you can watch the file as it grows. For example,
tail -f my_log_file.log
PRIME VIEW, INC.
26
Create/Delete Directory
To create a new directory, just use the mkdir command with the new directory's name.
To create "my_new_dir", type mkdir my_new_dir.
You can create several subdirectories at once if you use -p switch to mkdir command.
Check man pages on it and try this command.
To remove the directory you just created, type rmdir my_new_dir. (Directories must be
empty before you can delete them with the rmdir command.) If you need to remove one
or more non-empty subdirectories, use rm command with -r switch. Check man pages
for its use and try this command.
Create/Delete File
Files are created as a by-product of running a program, exporting a mail message, or
using an editor.
Example. Try to create file using commands:
touch example_file_0_bytes
echo “We will learn redirection later” > echo_file
cat >cat_file
This is one more redirection example
CTRL-D
Files can be deleted with the rm command, (for instance, typing rm old_memo deletes
the file "old_memo"). Remove files you just created (check the directory listing first).
PRIME VIEW, INC.
27
Stopping and Restarting a Process (aka Multi-tasking)
A <CNTL>- c is often used to abort a command or program execution.
Another approach is to shift the program or command to the background (this
simply means the process moves out of your way, is saved where you left off,
and leaves the account free to do other things -- often called multi-tasking in
PC environments).
To do this, hit a <CNTL>-z.
This will stop the process and allow you to execute another process (i.e., a
program or command).
To retrieve the halted process, type in the command ps. This will show you a
list of your processes, as well as the Process Identification Number associated
with them.
To bring a particular process back to life, type in this command:
fg processID#. (Note: if there is only one backgrounded process, you do not
have to include the PID#).
PRIME VIEW, INC.
28
Logging Out
Different UNIX machines use different words to
log out of an account. Among the most popular
are exit, logout or <CNTL>- d. In UNIX, a
<CNTL>- d (or EOF) is often used to end an
activity normally.
PRIME VIEW, INC.
29
Summary of Basic UNIX Commands
Below is a reference list of the UNIX commands you will use most often and that are necessary for a
basic use of UNIX.
command -flag(s) argument(s)
ls (list)
ls
ls -l
ls -al
provides a directory listing.
lists a directory in columns
gives a fuller listing including file permissions,
size, date created
similar to the above but includes "dot"/hidden files
cd
cd
cd
cd
cd
returns you to the home directory
moves up one directory level
moves up two directory levels
moves to named subdirectory
(change directory)
..
../..
subdirectory
mkdir (make directory)
mkdir subdirectory
creates a directory within the current directory
rmdir (remove directory)
rmdir subdirectory
deletes directory within the current directory (if
directory is empty)
PRIME VIEW, INC.
30
cp
cp
cp
cp
(copy)
file1 file2
file1 directory
file1 file2 directory
copies file1 to file 2
copies file 1 to named directory
copies file1 and file2 to named directory
mv
mv
mv
mv
mv
(move)
file1 newname
directory newname
file1 directory
file1 directory/newname
moves or renames one or more files.
renames file1
renames directory
moves file to named directory
moves file1 to named directory and renames
rm (remove)
rm filename
rm -i filename
deletes files*
deletes the named file
deletes named file after prompting to make
sure you wish to remove it
*BE EXTREMELY CAREFUL with rm and never use rm* ! here is no undelete command!
PRIME VIEW, INC.
31
man (manual)
man command
displays help or manual documentation.
displays manual information for the
specified command
man -k keyword
displays 1 line synopsis of each manual
section referring to the keyword
more
more filename
lists files one screen at a time.
scrolls forward through file one screen at a time.
pwd (print working directory)
pwd
displays path name of current directory.
displays your current directory
echo
ps
ps -ef
prints its arguments on the screen
process list; lists this account’s processes
lists all processes on the host
rm
rm -r
deletes (removes) files
recursive remove, can delete files and directory
>
redirection
PRIME VIEW, INC.
32
To ...
Short reference DOS to UNIX
DOS
display list of files
display contents of file
display file with pauses
copy file
find string in file
compare files
rename file
delete file
delete directory
change file protection
create directory
change working directory
get help
display date and time
display free disk space
print file
dir/w dir
dir
type
type filename | more
copy
find
comp
rename OR ren
erase OR del
rmdir OR rd
attrib
mkdir OR md
chdir OR cd
help
date, time
chkdsk
print
PRIME VIEW, INC.
UNIX
ls
ls -l
cat
more
cp
grep, fgrep
diff
mv
rm
rmdir
chmod
mkdir
cd
man
date
df
lpr
33