There are a few programs in Linux which every programmer MUST use at one point or another. Most of these are every-day tools, without which we cannot survive.
There are three basic functions we use to move files around in the Linux terminal. They are, in no particular order:
- cp source_location destination_location – Copy a file from one place to another
- mv source_location destination_location – Move a file from one place to another
- rm file – Delete a file
The uses for these programs are a bit self-explanatory. You could do this with the GUI interface, but that takes precious seconds out of your otherwise productive day.
Note: Each of these functions has a recursive option, which allows you to move entire directories around. This is a very useful feature.
Did you know that there are three different levels of permission in Linux, and three different kinds of permissions? The three levels are:
- Owner (user) Permissions – what can the person who owns the file do with it?
- Group Permissions – what can the group that owns the file do with it?
- General (other) Permissions – what can a random stranger do with the file?
Generally speaking, the owner can change all three levels of permissions. We do that with the program chmod.
chmod allows us to change the three kinds of permissions at each level. These permissions are:
- Read (r) – allows you to read the file and copy it
- Write (w) – allows you to make changes to the file
- Execute (x) – allows you to run the file like a program
There are also three basic ways to change permissions using chmod. The first method is to add or subtract the permissions you want to the file. For example, if we wanted to make panda executable, then remove panda’s write permissions, we could use the following commands:
chmod +x panda
chmod -w panda
The second way is to set permissions for each level. If we wanted panda to have all permissions for the owner, read/write permissions for the group, and only execute permissions for the general user, we could write the following:
chmod u=rwx, g=rw, o=x panda
Note: we can use the same format to add or subtract permissions from a particular permission level. In this case, chmod u+x panda changes the user permissions to include execution.
Note: There are four permission levels for chmod: user, group, other, and all.
Finally, we can set the permissions manually, using octal math. For each permission level:
- 4 is the read permission
- 2 is the write permission
- 1 is the execute permission
That means that the following commands are identical:
chmod u=rwx, g=rw, 0=x panda
chmod 761 panda
You can use any combination of the above methods to set your permissions. You can also check the permissions on your files using ls -l (or ls -ld, if you want to check directories).