CentOS file attributes, permissions, umask, find

Source: Internet
Author: User
Tags bit set

CentOS file attributes, permissions, umask, find
Task: 2.14-2.27 file or directory permissions chmod, chown, umask, lsattr, chattr, set uid, set gid, stick bit, the owner of the find file and the Directory and file of each Linux in the group have the owner and group permissions. Owner, group, and non-group users others have their respective permissions. Run the ls-l command to view the permissions of directories and files. Example:-rw-r --. 1 root 0 October 28 15:36 1.txt drwxr-xr-x. 2 root 6 15:35, December 6, October 28 the first column of abc. "d" indicates a directory, "-" indicates a common file, "l" indicates a link, and "B" indicates a block file, such as a hard disk, c starts with a character device file, such as a keyboard and mouse, and s begins with a socket file, which is used in mysql. Each three digits in the next nine digits is a segment, indicating the permissions of the owner, group, and others respectively. R indicates readable, w indicates writable, and x indicates executable. Note that the execution permission is required to open the directory, so the default file permission of the system is rw-r --, and the default directory permission is rwxr-xr-x, the r permission of the directory must be accompanied by the x permission to make sense. For ease of description, it is required that rwx use the corresponding Arabic numerals for computing permissions, r is 4, w is 2, x is 1, so the default file permission is 644, and the default directory permission is 755. Chgrp is used to change the group. To change the group to which a directory belongs, you must add-R to the command to change the group permissions of its cascading subdirectories and sub-files. Chown is used to change the owner. You can also modify the group in the parameter. To change the owner of a directory, you must add-R to the command to change the permissions of its cascade sub-directories and the group to which the sub-files belong. Example: chown-R user1: group1 dir1 // change the owner of directory dir1 to user1 and group to group1. Chmod is used to change the permission. The default permission for folders is 755, and the default permission for files is 644. Example: chmod 750 dir1 // you can change the dir permission to rwxr-x --- umask. The value of chmod dir1 indicates the permission that is required to be revoked when all permissions are granted, if all permissions of the default directory are rwxrwxrwx and all permissions of the file are rw-, the default permission is: rwxrwxrwx----- w -- w-= rwxr-x-r-x // directory rw------- w -- w-= rw-r -- // common the file umask is the value subtracted from the file, here is 022. If you change the umask value to 002, for example, by using the umask 002 command, the default permissions of files and directories will also be changed accordingly. Chattr and lsattr chattr are used to increase or decrease permissions, add + permissions, and subtract-. Common permissions include I and: I indicates that you cannot write, delete, rename, and set link a. It indicates that you can only append the object and cannot delete the object. The example is as follows: chattr + I dir2 // Add the I permission for the Directory dir2 chattr-I dir2 // Add the permission for the Directory dir2 minus the I permission chattr + a dir2 // Add the permission for the Directory dir2 lsattr and ls usage similar, special permissions for reading files or directories. Optional parameters include a and R.-a indicates that hidden files are listed together, and-r indicates that the properties of subfolders and folders in the connected directory are listed together. Set uid, set gid, and stick bit set uid allow common users to temporarily have the owner permission when executing binary files. For example, passwd has this permission. Use chmod u + s/usr/bin/ls // Add s permission chmod u-s/usr/bin/ls // remove s permission set gid is similar to set uid, when used as a binary file, the file can have group permissions during the execution phase. When used as a directory, any files created in this directory have the same group as the group to which the directory belongs. Chmod g + s/usr/bin/ls // Add s permission chmod g-s/usr/bin/ls // remove s permission sometimes, set uid has the upper-case S permission, because it does not have the x permission. After adding the upper-case x permission, the lower-case s will be changed. The stick bit is called the delete-prevention bit. It is represented by t in the permission and the command is chmod o + s dir. In general, when the directory where the file is located has the write permission, the file can be deleted. However, if the directory with the write permission has the t permission, the file under this directory cannot be deleted. The find which command can be used to view the PATH strength of executable commands in the environment variable PATH. Such as which ls. To use the locate command, install mlocate in advance, generate a file list library, and search and use it. Yum install-y mlocate // install mlocateupdatedb from yum // you need to update the file list library before you can start searching for locate ls // find the format of the lsfind command: find [path] [parameter]-atime + n/-n // indicates the file with the last access time greater than/less than n days-ctime + n/-n // indicates the last modification time (change content, permissions, links, etc) files greater than/less than n days-mtime + n/-n // indicates files whose last content modification time is greater than/less than n days find/tmp/dir/-mtime-1 // indicates that the following command can be used to view the mtime of a file that has been modified within one day, ctime and atime: stat can search for files of the specified type by adding the-name and-filetype parameters. Filetype includes f, B, c, d, l, s, and other types. Find/tmp/-name test // search for a file named test find/tmp/d // search for a directory file

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.