...

/

Managing File and Directory Permissions

Managing File and Directory Permissions

Understand file and directory permissions.

We'll cover the following...

Checking permissions

If we’re the system administrator, or if we can run the sudo command, we can change the permissions on files and directories anywhere on our system.

The file structure we made in the home directory is something other users on the machine could use, so let’s copy the structure into the /var directory so others can access it. We use the sudo command since we don’t have write access to the /var directory:

$ sudo cp -r ~/files /var/files

Next, we get a long listing of the /var/files directory, showing all hidden files. This lets us view the permissions of the /var/files directory itself:

su temp
sudo mkdir -p files/{movies,music,photos,docs/{diagrams,markdown},code/{go,js,elm}}
clear
sudo cp -r /files /var/files
ls -alh /var/files

Run the complete code on the terminal below for practice.

Terminal 1
Terminal
Loading...

Recall from Listing Files and Directories that the first entry in the list (.), represents the directory itself, in this case, /var/files. Remember that the permissions break down like this:

File Permissions

User

Group

Others

rws

r-s

r-x

In this case, the root user can read, write, and execute files in this directory. Other users on the system can read from this directory structure and execute any files there, but they won’t be able to create new files or even make changes to the contents of the files. ...