Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.

24
Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.

Transcript of Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.

Title Slide

CSS 404/504

The UNIX

Operating System (2)

By

Ralph B. Bisland, Jr.

2Internet Concepts Copyright Ralph Bisland 2004

File Permissions• The creator of a file/directory controls what

other users can do with the file/directory.• There are three types of permissions:

– Read permission ( r) - User can "read" (or access) your file

– Write permission (w) - User can "write" (or change) your file

– Execute permission (x) - User can "execute" (for programs only) your file

• Note: There are both file and directory permissions.

3Internet Concepts Copyright Ralph Bisland 2004

Categories Of Users

• There are three categories of users that can access your files:– Other (o) - all system users– Group (g) - All users within your group– User (u) - You only

• The default file permissions are for all three groups to have all three permissions

• To display the permissions of a file, use the ls -l (list long) command.

4Internet Concepts Copyright Ralph Bisland 2004

Setting File Permissions• If you do not set your file/directory

permissions correctly, others will not be able to access your web pages.

• There are two methods of setting permissions on a file:– Unmask: (umask)

• There is a system default (all permissions to all users) for file permissions that you may adjust.

– Change mode: (chmod)• Used to change the mode for individual files

5Internet Concepts Copyright Ralph Bisland 2004

File Permission Settings File permissions are generally specified

using a binary digits as on/off switches: Binary 0 = off, binary 1 = on

First binary digit = Read permission Second binary digit = Write permission Third binary = Execute permission

6Internet Concepts Copyright Ralph Bisland 2004

Using Octal Digits

• Use an octal digit to indicate the privilege for each category: Bin Oct Permission --- --- ------------------------------------

000 = 0 = No permission 001 = 1 = Execute permission only 010 = 2 = Write permission only 011 = 3 = Write and execute permissions only 100 = 4 = Read permission only 101 = 5 = Read and execute permissions only 110 = 6 = Read and write permissions only 111 = 7 = Read, write, and execute permissions

• File permissions are generally specified with three digits: owner, group, world

700 666 644

7Internet Concepts Copyright Ralph Bisland 2004

Using umask• The system default for permissions is 777

(all permissions to all categories)• This can be altered (and is) via the unmask

(umask) command

orca% umask 077

• This command unmasks or turns off the default permissions for group and world.

8Internet Concepts Copyright Ralph Bisland 2004

Using umask (ctd)• Text editors create files with permissions = 600

• This can be altered with the umask commandorca% umask 333orca% umask 222

• The umask command affects all files created when the mask is in effect.

• Any editing changes to the file do not affect the permissions.

• To see the current umask, enter umask without any parameters.orca% umask

9Internet Concepts Copyright Ralph Bisland 2004

Changing Permissions On A File• Once a file has been created, permissions can

be altered with the change mode (chmod) command:

• Format: chmod permission-mask file-name(s)

• Remember this command turns on permissions, it does not turn them off like umask.

• Example:

orca% chmod 644 my-file.dat

10Internet Concepts Copyright Ralph Bisland 2004

Changing File Permissions (ctd)• Another way to specify permissions:

• Specify which privilege (rwx) you wish to add or delete with a + or -

orca% chmod +w my-file.dat orca% chmod -x+r my-file.dat

• Can even alter permissions to a file by preceding privilege with u, g, or o.

orca% chmod o+r my-file.dat

11Internet Concepts Copyright Ralph Bisland 2004

Accessing Files From Other Users• If a file exists in another user’s account and you

wish to access it, you can copy it to your directory.• This is only allowed if the user gives you the

directory and file privileges of accessing it.• Assume that the other user's account is abc and

the subdirectory is xyz and you wish to copy the file called foo.dat into your directory.

orca% cp ~abc/xyz/foo.dat bar.datorca% cp ~abc/xyz/foo.dat .

12Internet Concepts Copyright Ralph Bisland 2004

