Device, Linux file system, FHS ③ Memorandum (file permission and owner management, hard link and symbolic link creation, system file search, proper file placement)

Permissions on files and directories are called permissions. There are three permissions: read, write, and execute. ① Read See the contents of a file such as cat more. See the contents in the directory. ls find

② Write to file Create a new file in the vi directory. Delete → touch mv rm

③ Execution Run the file. Access files in the directory cd

rwxrwxrwx 421421421 But it seems to be represented by 777.

ls ー l

Owning users, groups, permissions (access rights), etc. are set for files and directories. You can check this information with the ls -l command.

ls -l /etc/passwd -rw-r--r--. 1 root root 1929 Jan 18 14:17 /etc/passwd I remember this because it's a cliché. Owned user and group is root The group and other users have read permission.

-rw-r--r-- 1 test staff 24 Jul 21 13:38 index.html Is it a test user staff group?

chmod command

Set the SGID so that no matter who runs the program, it will run with the privileges of the group that owns the program. SGID is one of the special permissions. Use the chmod command to set the normal permission value plus 2000, or add the permission "s" to the group (g + s).

・ SUID By setting it in the executable file, no matter which user executes the program, it will be executed with the authority of the program's: point_up: owning user. The setting is the chmod command, which sets the normal permission value plus 4000, or adds the permission "s" to the owning user (u + s). A typical program with this set is the "passwd" command.

・ SGID By setting it in the executable file, it will be executed with the authority of the program's: point_up: owning group regardless of which user executes the program. The setting is the chmod command, which is the normal permission value plus 2000, or adds the permission "s" to the owning group (g + s).

・ Sticky bit By setting it in a directory, even a user who has write permission for that directory cannot delete files other than those owned by him / her. To set it, use the chmod command to set the normal permission value plus 1000, or add the permission "t" to other users (o + t). The "/ tmp" directory is a typical directory where this is set.

名称未設定.png33.png

umask Use this to set default permissions when creating a new file or directory. 666 --Mask value = default file permissions 777 --Mask value = directory default permissions

chown = chgrp Used to change the owner user or group of the specified file or directory. chown [-R] username: group name file or directory The part of: is. But OK You can go with groups and users!

This is a group only = Chgrp [-R] Group name File or directory

The "-R" option can be used to recursively change the owner user or group of the specified directory and the files under it.

ln command

This is for creating a link. ln Link source Link destination Optional -s to create a symbolic link.

① Hard link Duplicate a file. Then give the resulting file a name. Even if you delete the original file, the nickname will not be deleted. Both are deleted by deleting the nickname and the original file. ② Symbolic link Feeling that it will be relayed in between Feeling to order / order through this guy

The inode number does not change when you create a hard link. The number of hard links will increase.

First character displayed by ls -l

The permission character at the beginning indicates the file type.

find command

This command to search for files and directories under the specified directory

Search for file type by -type l is a symbolic link d is a directory f is a file -maxdepth hierarchy Search up to the specified hierarchy -mindepth hierarchy Search below from the specified hierarchy -atime Search by last access date -mtime Search by last updated date -print Display search results separated by line breaks -print0 Display search results separated by null characters (¥ 0) -name Search for files by file name. -perm access right Search for access right -size size File size search -exec command name Execute the command for the search result file

名称未設定.png123456.png

which whereis Find the location of the specified command Search from the directory set in which environment variable PATH Whereis Search in the standard directory where commands are stored in Linux. In other words, both are displayed with absolute paths

locate A command to search files at high speed using the search DB Search with locate httpd.conf etc.

/ usr directory

Programs that are not needed for startup are stored. / usr / shere / man manual / usr / bin General user commands that are not required to start the system / usr / sbin System administration commands that are not required for system startup

umask = change default permissions

Command to set default permissions when creating a new file or directory Set a mask value to determine the default permissions for newly created files and directories. The mask value is set for each user.

The default permissions used when the mask value is 0 are "666" for files and "777" for directories. These values minus the specified mask value will be set as the new default permissions. For example, if the mask value is 022, the default permissions for files and directories are "644 (666-022)" and "755 (777-022)", respectively.

All mask values below 0 are 0.

Hard link

A hard link is one of the functions of a file system, in which a file or directory entity is given multiple names so that each of them functions equally as an actual file name / directory name. It can be used on UNIX-based OS and Windows.

You cannot create hard links for directories. Can be created as long as it is a directory symbolic link.

updatedb The configuration file is /etc/updatedb.conf! Update the search database used by the locate command.

FHS A standard that defines a standard Linux directory structure that does not depend on the distribution. Distribution → Linux as an OS, or its distribution form. (I don't want to get only the kernel)

In the old days, distributions used their own directory structure. Therefore, the installed ones may be different for each distribution. FSH was created to eliminate such problems. You have to know exactly where you put it, but it doesn't mean that you won't be placed somewhere like before.

The following is a summary of the directory layout under "/ usr" specified by FHS. 名称未設定.png 11111.png

Symbolic link

A symbolic link is like a shortcut in Windows, a link that points to the location of the original file. The information that the symbolic link has is only the path information "where is the original file (directory)".

Deleting File1 (unless there is another hard link with the same inode number) deletes the actual file, but File2 remains. However, in that case, when accessing File2, an error will occur because there is no linked File1.

① Can be created between different file systems Since the symbolic link only has the location (path) information of the original file, it is possible to create a different file system! (2) If you check with the ls command, l will appear at the beginning. ③ inode number The inode number is different from the original file because the symbolic link does not refer to the actual file.

/etc/ld.so.cache Files used to find the location of shared libraries when running the program

chown and chgrp

chown [-R]: group name file or directory chgrp [-R] group name file or directory

Use the chown or chgrp command to change only the owning group. As in the question, both can be executed by the root user, but if the group to which the user belongs, even a general user can change it.

-Chown -R: staffgroup dir → A command that can change not only the owning group but also the owning user ・ Chgrp -R staffgroup dir → Owned group only

Recommended Posts

Device, Linux file system, FHS ③ Memorandum (file permission and owner management, hard link and symbolic link creation, system file search, proper file placement)
Device, Linux file system, FHS ① Memorandum Creation of partition and file system / maintenance of file system integrity
Device and Linux file system