Download presentation
Presentation is loading. Please wait.
1
Introduction to Unix – CS 21
Lecture 3
2
Lecture Overview Lab review More on files and listings
Disk usage and compressing files Permissions and ownership
3
How Did Lab Go? What was missing?
What did I want you to get out of it? 1. Basic differences between Windows and Unix 2. Difference between a good design and a bad design A, b, x don’t really make good descriptions
4
Lab Continued 3. Getting used to navigating the system
4. rmdir can only remove empty directories 5. A lot of environment variables are automatically set, but not every one will be used every time 6. Difference between an environment variable and a local variable 7. Get used to reading man pages 8. Think about the future
5
What ls Output Means
6
Properties Of Files All files have these properties Permissions Links
For directories, this lists the number of subdirectories Owner Owner group Size Timestamp Name
7
Disk Space And Quota Every file takes some amount of space, even an empty file Space for the name, and information about the file Your account has limited space quota can be used to check available space Du shows how much space you are using and where it is located “du –s” summarizes and just gives you the total
8
The du Command
9
Saving Disk Space Compressing files Decompressing files Zip gzip bzip2
GNU version of zip bzip2 Different algorithm Decompressing files unzip, gunzip, bunzip2
10
Running zip, gzip, And bzip2
11
A Special Type of File: A Symbolic Link
Not an actual file, but a pointer to another file Acts as a shortcut Can act as a shortcut to a directory Provides a quick link to any file Often used so files can be changed without disturbing other programs
12
Graphical Representation
/home/csmajs/user /home/csmajs/user/cs21 /home/csmajs/user/cs21/link /home/csmajs/user2/otherFile
13
Creating Symbolic Links With ln
ln –s TARGET NAME -s signifies a symbolic link Without the –s, a hard link is created Difference between a hard link and a symbolic link? A hard link’s target must exist A symbolic link can point to nothing (broken link)
14
Overview Of Permissions
-rwxrwxrwx - rwx rwx rwx File Type Owner Group World
15
Owner, Group, The World Owner Group The world The creator of the file
A set of users grouped together The world Every other account not in the group
16
Read, Write, Execute Read Write Execute
File can be read, but not modified Write Permission is granted to modify the file Execute Run directly as if the file is a program All programs should be executable (/bin)
17
What Permissions Mean On A Directory
Read Users can get a listing of that directory Write Users can create and remove files in that directory Execute Users can examine files in that directory
18
Changing Permissions With chmod
chmod SETTINGS FILENAME u = user g = group o = other a = all + (add) (remove) = (set) r = read w = write x = execute chmod a-x testFile
19
More Examples Set read and write access for all?
chmod a=rw FILE Add executable access for others? chmod o+x FILE Remove all access for owner? chmod u-rwx FILE
20
Advanced chmod Usage Most Unix hackers don’t use this form
They prefer the more direct approach Set permissions for owner, group, and others all with one number Unfortunately, this approach requires a little bit of information
21
How Decimal Numbers Work
1234 1 * * * * 1 1 * * * * 10 10 distinct values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Why is this system so comfortable? 3 2 1
22
Binary Numbers Only two distinct values
0 and 1 On and off Binary numbers work the exact same way as decimal numbers
23
Conversion 1010 111 1 * 2 + 0 * 2 + 1 * 2 + 0 * 2 8 + 0 + 2 + 0 = 10
1 * * * 2 = 7 3 2 1 2 1
24
Powers Of Two x 2 Decimal Value 1 4 8 16 32 64 1 2 3 4 5 6
25
Octal Numbers Eight distinct numbers
0, 1, 2, 3, 4, 5, 6, 7 Binary numbers can be split into groups of three and represented by an octal number exactly
26
Conversion Table Binary Number Octal/Decimal Number 000 001 1 010 2
001 1 010 2 011 3 100 4 101 5 110 6 111 7
27
Relationship Between Binary Numbers And Permission
Each permission can be represented by a binary number Each slot is either on or off = 000 rwx = 111 rw- = 110 r-x = 101 Each group of three corresponds exactly to an octal number
28
Conversion Examples Read, write, and execute permission for everybody?
rwx rwx rwx = = 777 Read and execute permission for everyone? r-x r-x r-x = = 555 Read permission for owner, write permission for group, and execute permission for everyone else? r-- -w- --x = = 421
29
More Examples All permission for owner, read and execute for everyone else? rwx r-x r-x = = 755 Read, write for owner, and read only for everyone else? rw- r-- r-- = = 644
30
Back To chmod The advanced way to use chmod is to use octal numbers and set all permissions at once
31
chgrp And chown chgrp will change the group setting of a file to another that you are a member of You probably don’t belong to more than one group chown will change the owner of a file Only the owner may chown a file Once chown’ed, the new owner is the only one who can grant permission back
32
Using umask To Set Default Permissions
Every time you create a file, the permissions are set to a default umask will set this default Unfortunately, it does it the exact opposite way than you would think
33
How umask Works If you want default permissions to be 770, you set your umask with the opposite: 007 Permissions = 770 = umask = Unix tries to be helpful and clears the executable flags, though
34
Examples Read, write, execute permission for owner, nothing for anyone else? Permissions = 700 = umask = All permissions for owner and read, write for group? Permissions = 760 = umask =
35
More Examples Read and write permissions for everybody?
umask = No permissions for anybody? Permissions = 000 = umask =
36
A Couple Simple Commands
echo Simply prints out whatever it is given Example:
37
Using echo To Make A Simple File
38
Timestamps touch command
Without any flags, it will make the modification time of that file the current time Can be used to create a new file, but the file will be empty (0 byte size)
39
Final Notes For Today We have covered up through chapter 5 in the book, so you will be expected to have read these chapters Next time we will delve deeper into creating files and moving them around in the file system
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.