I would like to change permissions of a folder and all its sub folders and files in one step (command) in Linux.
I have already tried the below command but it works
I think Adam was asking how to change umask value for all processes that tying to operate on /opt/lampp/htdocs
directory.
The user file-creation mode mask (umask) is use to determine the file permission for newly created files. It can be used to control the default file permission for new files.
so if you will use some kind of ftp program to upload files into /opt/lampp/htdocs
you need to configure your ftp server to use umask you want.
If files / directories be created for example by php, you need to modify php code
<?php
umask(0022);
// other code
?>
if you will create new files / folders from your bash session, you can set umask value in your shell profile ~/.bashrc
Or you can set up umask in /etc/bashrc
or /etc/profile
file for all users.
add the following to file:
umask 022
Sample umask Values and File Creation Permissions
If umask value set to User permission Group permission Others permission
000 all all all
007 all all none
027 all read / execute none
And to change permissions for already created files you can use find. Hope this helps.
It's very simple.
In Terminal go to file manager. example: sudo nemo
. Go /opt/
then click Properties → Permission. and then Other. Finally, change to create and delete and file acess to read and write and click on button apply... And work.
Use:
sudo chmod 755 -R /whatever/your/directory/is
However, be careful with that. It can really hurt you if you change the permissions of the wrong files/folders.
For already created files:
find . \( -type f -exec chmod g=r,o=r {} \; \) , \( -type d -exec chmod g=rx,o=rx {} \; \)
For future created files:
sudo nano /etc/profile
And set:
umask 022
Common modes are:
If you want to set permissions on all files to a+r
, and all directories to a+x
, and do that recursively through the complete subdirectory tree, use:
chmod -R a+rX *
The X
(that is capital X
, not small x
!) is ignored for files (unless they are executable for someone already) but is used for directories.
Here's another way to set directories to 775 and files to 664.
find /opt/lampp/htdocs \
\( -type f -exec chmod ug+rw,o+r {} \; \) , \
\( -type d -exec chmod ug+rwxs,o+rx {} \; \)
It may look long, but it's pretty cool for three reasons:
man
pages (see below).Note that I have not confirmed the performance difference (if any) between this solution and that of simply using two find commands (as in Peter Mortensen's solution). However, seeing a similar example in the manual is encouraging.
Example from man find
page:
find / \
\( -perm -4000 -fprintf /root/suid.txt %#m %u %p\n \) , \
\( -size +100M -fprintf /root/big.txt %-10s %p\n \)
Traverse the filesystem just once, listing setuid files and direc‐
tories into /root/suid.txt and large files into /root/big.txt.
Cheers