In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the knowledge points of Linux file permissions and directory management". In daily operation, I believe many people have doubts about the knowledge points of Linux file permissions and directory management. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what are the knowledge points of Linux file permissions and directory management?" Next, please follow the editor to study!
I. three identities of the linux file system
1), file owner
2), users in the same group
Users of the same user group can access the files of that user group
Each account can join multiple user groups.
Files in the same user group can also be set with different permissions, which can not be viewed by this group of users.
3), others
In addition to the file owner, the same group of users is someone else.
Ps: / etc/passwd records the accounts of all users
/ etc/shadow records the passwords of all users
/ etc/group records all group names
II. File attributes
Ls-al displays all file names and related attributes (including. Hidden file at the beginning)
Total 72drwxr xr-x 4 23 08:08 .drwxr-xr-x 5 root admin 170 4 13 21:24.-r-1 chaibozhou staff 9 3 21 12:00 .cfusertextencoding-rw-r--r--@ 1 chaibozhou staff 10244 4 23 11:25 .ds _ storedrwx- 5 chaibozhou staff 170 4 23 14:13 .trash-rw- 1 chaibozhou staff 3205 4 23 16:37 .bash _ historydrwxr -xr-x 6 chaibozhou staff 2044 4 15:51 .config
First column: file type and permissions
D: catalog file
-: ordinary files
L: link file
B: device file used to store data
C: device files for data transfer: mouse, keyboard
The next is a set of three characters that represent the permissions of the file owner, the same group of users, and other users, and the order of r, w, x is fixed.
Second column: how many filenames are connected to this node
Third column: the account number of the owner of this file / directory
Column 4: the user group to which this file belongs
Column 5: the size of this file, in b
Column 6: the creation date or modification date of this file
If you want a real and complete date and time, you can add a parameter to ls: ls-l-full-time
Ps: in the linux command, if the argument starts with -, it means that the following parameter is abbreviated; if it starts with--, it means that the subsequent parameter is complete. The full-time here is a complete parameter.
Ps: if you had installed linux in Chinese, the full date would have been displayed in Chinese, but Chinese could not be displayed in the command window, so garbled code would appear. You can only set it so that the date is displayed in English: lang=en_us
Seventh column: file name
III. The importance of linux authority
1. The function of protecting system files
Usually, only root administrators have read, write, and execute permissions for system files.
2. Provide data sharing function for team development.
The same development team can be set up as the same group of users so that files can be shared.
Commands for changing file attributes and permissions
1. Chgrp: change the user group to which the file belongs
Chgrp [- r] New user group directory or file: change the user group of the file under this path to "new user group"
Ps: this new user group must be under / etc/group, otherwise an error will be reported.
Ps: if the last parameter is directory, it means that only the user group of files in this directory will be changed to this.
Ps:-r means that if the last parameter is a directory, change the user group of all files in the current directory and all files in the subdirectory to this.
2. Chown: change the file owner
Chown [- r] username file or directory: change the file owner of all files in this directory to this username.
Ps: this user name must be under / etc/passwd.
This command modifies both the file owner and the user group: chown [- r] username: user group name directory / file
Chown [- r] username. User group name directory / file
Ps: because a user name can have a decimal point, the system will misjudge when a user name with a decimal point appears, so we usually use: to connect the user name and the user group name.
You can also change only the user group name: chown [- r]. User group name directory / file
When do I need to change the file owner and user group of the file?
When we copy a file to someone else, assuming that the file can only be read by the master, because the copy will copy the permissions and all the attributes of the file, then the other person will still be unable to access the copied file; so after the copy is completed, the first person should modify the attributes and permissions of the file.
Cp original directory / original file new directory / new file
1. Chmod: change the permissions of the file
There are two ways to change the permissions of a file, namely: to modify permissions with numbers, and to modify permissions with symbols.
A) use numbers to modify permissions
As we already know, permissions are made up of nine letters, and every three are in a group, indicating respectively the permissions of the file owner, the permissions of the same group of users, and the permissions of others. In this way, the three values of each group are added up to form a three-digit number. For example:
File owner: rwx = 4 / 2 / 1 / 7
User in the same group: rwx=4+2+1=7
Others:-= 0,0,0,0,0
So the order is as follows:
Chmod [- r] 770 files / directories
B) modify permissions with symbols
Chmod u/g/o/a + /-/ = r/w/x file / directory
Example: the file owner can read, write and execute; the same group of users and other users can read and execute.
Chmod upright RWX GOBLRX filename
Assuming that you didn't know the properties of the file and now only want all people to be able to execute the file, then:
Chmod axix file / directory
Assuming that you did not know the attributes of the file and now only want to make it impossible for the same group of users and other users to write, then:
Chmod go-w file / directory
The meaning of directory and file permissions
A file has rwx, which only means that the user can read, write and execute the contents of the file, that is, read the contents of the file, write to the file, and execute the file. But you don't have permission to delete this file.
A directory has rwx:
R: indicates that I have permission to read the directory structure, that is, I can view the directory structure through the ls command, but I cannot enter this directory through cd.
W: indicates that you have permission to change the directory structure, that is, you can create / delete / rename / move files / directories.
X: indicates that a user can enter this directory through cd.
Ps: whether a directory has x permission or not is very important. Without x permission, it means that you cannot enter this directory, that is, you cannot execute all the programs in this directory. There is a directory file as follows
Drwxr--r-- 3 root root 4096 date .ssh
The same group of users and other users of this directory file can only view the structure of the directory through ls, and cannot cd to this directory or execute all the programs in it.
When setting up the station, you should give some resources in the server to the outside world to access, but if a directory only has r permission, then you can only ls the structure of this directory, but you cannot access the data in this directory. If you want to open the data in the directory to others to browse, you must at least open r and x permissions, but w permissions cannot be easily opened. For example:
Suppose you have an account user1 whose home folder is: / home/user1,user1 has rwx permission for this directory file, and there is a data file under this folder with the following permissions:-rwx-- 1 root root... , then:
User1 belongs to other users for this file and does not have any permissions; but for this folder, it has rwx, can view the directory structure of the folder through ls, can enter the folder through cd, and can create, delete, rename and move files under this folder.
Use the root account to create a directory / dir under / temp with permissions of 744, and then create the file test under / dir.
Analysis: for the dir directory, the file master rwx, the same group users and other users can only r; that is, the file owner can ls the directory structure, can cd to this directory, and can create, delete, rename, and move files in this directory; while the same group users and other users can only ls this directory structure.
Ps: create directory: mkdir directory name
Ps: create empty file: touch file name
# use root identity to do the following cd / tempmkdir dirchmod 744 dirtouch dir/testchmod 600dir/test # for this file, the file owner 4x2: read and write, the same group and other users can do nothing # now switch identity to chaisu-chai # switch identity command: su-user name cd / templs-l dir # now the identity is chai, for this directory, only r permission That is, you can only ls the structure of this directory, but you cannot cd to this directory. Cd dir # directly reported an error: permission deniedexit # exited to your previous identity chown chai / temp/dir # change the file master of the dir directory to chai, and chai has rwx permissions cd / temp/dir # at this time chai can cd to dir, and you can create, delete, rename, move files rm test # delete test files in dir
Types of linux files
Ordinary documents-
1. Plain text file
You can view the normal file chai through cat / chai.
two。 Binary file
Executable files in linux (scripts and word batch files are not counted).
The cat just now is the binary file.
3. Data format file
It is a file with a specific format that will be read when the program is running, such as a configuration file.
For example, when a user logs in to linux, the login log will be recorded in the / var/log/wtmp file, which is a data format file.
Ps: data format files need to be read with last, and garbled code will occur if you read them with cat.
Directory file d
Connection file l
It's a shortcut under windows.
Device file
1. Block device file b
Device files used to store data, such as hard disks and floppy disks.
two。 Character device file c
Device files used for data transmission, such as keyboard and mouse.
3. Socket s
The device file is in / var/run.
4. Pipeline p
Used to solve the error problem caused by multiple programs accessing a file at the same time.
VI. Linux extension
Linux does not have an extension, and whether a linux file can be executed depends on whether the file has the permission x in its properties.
However, in order to enhance the readability of the file, we still add an "extension" to the file.
* .sh represents a script or batch file.
* z, * .tar, * .tar.gz, * .zip, * .tgz they are all compressed files.
Ps: the permissions of files downloaded from the Internet are likely to change, so when the downloaded file doesn't run, check to see if its permissions have x.
VII. Restrictions on documents by linux
Linxu uses the ext2/ext3 file system by default, and the length of the file name is limited to:
The maximum length of a single file or directory name is 255 characters
The maximum length of a complete file or directory name is 4096 characters.
Avoid some special characters when naming files.
VIII. Linux directory configuration standard
As there are so many manufacturers developing linux distribution, it is necessary to standardize the file system developed by these manufacturers, so there is a file system configuration specification: filesystem hierarchy standard=fhs.
There are four types of directory specifications for fhs:
1. Shareable directories
Indicates that this directory can be shared with other hosts on the network.
2. Directories that cannot be shared
Device files or socket files related to programs that can only be run on your own machine cannot be shared with other hosts because they are only related to your own machine.
3. Immutable directory
No matter what kind of distributions, these directories are fixed, and the file data in the directory is basically unchanged. Generally, these directories store function libraries, system configuration files, and so on.
4. Changeable directory
The data of the files in these directories changes all the time, such as log files.
The root directory is the most important directory of the whole system, all other hungry directories are derived from the root directory, and the root directory is also related to boot, restore, system repair and other operations.
Fhs recommends that the root directory be small enough and that the application should not be placed in the same partition as the root directory.
Fhs recommends that you must have these directories under the root directory:
-/ bin: commands in the bin directory can be used by all accounts. General commands are: cat, chmod, chown, date, mv, mkdir, cp, bash
-/ boot: release the files used by the opportunity
/ dev: any device is stored in this directory as a file
-/ etc: the main configuration files of the system are placed in this directory. The properties of files in this directory are accessible to ordinary users, but only root can modify them. Fhs recommends that executables should not be placed in this directory.
/ home: the default user home folder of the system.
~ represents the home folder of the currently logged in user
~ chai represents the home folder of the specified user
-/ lib: store the library functions used when booting and the library functions that will be used by the commands in / bin and / sbin directories.
-/ media: places device files that can be deleted. Such as: floppy disk, CD-ROM.
-/ mnt: if you want to mount some additional devices temporarily, put them in this folder.
-/ opt: the directory where third-party software is placed
-/ root: home folder of the system administrator
/ sbin: place the commands needed during the boot process, including booting, repairing, and restoring the system
-/ srv: an abbreviation for service, which stores some data needed for network services.
/ tmp: the place where the general user executes the program to store data temporarily. Anyone can access it, so clean it up regularly. Fhs recommends that this directory be cleared when distributions is powered on.
Other important directories:
-/ lost+found: a directory generated by using the ext2/ext3 file system. When an error occurs in the file system, some missing fragments are placed in this directory.
/ proc: is a virtual file system, that is, its data is stored in memory and does not take up hard disk space.
/ sys: is also a virtual file system that records kernel-related information.
When booting, only the root directory is mounted, and the partitions where the other directories are located are mounted after the system boot is complete. Therefore, the directory related to the boot process must be in the same partition as the root directory. Directories that must be in the same partition as the root directory are:
/ etc: configuration file
/ bin: important execution file
/ dev: required device files
/ lib: library functions needed to execute files and modules required by the kernel
/ sbin: important system execution file
/ usr directory
= unix software resource, which is the directory where the critical resources of the operating system are placed.
Fhs suggests that all software developers should place their data in a subdirectory of this directory instead of creating a separate directory.
This directory is equivalent to c:\ program files under windows.
/ var directory
/ usr places large-capacity files needed to install the program, while / var will gradually occupy the directory of the hard disk during the execution of the program. Such as: cache, log, etc.
Each directory can not only mount the local file system, but also use the file system on the network. You can use the network file system server = nfs server to mount the specified directory of the network mountain.
At this point, the study of "what are the knowledge points of Linux file permissions and directory management" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.