Linux chmod command parameters and usage details -- file folder permission setting command

Use permission: All users

How to use:  chmod  [-cfvR] [--help] [--version] mode  file ...

Description: Linux/Unix file access permissions are divided into three levels: file owner, group ,other. Using chmod can be used to control how files are accessed by others.

Mode :

Permission setting string, the format is as follows: [ugoa...][[+-=][rwxX]...][,...], where u represents the owner of the file, g It means that the owner of the file belongs to the same group (group), o means other people, and a means all three.
+ means to increase the authority, - means to cancel the authority, = means to set the only authority.
r means readable, w means writable, x means executable, X means only if the file is a subdirectory or the file has been set to be executable.
-c : only show the change action if the file permissions have been changed
-f : don't show an error message if the file permissions cannot be changed
-v : show the details of the permission change
-R : for all files in the current directory Make the same permission changes as subdirectories (that is, change one by one in a recursive manner)
--help : show help instructions
--version : show the version

Example: make the file file1.txt readable by everyone:
chmod ugo+ r file1.txt

makes the file file1.txt readable by everyone:
chmod a+r file1.txt

sets the files file1.txt and file2.txt as the owner of the file, which can be written by the same group as they belong, but not by other people:
chmod ug+w,ow file1 .txt file2.txt

Make  ex 1.py executable only by the owner of the file:
chmod u+x ex1.py

Make all files and subdirectories in the current directory readable by anyone:
chmod -R a+r *

In addition, chmod can also use numbers to represent permissions. For example, chmod 777 file
syntax is: chmod abc file

where a, b, and c are each a number, representing the permissions of User, Group, and Other, respectively.

r=4, w=2, x=1
If you want the rwx attribute, then 4+2+1=7;
if you want the rw- attribute, then 4+2=6;
if you want the rx attribute, then 4+1=7.

Example:
chmod a=rwx file

and
chmod 777 file

have the same effect.
chmod ug=rwx,o=x file has the same effect as

chmod
771 file . If chmod 4755 filename is used, this program can have root privileges Command name:  chown





Permission: root

Usage: chmod [-cfhvR] [--help] [--version] user[:group] file...

Description: Linux/Unix is ​​a multi-player multi-tasking system, and all files are owned By. The owner of the file can be changed using chown. Generally speaking, this command is only used by the system administrator (root). Generally, users do not have permission to change other people's file owners, nor do they have permission to change their own file owners to others. Only the system administrator (root) has such privileges.

count:

user : the user ID of the new file owner group : the user group (group) of the new file owner -c : if the file owner has indeed changed, only display the change action -f : if the file Owner cannot be changed and don't show error messages -h : make changes only to links, not files the link actually points to -v : show details of owner changes -R : make changes to all files in the current directory Make the same owner change as subdirectories (ie, change one by one in a recursive manner) --help : show helper instructions --version : show the version

Example:
set the owner of the file file1.txt as the user jessie of the users group :
chown jessie:users file1.txt

set the owner of all files and subdirectories in the current directory as users of the users group lambport :
chmod -R lamport:users *
-rw------- (600) -- Only the owner has read and write permissions.

-rw-r--r-- (644) -- Only the owner has read and write permissions; group users and other users have only read permissions.

-rwx------ (700) -- Only the owner has read, write, and execute permissions.

-rwxr-xr-x (755) -- The owner has read, write, and execute permissions; while group users and other users only have read and execute permissions.

-rwx--x--x (711) -- The owner has read, write, and execute permissions; while group users and other users only have execute permissions.

-rw-rw-rw- (666) -- All users have file read and write permissions. This approach is not advisable.

-rwxrwxrwx (777) -- All users have read, write, and execute permissions. even more inadvisable.

The following are two common settings for directories:


drwx------ (700) - Only the owner can read and write in the directory.

drwxr-xr-x (755) - All users can read the directory, but only the owner can change the contents of the directory. The representative number of
su id is 4. For example, the result of 4755 is -rwsr-xr-x
The representative number of sgid is 2, for example, the result of 6755 is -rwsr-sr-x
sticky bit represents the number is 1, for example, the result of 7755 is -rwsr-sr-t


Reference: http://www.linuxso.com/command/chmod.html



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326222005&siteId=291194637