Linux Tutorial Series: Namei Usage, Unique and Great Linux Command
Linux is a diverse platform that can use a large number of commands in its shell at once, among other things. These commands have different uses and purposes. When working in Linux, you need to find out and understand some specific files, their owners, paths, and what’s between certain folders. One of the unique and great commands is the “namei” command for Linux systems. So far, the namei command was used to learn more about a specific directory, such as path, location, etc. So today we will discuss the namei command in the Ubuntu 20.04 Linux shell.
With the terminal open, we are ready to use the command for a specific purpose. For these reasons, you must be aware that the namei command uses a number of flags in it. If you want to know more about the namei command, just type “namei” in the shell and you will see the command information.
The namei command can usually be used when permission problems arise, it can be used with any UNIX file such as symbolic links, files, directories, etc. Use namei to list information about all components in a path, including symbolic links. Information including permissions, owners, and groups can be displayed through parameters.
Simple command:
The namei command can be used in the shell without any flags in it to simply list path values. To do this, you need to define the path to a specific target in the shell. You can see from the image below that the path has been divided into blocks. The “d” part shows all directories of a specific path, while the “-” part shows the target file.
01: Align the path vertically
Let’s say you want to vertically align the path of a specific file found in your system’s home folder, but you don’t know how to do that. Therefore, you need the namei command to get help. You have to use it with the “-v” flag to make its path vertically aligned from start to finish. You must also provide the path to this file in the command. After using this command by providing the path to the “linuxmi.txt” file, we got the following result.
On the first line, “f:” indicates that the path to the file is specified before it. The “d” stands for directory, which means that all names before the “d” are directories. The “-” sign indicates that the preceding name is the file you need, that is, a normal file. The “f” symbol means that the path can only point to a regular file.
Let’s vertically align another file using the same namei command. So we updated the path given in the command this time, i.e. different from the last time. We added the path to the “linuxmi.cc” file in the “Downloads” folder of the system. The “-v” flag is used to vertically align the path to this file in the shell. You will see that it will display the original path on the first line of output before the “f”. After that, it will vertically align the list of all directories. Finally, it will display the filename before the “-” sign.
02: Find owner and group
The namei command is useful for finding out the real owner and group of a particular address given in it. The owner and group must be some Linux user who may or may not be currently logged in. So here we use the name- command with the “-o” flag to find out the owner and group of each section of the path given in the instructions below. First, it will show the overall address in the output before the “f” that it is pointing to some regular file. This path now contains a total of three directories and 1 regular file. The first two directories have the same owner and group, that is, the owner of the next directory under “root” is the user “linuxmi”, which also belongs to the “linuxmi” group. Regular files also belong to user “linuxmi”, i.e. the owner and group here is “linuxmi”.
Let us find out the owner of another file “linuxmi.cc” using the same namei command in Ubuntu 20.04 system. We used the “-o” flag in the file path. The output shows that the first two directories belong to the “root” user and group. The last two directories and regular file “linuxmi.cc” belong to the currently logged in user, linuxmi, you can also make changes to these directories and files.
03: Long list information
If you want to list all other information about a specific path, that can also be done with the namei command in the shell. That is, you can list all read, write, and execute permissions of a path in the shell with the namei command. To do this, you have to use the “-l” flag to list the information in the namei command and the paths mentioned in it. After executing the namei command with the “-l” flag, we got the result shown in the image below. The output of this command shows a context such as “drwxr-xr-x” and its owner and group information. The character “d” indicates the specific location of the directory. The first three “rwx” characters indicate that the owner has all read, write, and execute permissions on the file. “r_x” indicates that the group and other users of this system have read and execute permissions, but no write permissions. These permissions apply to all three mentioned directories. The file only gets read and write permissions for its owner and group, i.e. “rw-rw-”, and other users can only read it. That is, “i—”.
We have used the namei list command to get another path to the file “linuxmi.cc”. The output of this command shows the same output as the above file “linuxmi.txt” path. These directories contain the same permissions, owner, and group information. This file also contains the same owner, group and permissions as the previous “linuxmi.txt” file.
If the user just wants to list the permissions assigned to the owner, group, and other users, this can also be done using the namei command. You just need to update the flags in the command. So just replace the “-l” with the “-m” flag. In the output, you can see that it only shows information about permissions.
in conclusion:
This article briefly describes how to use the namei command in the Ubuntu 20.04 system shell to achieve certain things like display directories, files and directories in vertical order, the owners of those files and folders, the groups these files and folders belong to, assigned to these owners, groups and user’s permissions, all these commands are easy to implement in any Linux distribution.
From: Linux Fans
Link: https://www.linuxmi.com/linux-namei-command.html
> > > ## Follow us > > > Linux Corporation > > > star “ > > > Get technical dry goods every day, let us grow together > > > Cooperation contact: root@linuxidc.net > > >
Follow us
Linux Corporation
star “
Get technical dry goods every day, let us grow together
Cooperation contact: root@linuxidc.net
終端大師 Terminal Master