16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example:<br />

drwxr-xr-- 2 fred student 1024 Mar 21 19:35.<br />

0 = "d" its a directory<br />

123 = "rwx", <strong>the</strong> owner has full permission<br />

456 = "r-x" <strong>the</strong> student group members can list this directory and access its files<br />

789 = "r--" everyone else can list <strong>the</strong> directory but not touch its files<br />

or "--x"<br />

access directory files but only if file names are known, can't list directory<br />

! In Summary:<br />

To access an existing file, a user needs:<br />

- search "x" permissions to each directory in <strong>the</strong> path name<br />

- access "r" permission to <strong>the</strong> file<br />

Example:<br />

cat ../dir1/dir2/prog.c<br />

- need "x" search permissions in:<br />

..<br />

../dir1<br />

../dir1/dir2<br />

- and "r" read permission<br />

../dir1/dir2/prog.c<br />

Introduction to <strong>Unix</strong><br />

Warning:<br />

- don't allow o<strong>the</strong>rs "w" permissions to your directories, as files can <strong>the</strong>n be deleted<br />

- don't allow "w" permissions to your .profile "rm -r *" in your .profile would zap all your files next time you<br />

logged in chown, chgrp & chmod<br />

By <strong>the</strong> way...<br />

- chown user file<br />

-changes file ownership<br />

-can donate a file to ano<strong>the</strong>r user<br />

-restricted to root on most systems<br />

- chgrp group file<br />

-changes <strong>the</strong> group of a file<br />

-only group members need apply<br />

- chmod mode file<br />

-changes file mode (permission bits)<br />

-can modify existing permissions or explicitly set new permissions<br />

- chmod u+rw myfile<br />

-adds user read & write permissions<br />

- chmod og-x myprog<br />

-removes group & o<strong>the</strong>rs execute permission<br />

! Mode bits:<br />

File permissions are stored in one number as a set of bits called <strong>the</strong> mode<br />

User | Group | O<strong>the</strong>r<br />

r w x r w x r w x<br />

4 4 4 read<br />

2 2 2 write<br />

1 1 1 execute<br />

Example<br />

chmod 644 myfile<br />

chmod 751 myprog<br />

sets "rw-r--r--" permissions<br />

sets "rwxr-x--x" permissions<br />

! Unmask command:<br />

The "umask" command is used to set <strong>the</strong> default creation mask for new files and directories (can be set in .profile).<br />

3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!