Linux running time (4) (laruence's Private food notes)
Source: Internet
Author: User
Linux running time (4) (laruence's Private food note)-Linux general technology-Linux technology and application information. The following is a detailed description. Recently I practiced POJ, And the Linux progress has fallen. I feel like a frog at the bottom, and I know little about it. Learning, we have to make one step at a time. You are impatient with your own changes.
Below are the notes:
Linux file attributes and directory Configuration:
1. Users and user groups:
Each file has three permissions: User, user group, and others. Root can view any file with the highest permissions. The/etc/passwd file records root Information, the/etc/shadow file records password information, and the/etc/group file records user group information. Do not delete the three files.
2. Linux File Permissions
[Root @ linux ~] # Ls? Al (list attributes of all files)
Information listed in sequence includes: file attributes, connections, file owner, file user group, file size, latest file modification time, and file name
A. file attributes: file type (1), file owner attributes (3), file user group attributes (3), and others attributes of this file (3)
The first property -- file type: [d], directory;
[-]: File;
[L]: connection file;
: Interface devices available for storage in Device Files
[C]: serial port device in the device file, such as keyboard and mouse
The following attributes are composed of three digits: r: readable.
W: writable
X: executable
NOTE: If other users without the root account cannot execute any command (that is, they do not have the x permission), they will naturally not be able to access. Even if you have the r permission, you cannot execute a read task because the read task cannot be executed even when you access the system. In windows, whether a file can be executed depends on the extension. However, in Linux, whether a file is executed is not related to the file name depends on whether the file has the x attribute.
[-] [Rwx] [r-x] [r --]
1 234 567 890
1: indicates that the file name is a directory or file.
234: permissions of the owner (read, writable, and executable)
567: Same user group permissions (read and executable above)
890: other user permissions (read only)
B. The second column indicates the node occupied by the connection (I-node): This is related to the link file.
C: indicates the owner of the file.
D: column 4 indicates the owner's user group:
If a user group code is testgroup and the three member codes are test1, test2, and test3, if the file belongs to test1, test2 and test3 also have the Read and Write power.
E: File Size
F: The file creation date or the latest modification date: if Linux is installed in Chinese, the default language may be changed to Chinese. This column is garbled because Chinese characters cannot be displayed on a CLI terminal. Modify the/etc/sysconfig/i18n file, change "LC_TIME: To" LC_TIME = en ", and log on again to get the date displayed in English.
G: Column 7 is the file name of this file: if there is a ". ", indicates that the file is" hidden file ". Because the ls-al parameter is available, the hidden file is listed. If you only enter ls, add"..
2.2: Change File Permissions
Chgrp: Change the user group to which the file belongs
Chown: changes the file owner;
Chmod: changes the attributes and SUID of a file.
A: Change the user group to which the chgrp belongs.
First, the user group name to be changed must exist in/etc/group; otherwise, an error is displayed. Assume that you have logged on to FC4 as the root user, there is an install in your main folder. log File. the user group method for changing this file is as follows: the user group named users is in/etc/group, and the testing user group is no longer in this folder. In this case, you try to change the user group to users and testing.
[Root @ linux ~] # Chgrp [-R] dirname/filename .....
Parameters:
-R: Perform recursive changes, that is, update all files and directories under the subdirectory to the user group. It is often used to change a directory.
For example:
[Root @ linux ~] # Chgrp users install. log
[Root @ linux ~] # Ls-l
-Rw-r -- 1 root users 68495 Jun 25 install. log
[Root @ linux ~] # Chgrp testing install. log
Chgrp: invalid group name 'testing' <= error message ~ The user group name cannot be found ~
B. Change the file owner, chown
If you want to change the owner of all subdirectories or files in the directory, add the-R parameter directly:
[Root @ linux ~] # Chown [-R] Account name: file or directory
[Root @ linux ~] # Chown bin install. log
[Root @ linux ~] # Ls-l
-Rw-r -- 1 bin users 68495 Jun 25 install. log
[Root @ linux ~] # Chown root: root install. log
[Root @ linux ~] # Ls-l
-Rw-r -- 1 root 68495 Jun 25 08:53 install. log
Eg:
Copy the. bashrc file to. bashrc_test and send it to the bin user.
[Root @ linux ~] # Cp. bashrc. bashrc_test
[Root @ linux ~] # Ls-al. bashrc *
-Rw-r -- l root 395 Jul 4 :45. bashrc
-Rw-r -- l root 395 Jul 13 :31. bashrc_test
. Bashrc_test still belongs to the root user. Even if the file is given to the bin user, it cannot be modified. Therefore, the owner and user group of the file must be modified.
C. Change nine attributes: chmod
There are two ways to set attributes: numbers or symbols.
1. Change the File Permission for the numeric type
There are nine basic attributes of the Linux File, namely the read/write/excute attributes composed of owner, group, and others. Three of these attributes are a group, you can use numbers to indicate attributes:
R: 4
W: 2
X: 1
Accumulate the three attributes (r/w/x) in the same group. For example, if the attribute is [-rwxrwx ---], it is: owner = rwx = 7, group = rwx = 7, others = --- = 0;
The syntax of the command chmod for modifying attributes is as follows:
[Root @ linux ~] # Chmod [-R] xyz file or directory
Xyz: The permission attribute of the numeric type just mentioned. It is the sum of the rwx attribute values.
-R: Perform recursive changes to update all files and directories in the same subdirectory to this user group.
To open all attributes of the. bashrc file, run the following command:
[Root @ linux ~] # Ls-al. bashrc
-Rw-r -- 1 root 395 Jul 4 :45. bashrc
[Root @ linux ~] # Chmod 777. bashrc
[Root @ linux ~] # Ls-al. bashrc
-Rwxrwx 1 root 395 Jul 4 :45. bashrc
2. Change the File Permission of the symbol type
There are a total of nine attributes, namely user, group, and others, which can be expressed by u, g, and o. A Indicates all.
Chmod u \ g \ o \ a + (ADD) \-(remove) \-(SET) r, w, x file or directory
If you want to set the attribute of a file to "-rwxr-xr-x", user (u): Has the readable, writable, and executable permissions; group and others (g \ o ): has the permission to read and execute.
Therefore:
[Root @ linux ~] # Chmod u = rwx, go = rx, bashrc
[Root @ linux ~] # Ls-al. bashrc
If you want to remove attributes without changing other attributes, for example, to remove all attributes:
[Root @ linux ~] # Chmod a-x. bashrc
[Root @ linux ~] # Ls-al. bashrc
If you allow a program to have execution permissions without knowing what the original permissions of the file are, you can use chmod a + x filename to grant the program execution permissions.
2. Significance of directory Properties
The preceding figure shows the features of common files. For example, for directories, r, w, and x, the meanings are as follows:
R (read contents in directory): indicates that you have the permission to read the directory structure list. You can use the ls command to list the contents of this directory.
W (modify contents of directory): indicates that you have the permission to change the directory structure list, that is, to create a new file and directory; delete existing files and directories (no matter who the files belong to), rename existing files or directories, and move the files and directories in the directories.
For normal identity users (assuming the user name is name), the name can delete files created by the root in the name directory.
X (access directory): x depends on whether the directory can be accessed.
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # mkdir testing (mkdir is a command used to create a directory, short for make directory, this line uses the root identity to create a directory named testing under/tmp .)
[Root @ linux tmp] # chmod 744 testing (change the permission of this directory to 744, and the owner of this directory is root)
[Root @ linux tmp] # touch testing/testing (touch is used to create a file without content)
[Root @ linux tmp] # chmod 600 testing/testing
[Root @ linux tmp] # ls-al
If the user account is name, change root to name:
[Root @ linux tmp] # su name
[Name @ linux tmp] $ ls-1 testing (when the user using the system changes to name, # changes to $)
Total 0
? ---------? ? ? ? ? Testing
[Name @ linux tmp] $ cd testing <= name
Bash: cd: testing/: Permission denied
[Name @ linux tmp] $ exit
[Root @ linux tmp] # chown name testing (exit is used to exit su. We set the owner of the testing directory to name, and the name becomes the owner.
[Name @ linux testing] $ rm testing (rm: remobe write-protected regular empty file 'testing '). (It can be deleted after testing. Because the empty testing folder created under tmp/testing is created under the name directory, it can be deleted directly. However, testing in tmp cannot be deleted, it is created by the root user.
2. linux File Types and extensions
A. File Type
1> regular file: The first attribute displayed by ls-al is [-]. It can be divided:
1. plain text files (ASCII): Almost all configuration files belong to this file type. Use the command cat ~ /. Bashrc can see the content of the file (cat reads the file content)
Ii. binary: the executable file in linux is in this format. The command cat is a binary file.
3. data Files: Some programs read certain files in specific formats during running, and those files in specific formats can become data files. For example, when a user logs on to linux, the logon data is recorded in the/var/log/wtmp file, which is a data file that can be read by the last command. However, garbled characters may occur when cat is used. Because it belongs to a special format file.
2> directory: The first attribute is [d]
3> link: similar to the shortcut in Windows. The first attribute is [l].
4> device and device Files: files related to external storage are usually concentrated in the/dev directory. There are two types of files:
1. block Device Files: an interface device that stores data for system access. In simple words, it is a keyboard. The first attribute is;
2. character (character) Device File: it is the interface device of the serial port, such as the keyboard and mouse. The first attribute is [c].
5> sockets (sockets): these types of files are usually used for network data connections. You can start a program to listen to the requirements of the client, and the client can communicate with each other through a socket. The first attribute is [s], which is usually seen in the/var/run directory.
6> pipelines (FIFO, pipe): FIFO is also a special file type. The main purpose is to solve errors caused by simultaneous access to a file by multiple programs, the first attribute of FIFO is [p].
The device file is an important file in the system. It is recommended that you do not modify it.
B. linux File Extension:
Generally, Linux files do not have an extension. However, the execution can be different from the execution successful. Install. log is a plain text file. If the permission is changed to-rwxrwxrwx, since its content does not have executable data, x indicates that the file has the executable ability, but if the execution is successful, you must check the content of the file.
The linux extension does not actually help. However, you can use the extension to understand the content of the file. There are several common extensions:
1. *. sh: the batch processing file (scripts, script). Because the batch processing file is written in shell, the extension is. sh.
2. * Z,. tar, .tar.gz, *. zip, *. tgz: the compressed file that has been packaged. This is because the compression software gets its related extension.
3..html, *. php: webpage-related files, indicating the HTML syntax and PHP syntax respectively.
The file attributes uploaded from the network to the LINUX system will change. If the attributes are not changed, they may not be executed. When the file name starts with the decimal point ".", it indicates that the file is "hidden file ". Because-option and other parameters are often used in commands, it is best to avoid naming the names starting with-or +.
6.4
6. Linux directory Configuration
A. Linux directory configuration Standard FHS (Filesystem Hierarchy Standard, file system level Standard): it regulates what files should be stored in the main directories under the root directory.
FHS defines two levels of standards. The first layer is what file data should be stored in each directory under the/directory, for example, the/etc should be placed in the setting file, /bin and/sbin should be placed with executable files. The second layer is defined for the subdirectories of the/usr and/var directories. For example, place/var/log in the system logon file and/usr/share in the shared data file. (That is, FHS defines the file data to be placed in the directory at the top/and sub-layers (/usr,/var). Other Sub-layer directories can be configured by developers ).
Each directory can use not only the local partition file system, but also the Network File System. You can use the Network File System (NFS) server to load a specific directory.
Absolute path: the name of the file or directory written from the root directory;
Relative Path: the relative location of the current path
.: Indicates the current directory, which can also be expressed ./.
..: Indicates the directory of the previous layer. It can also be represented ../.
Previous: indicates the previous working directory.
~ : Indicates the Home Directory of the current user identity
~ Account: The Home Directory of the account user.
A single file or directory can contain a maximum of 255 characters
The complete file name containing the full path name and directory (/) is 4096 characters)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service