How to change file and folder permissions with ... http://linuxg.net/how-to-change-file-and-folder-pe...
LinuxG.net
The Linux and Unix Geekster!
Linux Geekster About Post List Zero Viruses The Cookie Policy Privacy Policy
Contact
1 of 8 21/12/2018, 9:00 AM
How to change file and folder permissions with ... http://linuxg.net/how-to-change-file-and-folder-pe...
How to change file and folder permissions with chmod –
part 1
Posted on July 1, 2012 by Geekster — No Comments ↓
Permissions can be set in the octal mode (with digits), or with letters.
In this article, we will change the file and folder access rights in the human readable representation with
chmod.
In Linux and Unix systems, the file and folder permission permissions are:
read permissions: r
write permissions: w
execution permissions : x
Structured in u g o format:
u = user
g = group
o = others
The user is the owner of the file or directory, the group is the group that owns the file or directory
and the users that do not belong to the owner group are the others.
The generical tool for displaying the permissions is ls -l . But I prefer to use stat.
$ ls -l /etc/motd
lrwxrwxrwx 1 root root 13 2012-05-21 22:38 /etc/motd -> /var/run/motd
$ stat -c "%A %n" /etc/motd
lrwxrwxrwx /etc/motd
Sample: lrwxrwxrwx /etc/motd
The red characters represent the permissions for the user, the green characters represent the access
rights for the group and the blue ones for the others.
I have this file with no access rights:
The chmod command is used for changing the file and folder access rights. The plus + sign adds
2 of 8 21/12/2018, 9:00 AM
How to change file and folder permissions with ... http://linuxg.net/how-to-change-file-and-folder-pe...
$ ls -l
---------- 1 razvan razvan 0 2012-06-29 23:12 testfile
permissions and the minus – sign removes permissions:
Add exec permission for the user:
$ chmod u+x testfile
Remove exec permission for the user:
$ chmod u-x testfile
Add read and write permissions for the group:
$ chmod g+rw testfile
Remove the read and write permissions for the group:
$ chmod g-rw testfile
Add read write exec permissions for the others:
$ chmod o+rwx testfile
Remove the read write exec permissions for the others:
$ chmod o-rwx testfile
Add read write for the user, exec write for the group:
$ chmod u+rw,g+wx testfile
Remove the recently set permissions:
$ chmod u-rw,g-wx testfile
Add read write for the user and group and x for the others:
$ chmod u+rw,g+rx,o+x testfile
Remove the recently added permissions:
3 of 8 21/12/2018, 9:00 AM
How to change file and folder permissions with ... http://linuxg.net/how-to-change-file-and-folder-pe...
$ chmod u-rw,g-rx,o-x testfile
The a argument is used to set permissions to everybody (all).
Add exec and write for everybody:
$ chmod a+wx testfile
Remove the recently added permissions:
$ chmod a-wx testfile
Set read and write for the user, read and exec for the group and write for the others:
$ chmod u=rw,g=rx,o=w testfile
Remove all the permissions:
$ chmod u=,g=,r= testfile
These commands can be combined one with another, to serve your needs.
Next, I will show you how to set the permissions recursively.
To set the permissions for a directory and for all the files contained by it, use the -R option:
$ chmod -R u=rwx,g=rw,o=x testdir
This also works for removing permissions:
$ chmod -R u-x,g-x,o-rwx
Set exec permissions only for the directories.
This command will add execution writes for the user on directories in your current folder, and will not
change the file permissions:
$ chmod u+X *
[X is an upper case this time]
Related Posts
How to set the SetUID and SetGID bit for files in Linux and Unix
4 of 8 21/12/2018, 9:00 AM
How to change file and folder permissions with ... http://linuxg.net/how-to-change-file-and-folder-pe...
How to change file and folders permissions with chmod – part 2
How to use the sticky bit in Linux and Unix
15 Basic Commands Every Linux and Unix User Should Know How to Use
Cron Tab for Odd or Even days only
Liked it? Take a second to support Geekster on Patreon!
‹ How to manage background and foreground jobs How to replace one string with another in a file ›
Tagged with: change file permissions, chmod, linux, the chmod command, unix
Posted in The Linux and Unix Articles!
5 of 8 21/12/2018, 9:00 AM
How to change file and folder permissions with ... http://linuxg.net/how-to-change-file-and-folder-pe...
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment
Name *
E-mail *
Website
Post Comment
Support LinuxG via Patreon
Support LinuxG.net on Patreon!
6 of 8 21/12/2018, 9:00 AM
How to change file and folder permissions with ... http://linuxg.net/how-to-change-file-and-folder-pe...
search here … Go
Subscribe
Subscribe
Subscribe to get the latest Linux news and how to
guides directly on your e-mail!
Recent posts
How To Install Deluge 1.3.15 on Ubuntu 18.10,
Ubuntu 18.04 And Derivative Systems
How To Install qBittorrent 4.1.4 on Ubuntu
18.10, Ubuntu 18.04 And Derivative Systems
How to Install Transmission 2.94 on Ubuntu
18.10, Ubuntu 18.04 And Derivative Systems
How To Install Kernel 4.20 RC6 on Ubuntu
How To Install SeaMonkey 2.49.4 on Ubuntu
18.10, Ubuntu 18.04 And Derivative Systems
How To Install WhatsDesk (WhatsApp Client)
On Ubuntu Via Snap
How to Install And Use Franz (WhatsApp,
Slack, Discord, Telegram client) on Ubuntu
Last 7 Days Most Popular
Posts
Sorry. No data so far.
7 of 8 21/12/2018, 9:00 AM
How to change file and folder permissions with ... http://linuxg.net/how-to-change-file-and-folder-pe...
Tags
canonical centos debian debian wheezy deepin
deepin 2014 elementary os
elementary os 0.2 elementary os 0.2 luna
elementary os 0.3 fedora kernel linux
linux lite linux lite 2.0 linux mint
linux mint 13 linux mint 14
linux mint 15 linux mint 16
linux mint 17 linux mint 17.1 linux news
lxle lxle 14.04 mageia news openmandriva
opensuse pear os pear os 8 peppermint
peppermint five pinguy os
pinguy os 14.04 ubuntu
ubuntu 12.04 ubuntu 12.10
ubuntu 13.04 ubuntu 13.10
ubuntu 14.04 ubuntu 14.10
ubuntu 15.04 ubuntu touch unix
© 2018 LinuxG.net
8 of 8 21/12/2018, 9:00 AM