1 File Permissions Look at permissions with ls -l Output: –-rw-r--r-- 1 enda users 1234 Jun 2 10:51 file.ext
2 What are those first few characters? First character (type of file) Next 9 (permissions) Next (Number of links) Next (Name of file owner) Next (Group name) Then file size, date, and file name
3 First character Usually either - or d - for normal files d for directories l for link (We’ll see this later)
4 Next 9 Characters Each set of 3 specifies read, write, and execute access for user, group, and everyone
5 Read Access Allows you to read the file but not modify it or execute it
6 Write Access Allows you to overwrite a file but not read or execute it
7 Execute Allows you to execute an executable but not read it or write over it
8 Changing Permissions Command: chmod “Change Mode” Use this command to set the access mode for the user (file owner), a group, other (everyone else), or all (all possibilities)
9 chmod Template: chmod [u|g|o|a][+|-][r][w][x] Pick one of u,g,o, or a for the first part to represent whether you are changing permissions for user, group, other, or all Pick one of - or + to either remove or add permissions, respectively Pick r,w, or x or any combination to represents read, write, or execute permissions, respectively
10 chmod example Suppose I want to make a file named secrets.txt that can only be accessed by myself I want read, write, and execute permissions I do not want anyone else to be able to access the file at all Example: –chmod a-rwx secrets.txt –chmod u+rwx secrets.txt
11 Another chmod example Suppose I want to make a file called submit that can only be executed by anyone Example: –chmod a-rw submit –chmod a+x submit
12 Another chmod Example Suppose I want to make a web page called index.html that I can read, write, or execute but everyone else can only read Example: –chmod a-wx index.html –chmod u+rwx index.html –chmod a+r index.html
13 chmod Tricks Here’s a trick for making a file that you can read, write, execute but nobody else can do anything with Example: chmod 700 example_file Here’s how to make a file that you can read, write, execute but others can only read Example: chmod 744 example_file
14 Numbers Read: 4 Write: 2 Execute: 1 Read and Write: 4+2 = 6 Read and Execute: 4+1=5
15 chmod with directories You cannot execute a directory Instead, think of the “x” as meaning “directory listing is allowed” If you do not allow users the “x” permission on a directory then they cannot use the command ls to list the contents of a directory
16 Creating File Links Links are like shortcuts to a file You can create links to any file Command: ln Template: ln existing_file new_link Example: ln file1.txt file2.txt DOES NOT COPY THE FILE
17 Hard and Soft You can make a Hard link –This is the same file. –If you were to now delete the original file, the contents of the file would still exist as the new filename. You can make a soft link –Now the file just has 2 different names. –However if you delete the original file, the data is gone forever.
18 Experiment Suppose I have a file named stuff.txt Suppose I create a link called stuff2.txt What is the contents of stuff.txt? What is the contents of stuff2.txt? Suppose I edit stuff.txt and change it. Are stuff.txt and stuff2.txt different? NO!!!!!!!!
19 How to remove a link? Just use: rm
20 What happens if you remove what a link is connected to? The link remains and it is still connected to the original data.