Table of contents
No headings in the article.
In Linux, file permissions are a set of rules that determine who can access and modify files and directories. File permissions are set for three types of users: the file owner, the group that the file belongs to, and all other users.
There are three basic types of file permissions in Linux:
Read permission (r): Allows a user to view the contents of a file or directory.
Write permission (w): Allows a user to modify the contents of a file or directory.
Execute permission (x): Allows a user to execute a file or access a directory.
These permissions are assigned to each of the three types of users mentioned above using a combination of three bits for each permission. The bits are represented as follows:
r (read) = 4
w (write) = 2
x (execute) = 1
- (no permission) = 0
So, for example, if a file has the following permissions: rw-r--r--
, it means that the file owner has read and write permissions, while all other users have only read permission.
To modify file permissions, the chmod
command is used. The chmod
command modifies the permissions of a file or directory by setting or removing the read, write, and execute bits for each of the three types of users.
The basic syntax of the chmod
command is as follows:
chmod [permissions] [file/directory]
Here, [permissions]
represents the desired permissions in the form of three digits, where the first digit represents the file owner's permissions, the second digit represents the group's permissions, and the third digit represents all other users' permissions. Each digit is a sum of the values of the desired permissions (r=4, w=2, x=1).
Create a simple file and do ls -ltr
to see the details of the files
Open the terminal and navigate to the directory where you want to create the file.
Use the
touch
command to create a new file. For example, let's create a file calledmy_file.txt
:
touch my_file.txt
- Use the
ls -ltr
command to view the details of the file. Thels
command is used to list the contents of a directory, and the-ltr
option is used to sort the files by modification time in reverse order (newest files last) and display the details in long format, including permissions, ownership, size, and modification time:
ls -ltr my_file.txt
This will display the details of the my_file.txt
file in the terminal, similar to the following:
-rw-r--r-- 1 user group 0 Mar 26 10:30 my_file.txt
Here, -rw-r--r--
indicates the file permissions, 1
indicates the number of links to the file, user
is the owner of the file, group
is the group that the file belongs to, 0
is the file size in bytes, Mar 26 10:30
is the modification time, and my_file.txt
is the name of the file.
That's it! You have created a simple file and viewed its details using ls -ltr
command in Linux.
#Linux #DevOps #Shellscript
Please free to write your thoughts and can connect with me on LinkedLn