basic unix © mcgraw hill 2000. all rights reserved

22
Basic UNIX © McGraw Hill 2000. All rights reserved.

Upload: clinton-miles

Post on 23-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Basic UNIX © McGraw Hill 2000. All rights reserved

Basic UNIX

© McGraw Hill 2000. All rights reserved.

Page 2: Basic UNIX © McGraw Hill 2000. All rights reserved

Introduction

UNIX is an operating system UNIX has 3 main parts:

Kernel - manages hardware resources like terminals and printers

File System - accesses files; tree structured Shell - interacts with users

UNIX is interactive UNIX is multi-tasking UNIX is multi-user

Page 3: Basic UNIX © McGraw Hill 2000. All rights reserved

System Prompt % or $ or computername> System prompt indicates that system is

waiting for a command Enter commands at the prompt:

%pine %menu %date %who %help %whoami %cal %cal arg (arg = year) %man arg (arg = command name)

Note: UNIX commands are case sensitive!

Page 4: Basic UNIX © McGraw Hill 2000. All rights reserved

File System

File is a container for data

3 kinds of files:

Directories (like folders) Container for files and other directories

Sub-directory is a directory contained within another

directory

Ordinary files

Special files

Page 5: Basic UNIX © McGraw Hill 2000. All rights reserved

File Structure

Directories and files are organized in a tree-like hierarchy

Directory at the top is known as the root directory and is represented as a /

Some standard subdirectories under the root directory are etc, usr, and tmp

Page 6: Basic UNIX © McGraw Hill 2000. All rights reserved

UNIX Tree-like Hierarchy

/

mnt n bin tmp_mnt

m

00 37 39

jrp hdb ehepp

root

Full pathname:

/n/m/37/ehepp

Page 7: Basic UNIX © McGraw Hill 2000. All rights reserved

Home Directory

“Home” directory is where you find yourself when you log in

To print the name of the directory you are in: %pwd (print working directory)

Shows the “full pathname” eg. /n/m/37/ehepp

Page 8: Basic UNIX © McGraw Hill 2000. All rights reserved

Pathnames

A pathname is the concatenation of the directories you traverse to reach a file

A relative pathname is the concatenation of the directory names from where you are currently “located” in the file hierarchy

A full pathname specifies the complete path traversed starting with the root (also called an absolute pathname)

Page 9: Basic UNIX © McGraw Hill 2000. All rights reserved

File and Directory Organization You can create and maintain files and

directories in your home directory Use subdirectories to organize files Use the mkdir command to create a

subdirectory: %mkdir myCS403stuff

New subdirectory will be be created in current directory (also called working directory)

Page 10: Basic UNIX © McGraw Hill 2000. All rights reserved

Moving Through the File Structure Using the cd command cd is the change directory command

Specify a directory name as an argument to cd command to move to that directory within the current directory %cd myCS403stuff

Specify a full pathname as an argument to change directories %cd /n/m/37/ehepp/myCS403stuff

Page 11: Basic UNIX © McGraw Hill 2000. All rights reserved

cd Command (continued)

%cd or %cd ~ will put you in your home directory: %cd %pwd /n/m/37/ehepp

To move up one one level in a directory hierarchy, follow the cd command with two dots: %cd .. %pwd /n/m/37

Page 12: Basic UNIX © McGraw Hill 2000. All rights reserved

File Manipulation

Rename a file (move)

%mv index.html index.old

Delete a file (remove)

%rm -i mystuff.txt

Look at contents of a file

%more index.html

Copy a file %cp -i index.html index.bkup

Create a file %pico myfile.html

Update a file %pico myfile.html

Page 13: Basic UNIX © McGraw Hill 2000. All rights reserved

Other UNIX Commands

List a directory’s contents %ls

List a directory’s contents in the “long form” %ls -l

List a directory’s contents including hidden files %ls -a

Remove a directory %rmdir myCS403stuff

Page 14: Basic UNIX © McGraw Hill 2000. All rights reserved

File Permissions

Permissions provide a measure of security by establishing who is able to access what files and directories, and how they can be accessed

File and directory permissions can be displayed using the ls -l command%ls -l

-r--r--r-- 1 marymc Spanish 167 Jul 27 08:15 file.txt

Page 15: Basic UNIX © McGraw Hill 2000. All rights reserved

Permission Codes

3 identifiers specify who can access the file: User who owns file – u (aka “owner”) Users who are members of the same group as the

file owner - g All other users - o (aka “rest of the world”)

3 levels of access: Read - r Write - w Execute – x (or “search” for directories)

Page 16: Basic UNIX © McGraw Hill 2000. All rights reserved

Permission Codes (continued)

r w x r w x r w x

u g

Nine characters are split into three sets of three characters each:

- 1st set identifies permissions for the user- 2nd set identifies permissions for the group- 3rd set identifies permissions for others (the rest of the world)

o

Page 17: Basic UNIX © McGraw Hill 2000. All rights reserved

Permission Code Examples

r - - r - - r - -user, group members, and others can read the file

r - - - - - - - -only the user can read the file

r w - r - - - - -user can read and write the file, group members

can read the file, all others are denied access

Page 18: Basic UNIX © McGraw Hill 2000. All rights reserved

Changing Permissions Use the chmod command to change

permissions Two ways to use chmod command:

Symbolic form Numeric form

Page 19: Basic UNIX © McGraw Hill 2000. All rights reserved

Symbolic Form of chmod Uses permission code symbols (u, g, o, r,

w, x) to add and remove permissions Basic form of command:

To add a permission: %chmod [who]+[access] filename eg. - %chmod o+r README To remove a permission: %chmod [who]-[access] filename eg. - %chmod o-w README

Note: Can set more than one at a timeeg. - %chmod o+r,og-w myfile.html

Page 20: Basic UNIX © McGraw Hill 2000. All rights reserved

Numeric Form of chmod

Think of 9 character permission codes as 9 on/off switches represented by 1/0r w x r w x r w x 1 1 1 1 1 1 1 1 1

r w x r - x r - - 1 1 1 1 0 1 1 0 0 View the binary representation as 3 triplets

1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0

7 7 7 7 5 4

Page 21: Basic UNIX © McGraw Hill 2000. All rights reserved

Numeric Form of chmod (continued)

Use chmod command with octal value representing desired permissions

Examples:%chmod 777 myfile.html

1 1 1 1 1 1 1 1 1 r w x r w x r w x

%chmod 711 mydirectory1 1 1 0 0 1 0 0 1 r w x - - x - - x

%chmod 644 myfile.html1 1 0 1 0 0 1 0 0 r w - r - - r - -

Page 22: Basic UNIX © McGraw Hill 2000. All rights reserved

File Names

UNIX is case sensitive so Myfile.html is not the same as myfile.html

Avoid special characters in file names: < > | & *

Extension at end of file name indicates type of file: .html or .htm - Web page .c - C program file .ps - postscript file

* represents any arbitrary character string eg. - %ls *.html