• No results found

Basic File Attributes

N/A
N/A
Protected

Academic year: 2020

Share "Basic File Attributes"

Copied!
55
0
0

Loading.... (view fulltext now)

Full text

(1)

UNIX

Reference:

UNIX Concepts and Applications – 4th Edition

By

(2)

Basic File Attributes

• ls –l

• File ownership

• File permissions

• chmod

• Directory permission

(3)

ls –l (Listing file attribtes)

$ ls –l

(4)

ls –l (Listing file attribtes)

(5)

ls –l (Listing file attribtes)

• ls looks up the file’s inode to fetch its attributes.

– File type and Permissions: the first column shows the type and permissions associated with each file. If the first character is a “-”, then it indicates that the file is an ordinary file. For the directories we will see a “d” at the same position.

(6)

ls –l (Listing file attribtes)

• ls looks up the file’s inode to fetch its attributes.

(7)

ls –l (Listing file attribtes)

• ls looks up the file’s inode to fetch its attributes.

(8)

ls –l (Listing file attribtes)

• ls looks up the file’s inode to fetch its attributes.

(9)

ls –l (Listing file attribtes)

• ls looks up the file’s inode to fetch its attributes.

– File size: the fifth column shows the size of the file in bytes, i.e., the amount of data it contains.

(10)

ls –l (Listing file attribtes)

• ls looks up the file’s inode to fetch its attributes.

– The space occupied by a file on disk is usually larger than this.

(11)

ls –l (Listing file attribtes)

• ls looks up the file’s inode to fetch its attributes.

– The two directories show smaller file sizes (512 bytes each).

– The directory maintains a list of filenames along with an identification number (the inode number) for each file.

(12)

ls –l (Listing file attribtes)

• ls looks up the file’s inode to fetch its attributes.

– Last modification time: the sixth, seventh and eighth columns indicates the last modification time of the file.

– A file is said to be modified only if its contents have changed.

(13)

ls –l (Listing file attribtes)

• ls looks up the file’s inode to fetch its attributes.

(14)

File Ownership

• When you create a file, you are the owner of the file.

• Your group is the group owner of the file.

• If you copy someone else’s file, you are the owner of the copy.

(15)

File Ownership

• When the system administrator creates a user account, he has to assign these parameters to the users:

– The user-id (UID): both name and numeric representation

(16)

File Ownership

• The file /etc/passwd maintains the UID (both the number and name) and GID (only the number).

(17)

File Ownership

• To know your UID and GID without viewing /etc/passwd and /etc/group we use

$ id

(18)

File Permissions

• Every file and directory in your account can be protected from or made accessible to other users by changing its access permissions.

(19)

File Permissions

• To display the access permissions of a file or directory use the command:

ls -l filename (directory)

• This displays a one line summary for each file or directory. For example:

(20)

File Permissions

• There are three types of permissions:

r read the file or directory

w write to the file or directory

(21)

File Permissions

• Each of these permissions can be set for any one of three types of user:

u the user who owns the file (usually you)

g members of the group to which the owner

belongs

(22)

File Permissions

• The access permissions for all three types of user can be given as a string of nine characters:

(23)

File Permissions Examples

$ ls -l file1

(24)

File Permissions Examples

$ ls -l file2

-rw-r--r–

(25)

File Permissions Examples

$ ls -l myprog

-rwx--x—x

(26)

File Permissions Examples

$ ls -l

...

drwxr-x---

(27)

Summary File Permissions

Permission File Directory

r read read a file list files in ... w write write a file create file in ...

rename file in … delete file …

x execute execute a shell script

read a file in ...

write to a file in ... execute a file in ...

(28)

Changing File Permission

The chmod (change mode) command is used to set permissions of one or more files for all three categories of user (user, group and others).

• It can be run only by the users (the owner) and the superuser.

• The command can be used in two ways: – Relative manner

(29)

Changing File Permission

(30)

Changing File Permission

• To change the access permissions for a file or directory use the command

chmod mode filename

chmod mode directory_name

(31)

Changing File Permission

Who the permissions apply to

• This is specified as one of:

o u (user) the owner of the file

o g (group) the group to which the owner belongs

o o (other) everyone else

(32)

Changing File Permission

How the permissions are to be set

This is given as one of:

o + add the specified permission

o - subtract the specified permission

o = assign the specified permission, ignoring

(33)

Changing File Permission

The permissions to be set

These are specified by one or more from:

