Shell and files
Files concepts that are relevant to the shell
✔️ Linux and files
- The first thing we need to appreciate with linux is that under the hood, everything is actually a file. A text file is a file, a directory is a file, your keyboard is a file (one that the system reads from only), your monitor is a file (one that the system writes to only) etc ...
- In other systems such as Windows the extension is important and the system uses it to determine what type of file it is. Under Linux the system actually ignores the extension and looks inside the file to determine what type of file it is.
✔️ Files permissions
- Linux permissions dictate 3 things you may do with a file (read, write and execute)
- Each permission is to in Linux by a single letter :
-
r
read - you may view the contents of the file. -
w
write - you may change the contents of the file. -
x
execute - you may execute or run the file if it is a program or script.
-
- For a given file, 3 different sets of people can be given permissions :
-
owner
- a single person who owns the file. (typically the person who created the file but ownership may be granted to someone else) -
group
- every file belongs to a single group. -
others
- everyone else who is not in the group nor the owner.
-
-
chmod
sets permissions on a file for owner, group, others :chmod <permissions> <file>
. - Permissions shorthand is a 3 octal digits number those 3 digits set permissions for owner, group, others.
- Each digit sets r, w, x permissions for the intended target.
- For instance,
chmod 644 /path
sets the permissions for/path
to-rw-r--r--
. - The same series of permissions may be used for directories but behave differently :
-
r
- you have the ability to read the contents of the directory (ie do anls
). -
w
- you have the ability to write into the directory (ie create files and directories). -
x
- you have the ability to enter that directory (iecd
).
-
- On a Linux system there are only 2 people usually who may change the permissions of a file or directory : the owner of the file or directory and the root user.
Example : It is typical for a system to run a webserver and allow users to each have their own web space. A common set up is that if you place a directory in your home directory called public-html then the webserver will read and display the contents of it. The webserver runs as a different user to you however so by default will not have access to get in and read those files. This is a situation where it is necessary to grant execute on your home directory so that the webserver user may access the required resources.