
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
How to change file or directory permission in Linux/Unix?
We know that the Linux/Unix is a multiuser operating system files and directories are associated with permission so that only authorized users can access the files.
The chmod command is used to change the access permission of files or directories.
Syntax
The general syntax of the chmod command is as follows −
chmod [OPTION]... [Mode]... [File]...
Syntax of chmod command is as followed, it contains some three parameters that will help to set or change the permission of the file.
We will discuss each parameter in detail so that you can have a better idea of using the chmod command.
A brief description of options available in the chmod command −
Sr.No. | Option & Description |
---|---|
1 | -c, --changes Gives a diagnosis for all the files that actually changed. |
2 | -f, --silent, --quite It suppresses most of the error messages. |
3 | -v, --verbose Give a diagnosis for all the processed files. |
4 | -R, --recursive It changes files and directories recursively. |
5 | --help Displays a help message and then exits. |
6 | --version It gives info about the version and then exits. |
Mode
Mode can be represented in two different ways.
- Numeric notation
- Symbolic notation
Numeric notation
In numeric notation, a three figures octal number (0-7) sequence is followed. Each digit holds Its own class. First digit for user Second digit for group and the last one is for others. If digits are out of range then it will be considered as zeros.
Sr.No. | Numeric notation & Description |
---|---|
1 | 7 Read, write and execute. |
2 | 6 Read and write. |
3 | 5 Read and execute. |
4 | 4 Read-only. |
5 | 3 Write and execute. |
6 | 2 Write only. |
7 | 1 Execute only. |
8 | 0 None. |
Symbolic notation
Symbolic notation is a combination of letters that specifies the permission. Some important letters are (u) for user (g) for group (o) for others and (a) for all the users.
Sr.No. | Symbolic notation & Description |
---|---|
1 | rwx Read, write and execute. |
2 | rw- Read and write. |
3 | r-x Read and execute. |
4 | r-- Read-only. |
5 | -wx Write and execute. |
6 | -w- Write only. |
7 | --x Execute only. |
8 | --- None. |
Some arithmetic operators are used for certain permission.
“+” Plus, the operator will be used for adding the next permission to the existing one.
“- “Minus operator for removing.
“=” And equal means that it is the only permission is being used.
Changing the permission of a file
We can change the permission of a file and allow only the owner to read the file using the chmod command.
First, we will check permission of a file using the below command.
$ ls -l
Then we will change the permission of a file using the chmod command. We can provide permission numeric mode or symbolic mode.
Numeric notation –
$ chmod 400 file.txt
Or we can use the below command instead of numeric notation.
Symbolic notation –
$ chmod u + r hello.txt
As mentioned in the above tabular form, the option 200 allows the owner only to write into the file.
After executing the below command, only the owner of the file is allowed to modify it.
$ chmod 200 file.txt
To display more information about the chmod command, we use the --help option with the chmod command as shown below.
$ chmod --help
- Related Articles
- How to disable delete permission of File and Directory in Linux?
- How to change the permission of a directory using Python?
- How to copy a file, group of files, or directory in Linux?
- How to change the permission of a file using Python?
- How to change the shell working directory in Linux?
- How to Create a File in the Linux/Unix system using terminal?
- How to Get the most recent file in a directory in Linux?
- How to create a zip file and ignore directory structure in Linux?
- How to find the most recent file in a directory on Linux?
- How to change the file owner and group in Linux?
- Rename file or directory in Java
- Java Program to delete file or directory
- How to change the root directory of an Apache server on Linux?
- How to Change the Default Home Directory of a User on Linux?
- Delete the file or directory in Java
