33
PRIME VIEW, INC. 1

Chapter 1 First Steps

  • Upload
    manton

  • View
    31

  • Download
    2

Embed Size (px)

DESCRIPTION

Chapter 1 First Steps. 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 - PowerPoint PPT Presentation

Citation preview

Page 1: Chapter 1 First Steps

PRIME VIEW, INC. 1

Page 2: Chapter 1 First Steps

PRIME VIEW, INC. 2

Useful links for this course.

History:http://www.paralogos.com/DeadSuper/http://www.computer50.org/mark1/photogallery.htmlhttp://perso.wanadoo.fr/levenez/unix/

UNIX:http://www.arch.su.edu.au/~doug/Unixhelp/DOStoUNIX_.html == DOS to UNIX, basic commandshttp://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. Tutorialhttp://wks.uts.ohio-state.edu/unix_course/ Ohio Univ. Course; book and slideshttp://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 cardhttp://riceinfo.rice.edu/Computer/Documents/Unix/unix1.pdf -- Get nicely formatted doc on basicshttp://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 sitehttp://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/ -- UnixGuidehttp://www.elementkjournals.com/sun/ -- Inside Solaris

Page 3: Chapter 1 First Steps

PRIME VIEW, INC. 3

Tests:http://Brainbench.com/xml/bb/homepage.xmlhttp://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.nethttp://www.shellyeah.org

UWIN ksh emulator for Windows:http://www.research.att.com/sw/tools/ andhttp://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

Page 4: Chapter 1 First Steps

PRIME VIEW, INC. 4

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)

Page 5: Chapter 1 First Steps

PRIME VIEW, INC. 5

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.

Page 6: Chapter 1 First Steps

PRIME VIEW, INC. 6

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

Page 7: Chapter 1 First Steps

PRIME VIEW, INC. 7

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

Page 8: Chapter 1 First Steps

PRIME VIEW, INC. 8

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

Page 9: Chapter 1 First Steps

PRIME VIEW, INC. 9

UNIX: Getting Started

Page 10: Chapter 1 First Steps

PRIME VIEW, INC. 10

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.

Page 11: Chapter 1 First Steps

PRIME VIEW, INC. 11

What is UNIXUNIX 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.

Page 12: Chapter 1 First Steps

PRIME VIEW, INC. 12

Kernelschedules programsmanages data/file access and storageenforces security mechanismsperforms 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.

Page 13: Chapter 1 First Steps

PRIME VIEW, INC. 13

ShellUsers 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

Page 14: Chapter 1 First Steps

PRIME VIEW, INC. 14

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.

Page 15: Chapter 1 First Steps

PRIME VIEW, INC. 15

UNIX machine(Server)

Netw

ork

TTY

TTY

Personal Computers

Reflections

Exceed

NT

NT

ftp

telnet

Page 16: Chapter 1 First Steps

PRIME VIEW, INC. 16

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.

Page 17: Chapter 1 First Steps

PRIME VIEW, INC. 17

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

Page 18: Chapter 1 First Steps

PRIME VIEW, INC. 18

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.

Page 19: Chapter 1 First Steps

PRIME VIEW, INC. 19

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 commandspwdlsls ../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

Page 20: Chapter 1 First Steps

PRIME VIEW, INC. 20

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 (determine which are directories) cd <dir name> pwd cd .. pwd cd <dir name> pwd cd pwd cd /usr cd /

Page 21: Chapter 1 First Steps

PRIME VIEW, INC. 21

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.

Page 22: Chapter 1 First Steps

PRIME VIEW, INC. 22

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

  

Page 23: Chapter 1 First Steps

PRIME VIEW, INC. 23

The output should look similar to this: total 6-rwxr-xr-x 1 peterl group1 441 Mar 15 15:16 adrwxr-xr-x 2 peterl group1 96 Apr 15 16:15 bindrwxr-xr-x 2 peterl group1 96 Apr 15 16:15 local-rw-r--r-- 1 peterl group1 0 Apr 15 16:15 mdir.txt-rw-r--r-- 1 peterl group1 805 Dec 16 14:54 rcp.sh-rw-r--r-- 1 peterl group1 805 Dec 16 14:55 rcp2.shlrwxr-xr-x 1 peterl group1 10 Apr 15 16:16 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

Page 24: Chapter 1 First Steps

PRIME VIEW, INC. 24

File Types

· First character is file type

- - regular filed - Directoryl - Symbolic linkm - XENIX shared memoryb - Block special (device) filec - Character special (device) filep - Named pipe (FIFO)s - 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

Page 25: Chapter 1 First Steps

PRIME VIEW, INC. 25

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 charactersr - Read permissionw - Write permissionx - Execute (or search) permission

· Symbolic links always have all permissions- Permissions the "pointed to" files are what matter

Page 26: Chapter 1 First Steps

PRIME VIEW, INC. 26

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 myfiletail -30 myfile

“+” sign before the option will make tail work like head, counting from the beginning of the file. So,

head -15 myfiletail +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

Page 27: Chapter 1 First Steps

PRIME VIEW, INC. 27

Create/Delete DirectoryTo 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 FileFiles 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_bytesecho “We will learn redirection later” > echo_filecat >cat_fileThis is one more redirection exampleCTRL-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).

Page 28: Chapter 1 First Steps

PRIME VIEW, INC. 28

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#).

Page 29: Chapter 1 First Steps

PRIME VIEW, INC. 29

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.

Page 30: Chapter 1 First Steps

PRIME VIEW, INC. 30

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) provides a directory listing. ls         lists a directory in columns ls -l     gives a fuller listing including file permissions,

size, date createdls -al    similar to the above but includes "dot"/hidden files

cd (change directory) cd returns you to the home directorycd .. moves up one directory levelcd ../.. moves up two directory levelscd subdirectory moves to named 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)

Page 31: Chapter 1 First Steps

PRIME VIEW, INC. 31

cp (copy) cp file1 file2 copies file1 to file 2cp file1 directory             copies file 1 to named directorycp file1 file2 directory       copies file1 and file2 to named directory

mv (move) moves or renames one or more files. mv file1 newname                renames file1mv directory newname       renames directorymv file1 directory              moves file to named directorymv file1 directory/newname moves file1 to named directory and renames

rm (remove) deletes files* rm filename        deletes the named filerm -i filename     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!

Page 32: Chapter 1 First Steps

PRIME VIEW, INC. 32

man (manual) displays help or manual documentation. man command displays manual information for the

specified command

man -k keyword displays 1 line synopsis of each manual section referring to the keyword

more lists files one screen at a time. more filename scrolls forward through file one screen at a time.

pwd (print working directory) displays path name of current directory. pwd                         displays your current directory

echo prints its arguments on the screenps process list; lists this account’s processesps -ef lists all processes on the host

rm deletes (removes) filesrm -r recursive remove, can delete files and directory

> redirection

Page 33: Chapter 1 First Steps

PRIME VIEW, INC. 33

Short reference DOS to UNIXTo ... DOS UNIX

display list of files dir/w dir ls dir ls -ldisplay contents of file type catdisplay file with pauses type filename | more morecopy file copy cpfind string in file find grep, fgrep compare files comp

diffrename file rename OR ren mvdelete file erase OR del rmdelete directory rmdir OR rd rmdirchange file protection attrib chmodcreate directory mkdir OR md mkdirchange working directory chdir OR cd cdget help help mandisplay date and time date, time datedisplay free disk space chkdsk dfprint file print lpr