File Attributes
In linux, files have many attributes. We can execute the following command in the command line to view them: ls -l
This command will list all files in the current directory. Each line is a file ie:
-rwxrwxrwx 1 root root 9580 abr 30 14:48 myfile
- is the type of file.
rwxrwxrwx is the permission of the file. We will see how they work later on this article.
1 is the number of hard links
root root the first root is the user owner of the file, and the second refers to the group.
9580 is the file size
abr 30 14:48 is the date and time of the last modification of the file.
myfile is the name of the file.
Type of files
The first attribute can have the following values:
- regular file
d directory
l soft link
b block-oriented device file
c character-oriented device file
p fifo or pipe
File Permissions
Permissions are sorted by groups of 3. The first group refers to the owner of the file, the second refers to the group and the third refers to other.
rwx rwx rwx is equal to 777 in octal
r Read
w Write
x Execute
Example: rwx r-- --x
rwx = 421
r-- = 400
--x = 001
4+2+1=7
4+0+0=4
0+0+1=1
So, the file permission in octal is 741
CHMOD
To change the file permissions we can use the chmod command. There are two ways to use it:
The first way is - chmod 777 myfile will set the permission 777 to myfile
The second way is - chmod g+x myfile Here we add the permission execute to the owner group of the file.
We can use o+, o- for other users permissions, g+, g- for adding or deleting group permissions and u+, u- for the user owner permissions, followed by the letter r(read), w (write) or x (execute).
CHOWN
If we want to change the owner of an specific file we can use this useful command:
chown -R newowner /pathofthefile
CHGRP
And to change the group we can use this command:
chgrp newgroup /pathofthefile
More Articles in This Category
Cron
Add a link to this article
It will look like this: File Permissions
discuss this topic to forum
