Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
The chmod
command in Linux (short for "change mode") is a utility used to change the permissions of files and directories. In this tutorial, we will discuss how to use the chmod
command effectively, along with various options and examples.
Understanding Linux permissions:
Linux permissions are based on three types of access: read (r
), write (w
), and execute (x
). These permissions are set for three different categories of users: the owner of the file, the group that the file belongs to, and others (everyone else). Permissions are usually represented using a combination of these characters (e.g., rwxr-xr-x
).
Basic usage of the chmod
command:
The chmod
command can be used with either symbolic or numeric (octal) representations of permissions.
Symbolic representation:
To change permissions using symbolic representation, use the chmod
command followed by the permissions changes and the path of the file or directory:
chmod [ugoa][+-=][rwx] file.txt
The first part [ugoa]
represents the user categories: user (owner) u
, group g
, others o
, and all a
. The second part [+-=]
represents the operations: add +
, remove -
, and set =
. The third part [rwx]
represents the permissions: read r
, write w
, and execute x
.
Numeric (octal) representation:
To change permissions using numeric representation, use the chmod
command followed by a three-digit octal number and the path of the file or directory:
chmod 755 file.txt
Each digit in the octal number represents the permissions for a specific category of users: the first digit is for the owner, the second is for the group, and the third is for others. The digit is the sum of the permissions' numeric values: read 4
, write 2
, and execute 1
.
Examples of using the chmod
command:
Grant read, write, and execute permissions to the owner, and read and execute permissions to the group and others:
chmod u=rwx,g=rx,o=rx file.txt
or
chmod 755 file.txt
Remove write permission from the group and others:
chmod go-w file.txt
Add execute permission for all users:
chmod a+x file.txt
Changing permissions recursively:
To change the permissions of a directory and its contents recursively, use the -R
or --recursive
option:
chmod -R 755 /path/to/directory
This command will change the permissions of the specified directory and all its files and subdirectories to 755
.
By following this tutorial, you should now have a good understanding of how to use the chmod
command in Linux to change the permissions of files and directories. The chmod
command is an essential tool for managing file access and ensuring that the right users have the appropriate permissions for files and directories.
How to use chmod command in Linux:
chmod
command is used to change the permissions of files and directories in Linux.chmod [options] mode file
Changing file permissions with chmod:
chmod +x filename
Setting read, write, and execute permissions in chmod:
chmod u+rwx file
Modifying permissions for specific users in chmod:
chmod u=rx,g=w,o+x file
Recursive permission change with chmod in Linux:
chmod -R mode directory
Numeric mode vs. symbolic mode in chmod:
chmod 755 file # Numeric mode chmod u=rwx,go=rx file # Symbolic mode
Viewing current file permissions with chmod:
ls -l filename
Revoking permissions using chmod:
chmod go-rw file
Advanced chmod options for fine-grained control:
--reference
and --preserve-root
for precise control.chmod --reference=reference_file target_file