The operating system controls file access in Linux by utilizing file permissions, attributes, and ownership. In Linux, file permissions, attributes, and ownership determine the level of access that system programs and users have to files.
Learn more about Linux file permissions
This ensures that only particular directories and files are accessible to authorized users and processes only.
Having knowledge of the Linux file system permissions structure enables you to restrict access to files and directories to only authorized users and processes, hence increasing the level of security of your system.
In Linux, each file is owned by a specific user and a group, and authorization access rights are assigned to three different types of users:
• The owner of the file.
• The group members.
• Others users (everybody else).
There are three types of file permissions that apply to each user class and let you determine which users can read, write to, or execute the file.
Here are three types of file permissions that apply to each user class:
• The read permission.
• The write permission.
• The execute permission.
Both files and directories have identical permission properties. However, they have different meanings.
[+] Read Permission (r)
• When the read permission is set, the file can be read; for example, the user can open the file in a text editor (nano, vim, and so on).
• The contents of the directory can be viewed. The ls command allows the user to list files within a directory.
[+] Write Permission (w)
• A file that has write permissions can be changed or modified.
• If a directory has write permissions, its contents can be modified. The user can create new files, delete existing files, move files, rename files, etc.
[+] Execute permission (x)
• The file can be run, such as a bash script.
• The directory can be entered using the cd command.
As I have mentioned, file permissions or attributes can be viewed using the ls command. Here is an example:
A breakdown of the ls command output:
The file type is indicated by the first character. It could be a normal file (-), a directory (d), a symbolic link (l), or any other form of file. The file permissions are represented by nine characters, three groups of three characters each.
The first group indicates the owner's permissions, the second group indicates group permissions, and the third is everyone else's permissions.
In the example above, (`-rwxr-xr-x`) means that the file owner has read, write and execute permissions (`rwx`), and the group and others have only read and execute permissions (`r-x`).
[+] File permissions numerical representations:
File permissions can be represented numerically or symbolically. In this thread I will only concentrate on the numerical format.
The permission number might be three or four digits in length, ranging from 0 to 7.
When a three-digit number is used, the first digit denotes the file's owner's permissions, the second the file's group, and the last all other users.
The following numbers represent the write, read, and execute permissions:
• r (read) = 4
• w (write) = 2
• x (execute) = 1
• no permissions = 0
The permissions digit of a particular user class is the sum of the permissions values for that class.
Each digit of the permissions number can be an addition of 4, 2, 1, or 0:
• 0 (0+0+0) - There is no permission.
• 1 (0+0+1) - Execute permission only.
• 2 (0+2+0) - Only write access permissions.
• 3 (0+2+1) - Permission to write and execute.
• 4 (4+0+0) - Read-only permission.
• 5 (4+0+1) - Permission to read and execute.
• 6 (4+2+0) - Read and write access permissions.
• 7 (4+2+1) - Permission to read, write, and execute.
For example, if the permission number is set to 755 it means that the file’s owner has read, write and execute permission, file’s group has read and execute permissions, and other users have also read and execute permissions:
(simple yet powerful way to merge and organize data from multiple text files):
Learn more about the paste command in this master guide:
The paste command merges lines of files horizontally by combining corresponding lines from each file specified as an argument and separating them with tabs.
In this thread, we will guide you on how to utilize the paste command effectively.
How to use the paste Command
The paste command is not as commonly used as other Linux and Unix command-line utilities, but it can be incredibly useful.
The basename command in Linux prints the last element of a file path. This is particularly helpful in bash scripts where you only want the file name from a given file path.
In this thread, we will look at various examples to help us understand the basename command in Linux:
The "basename" function takes a filename and prints the last portion of it. If necessary, it can also remove any subsequent suffixes.
[+] Basename command syntax:
The basename command supports two syntaxes:
$ basename NAME [SUFFIX]
$ basename OPTION... NAME...
The basename command in Linux prints the last element of a file path. This is particularly helpful in bash scripts where you only want the file name from a given file path.
In this thread, we will look at various examples to help us understand the basename command in Linux:
The "basename" function takes a filename and prints the last portion of it. If necessary, it can also remove any subsequent suffixes.
[+] Basename command syntax:
The basename command supports two syntaxes:
$ basename NAME [SUFFIX]
$ basename OPTION... NAME...
pushd and popd are very underutilized commands, yet incredibly powerful.
These cmds give you the ability to manage your directory stack and easily switch between directories, making them a must-have tool for any Linux user looking to maximize their efficiency and productivity
In this thread, I'll show you how to use the pushd and popd commands to unlock the power of easy system directory navigation and streamline your workflow.
First let's understand what a Directory Stack is?
The Directory Stack is an ordered list of directories that have been accessed during navigation.
The contents of the Directory Stack can be viewed through the execution of the dirs command.
Logs are a critical component of system and application management, providing valuable info for troubleshooting, performance analysis, security analysis, and compliance.
This thread will go over a few tools that can help you parse & analyze logs effectively from the cmdline.
Linux logs are a valuable resource for system administrators, network administrators, developers, and security professionals.
They record a timeline of events on a Linux system, such as operating system events, application activity, and user activities and actions (for example log-in attempts). This information can be valuable for troubleshooting, performance analysis, security analysis, and compliance.