Users and Permissions
For each file, ls <filename> -l
displays the permission of the file, something like -rw-rw-r--
:
- the first char specifies the type of file: d for directory, - for file, l for link.
- every following 3 chars specify the permissions to 3 different groups respectively: the file owner, the group and others
The purpose of having these 3 different tiers for each file could be explained easily with an example:
You(t1) and your teammates(t3, t2) are working on a project, and you and your teammates and other random people are all using the same Linux machine in the school lab. You wanna give yourself the permission to read, write and execute the program "project.py", while giving your teammates the rights to read and execute but not modifying it, and you don't even allow others to look at your code.
Then what you could do is to create a group named "team", putting t1, t2 and t3 all under this group, then do chmod 750 project.py
Changing permissions
Only the file owner or the root user is able to change the permissions of a file. Three commands are used:
-
chmod <xxx>
changes the permissions of the file, where each x corresponds to the permissions to the file owner, group and others respectively. Note that the numbers are: r:4, w:2, x:1 -
chgrp <group_name> <file_name>
changes the group. Note that<group_name>
must be an existing group in /etc/group -
chown
changes the owner of the file. I've never used it though.
$PATH
This variable stores all the paths that are looked up when executing a command. For example, the command ls
is stored under /bin/
.
To inspect the vairable, do echo $PATH
To add something to the $PATH variable, do PATH="${PATH}:<absolute_path>"
Inspecting files
cat <filename>
: print the content of the file
more <filename>
: display the file page by page. Press space for next page, press q for quit, press Enter for next line.
head -<n> <filename>
: display the first n lines of the file
tail -<n> <filename>
: display the last n lines of the file
Top comments (0)