Online Help• Most UNIX commands have on-line help.

• To get to the help, use the manual (as in reference manual) command (man) followed by the command name you wish help on.

• Example:

orca% man ls

13Internet Concepts Copyright Ralph Bisland 2004

Searching Files• Text files can be searched for strings.

• To search a file for a string use the global regular expression print command

• Commonly known as grep• Format: grep [parameter(s)] string filename• Example:

orca% grep ralph my-file.dat

• Each line containing the string "ralph" is displayed

14Internet Concepts Copyright Ralph Bisland 2004

Searching Files (ctd)• If the string contains a blank, the string must

be enclosed in double quotes.

orca grep "ralph bisland" my-file.dat

• Parameters:– i = Ignore case– v = display lines that do not match the string

15Internet Concepts Copyright Ralph Bisland 2004

Piping• Pipe: A connection between two processes that

passes the output of the first process as input to the second process.

• Very useful feature.• The symbol used for piping is the vertical bar (|).• Format: <command1> | <command2>• Example:

orca% ls | more

16Internet Concepts Copyright Ralph Bisland 2004

Redirecting Input & Output• Redirection: A shell construct for

causing a program to take its standard input from a specified file or to send its standard output to a specified file.

• The symbols used for redirecting are >, >> and <

• Use the < symbol to redirect input files (use the file specified as input to the process)

17Internet Concepts Copyright Ralph Bisland 2004

Redirecting Input & Output• Format: process < filename

orca% cat < my-file.dat

• Use the > symbol to direct the output of a process into a file

• Format: process > filename

orca% ls -l > outfile.dat

• The >> symbol appends the output on to a currently existing file.

18Internet Concepts Copyright Ralph Bisland 2004

Searching For A File

• The locate command helps you find where a file is located.

• Format: locate stringwhere string is a subset of a file name

• Warning: This command searches the entire computer for the file string. This may lead to lots of output.

19Internet Concepts Copyright Ralph Bisland 2004

Examplesorca% locate rbb

/orca/faculty/bisland/public_html/rbb.save/orca/faculty/jrodgers/public_html/rbb.cgi/orca/faculty/jrodgers/public_html/rbb.dat

You may want to consider piping theoutput to the grep utility

orca% locate rbb | grep bisland

20Internet Concepts Copyright Ralph Bisland 2004

Spelling Of A Word• UNIX has a file containing approximately 45,000

words stored in its spelling dictionary.orca% wc /usr/dict/linux.words

45402 45402 409048 /usr/dict/linux.words

• You may search this dictionary for the spelling of words.

• To search the dictionary use the look command.• Format: look stringorca% look pneu

21Internet Concepts Copyright Ralph Bisland 2004

Who Is Currently Using The System• To find out the login names of the users

currently using the system, use the who command.

• Format: who

orca% who

22Internet Concepts Copyright Ralph Bisland 2004

AliasingAny command can be aliased by using the alias command.

Use aliasing to make commands shorter or easier to remember for you.

Format: alias <string>=<thing to alias>

Note: The = is used in the Korn shell only.

Examples:

$ alias q=logout

$ alias lo=logout

$ alias lls='ls -al'

Note the use of quotes if there are embedded spaces in the alias string

23Internet Concepts Copyright Ralph Bisland 2004

Nifty Neat UNIX Utilities

• Calendar cal <month-number> <year> Ex. cal 9 1752cal <year> Ex. cal 1995

• Leaveleave Ex: leaveleave <absolute time> Ex: leave 1030leave <+relative time> Ex: leave +30

• Calculator bc Ex: bc {then enter expressions}

Note: all calculations are done in integer

24Internet Concepts Copyright Ralph Bisland 2004

More Nifty Neat UNIX Utilities• Who Am I? orca% whoami

• Hostname: orca% hostname

• Disk quota: orca% quota

• Date: orca% date

• Random Sayings: orca% fortune orca % fortune –o