o r read

o w write

o x execute

(34)

Changing access permissions using

the chmod command

• To give yourself permission to execute a file that you own:

$ chmod u+x file1

(35)

Changing access permissions using

the chmod command

• To give members of your group permission to read a file:

$ chmod g+r file2

(36)

Changing access permissions using

the chmod command

• To give read permission to everyone for a particular type of file:

$ chmod a+r *.pub

(37)

Changing access permissions using

the chmod command

• To give the group write and execute permission:

$ chmod g+wx $HOME/SCCS

(38)

Changing access permissions using

the chmod command

$ ls –l xstart

-rw-r--r--$ chmod u+x xstart $ ls –l xstart

(39)

-rwxr--r--Changing access permissions using

the chmod command

$ chmod ugo+x xstart; ls –l xstart -rwxr-xr-x

The previous sequence can be replaced by,

$chmod a+x xstart (a implies ugo)

(40)

Changing access permissions using

the chmod command

chmod accepts multiple filenames in the

command line.

(41)

Changing access permissions using

the chmod command

• Permissions are removed with – operator.

$ ls –l xstart -rwxr-xr-x

(42)

Changing access permissions using

the chmod command

chmod accepts multiple expressions delimited

by commas.

(43)

-rw-r--r--Changing access permissions using

the chmod command

• More than one permission can also be set;

• u+rwx is a valid chmod expression.

(44)

Changing access permissions using

the chmod command

• Absolute permissions: sometimes you don’t need to know what a file’s current permissions are, but want to see all nine permission bits explicitly.

(45)

Changing access permissions using

the chmod command

• There is a shorthand way of setting permissions by using octal numbers.

– Read permission is given the value 4,

– write permission the value 2

– Execute permission 1.

r w x

(46)

Changing access permissions using

the chmod command

• These values are added together for any one user category:

o 1 = execute only

o 2 = write only

o 3 = write and execute (1+2)

o 4 = read only

o 5 = read and execute (4+1)

o 6 = read and write (4+2)

(47)

Changing access permissions using

the chmod command

• So access permissions can be expressed as three digits. For example:

user group others chmod 640 file1 rw- r-- --- chmod 754 file1 rwx r-x r-- chmod 664 file1 rw- rw- r--chmod 000 file1 --- ---

(48)

Changing access permissions using

the chmod command

• Using chmod recursively (-R)

It’s possible to make chmod descend a directory hierarchy and apply the expression to every file and subdirectories its find.

$ chmod –R a+x dir1

(49)

Changing access permissions using

the chmod command

• You can provide multiple directory and filenames, and if you want to use chmod on your home directory tree, then “cd” to it and use it in one of these ways:

(50)

Changing file ownership

• Changing file ownership means only updating the association between a Unix user and a file, and nothing else.

• When you're changing the owner of a file, no data contained in a file is changed.

(51)

Changing file ownership

$ chown nobody file1

In this command, nobody is the username of the new owner for a list of files. In my example, the only file we'd like to change ownership for is file1.

(52)

Changing group owner

• By default, the group owner of a file is the group to which the owner belongs.

The chgrp command changes a file’s group owner.

(53)

Changing group owner

Note: a user can belong to more than one

group, and the one shown in the /etc/passwd is the user’s main group.

• If the user is not the member of the group then only superuser can make the changes.

(54)

Changing both

(55)

chown and chgrp with –R option

References

Related documents

With regard to the maintenance process, each vehicle can keep an accurate state of the current E-VoEG model using the information of the received BSMs and authenti- cated

The only allowed set of permissions is 755, so please open your FTP browser and change permissions of all files with .php extension to -rwxr-xr-x (CHMOD 777) (these files can be

Class Work and  Homework Policy:   

An efficient hybrid differential evolutionary algorithm for BLOP (HDEAB) is proposed where the optimal lower level value function mapping method, the differential

A wide range of pipe materials is available for installation using pipejacking and microtunnelling techniques, the choice depending on the requirements of the client, the

The Research Secretary coordinates distribution of fliers, itineraries, meeting room arrangements, equipment (computer, LDC project), sign-in sheets, collection of public

• Non-CFC appliances will be accepted at the following transfer stations (fee may apply): Becket, Egremont, Great Barrington, Monterey, New Marlborough, Otis, Sheffield (no

– VCC staff were added mid-way into the production schedule – No difference observed in qualitative monitoring ratings. – No difference observed in interview administration length