Linux File Attributes: A Beginner’s Guide to Linux | Jungle Disk
So, if you’re new to Linux and you’re coming from a Windows background, one of the basic concepts you will need to grasp is the way file permissions work on Linux systems.
Let’s take file.txt as an example. The file “file.txt” has the permissions “-rw-rw-r–.” which can also be written as “0664.” A file’s permissions are essentially broken down into three groups: permissions for the owner, group and others (in that order). The numerical value assigned to each of these is four for read permissions, two for write permissions and one for execute permissions.
With the permissions given, the owner “Bob” has read and write permissions, as well as everyone in the “Bob” group. Others can read the file, but can’t make any changes to the file nor execute it. The first dash in the permissions is not actually a permission but is meant to represent the file type. Regular files are marked with a dash “-“ and directories with a “d”.
So file permissions are pretty straightforward, but how would you change permissions of a file? The three commands you would commonly use to do that are “chmod,” “chgrp” and “chown.” The “chmod” command or “change mode” is what you use to change the access mode (permissions) of a file. To give full permissions to a file, you could do “chmod 777” which would grant full access to read, write and execute for every user (never do this).
Say you’re ready to share the file. The first thing you’re going to need to do is to move the file in a folder everyone you want to have access to the file has access to. In the above example we were using Bob’s home directory, which you can see at the very top that only Bob has access to, per the “(drwx——)” permissions. So, let’s move it out to a new directory at /usr/shared with “sudo mkdir /usr/shared && mv /home/bob/file.txt /usr/shared/ && sudo chmod 664 /usr/shared”. Now you’re working out of a folder that you want multiple users have access to, but not everyone. Well that’s where groups and the chgrp command would come in.
If file.txt had a sick recipe for pumpkin spice cake balls and I wanted Paul to share in the flavor explosion, but not enough to share my supply of pumpkin goodness, I could make make a “bakers” group with “sudo groupadd bakers” and then add Paul to the “bakers” group with “sudo usermod -aG bakers paul.” Then I just give use “chgrp bakers /usr/shared” to give members of the “bakers” group access to the directory which has the file(s) I want others to access.
To quickly touch on the some of the other commands used:
- mkdir is used to make new directories
- mv is for moving files from A to B
- sudo is for executing a command with root privileges If you’re looking for a Linux distribution to give a try, I recommend downloading a virtualization tool like VirtualBox and an ISO of a distribution like Linux Mint as a good place to get started.