File permissions

From English Wiki
Revision as of 04:10, 15 August 2022 by Kentlee7 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The following are common file and directory permission commands and codes in Linux.

1 File Permission commands

Command Function
chmod -c -R Assign a file read, write, and execute permissions
chmod -R 777 [dir] Assign full permission recursively to the directory and all sub-directories
chmod -x file Remove the execution permission of any file
chmod [±]t dir Add or remove stticky bit, whereby files in a directory can only be renamed or removed by owner or root
g|a] +/- [r|w|x] Change privileges for user, group, or all to read, write, or execute
chmod 755 file Grant the file owner read, write, and execute permissions; othres have only read and execute permissions
chmod 766 file Grant the file owner full read, write and execute permissions, while group and other users can only read and execute.
chmod 777 file Grant full (read, write, and execute) permission to everyone
chmod u-x Remove executable privileges from user
chmod u+x Assign executable privileges to user
chown -c -R Change ownership of a file; changes apply recursively to directory contents
chown -R user:group dir Change owner and group ownership of the directory and all sub-directories
chown user file Change ownership of a file
chown user file Change the ownership of a file
chown user:group file Change user and group privileges of a file
chown root /u Transfer ownership of a file to the root user
touch -a -t Create or modify a file timestamp
umask xxxx Set default permis­sions to a directory


2 File permission codes: Letter designations

Command Function
- regular file
d directory
l symbolic link
c character device
b block device
t sticky bit


3 Common octal commands and patterns

Command Function
chmod 777 file (Do not use this) rwx      rwx      rwx
chmod 775 file rwx      rwx     r-x
chmod 755 file rwx      r-x      r-x
chmod 664 file rw-      rw-      r--
chmod 644 file rw-      r--      r--


4 File permissions: Basic octal codes

Command Function
1 Execute (x)
2 Write (x)
4 Read (r)


5 File permissions: Full octal codes

Command Function
7 Read, write and execute
6 Read and write
5 Read and execute
4 Read
3 Write and execute
2 Write
1 Execute
0 No permissions


6 Octal triplets

Command Function
000 ---
001 --x
010 -w-
011 -wx
100 r--
101 r-x
110 rw-
111 rwx


7 See also