How can I recursively change the permissions of files and directories?
I have ubuntu installed on my local computer with apache / php / mysql.
I now have a directory at /var/www - inside which I have several of my ongoing projects. I also work with opensource ( drupal, magento, sugarcrm ).
The problem I am facing is changing file permission with terminal. Sometime I need to change the permission of entire folder and its subsequent sub-folders and files. I have to individually change using
sudo chmod 777 foldername
How can I do this recursively.
Also why do I have to always do it 777, I tried 755 for folders and 644 for files, but that won't work.
permissions
add a comment |
I have ubuntu installed on my local computer with apache / php / mysql.
I now have a directory at /var/www - inside which I have several of my ongoing projects. I also work with opensource ( drupal, magento, sugarcrm ).
The problem I am facing is changing file permission with terminal. Sometime I need to change the permission of entire folder and its subsequent sub-folders and files. I have to individually change using
sudo chmod 777 foldername
How can I do this recursively.
Also why do I have to always do it 777, I tried 755 for folders and 644 for files, but that won't work.
permissions
add a comment |
I have ubuntu installed on my local computer with apache / php / mysql.
I now have a directory at /var/www - inside which I have several of my ongoing projects. I also work with opensource ( drupal, magento, sugarcrm ).
The problem I am facing is changing file permission with terminal. Sometime I need to change the permission of entire folder and its subsequent sub-folders and files. I have to individually change using
sudo chmod 777 foldername
How can I do this recursively.
Also why do I have to always do it 777, I tried 755 for folders and 644 for files, but that won't work.
permissions
I have ubuntu installed on my local computer with apache / php / mysql.
I now have a directory at /var/www - inside which I have several of my ongoing projects. I also work with opensource ( drupal, magento, sugarcrm ).
The problem I am facing is changing file permission with terminal. Sometime I need to change the permission of entire folder and its subsequent sub-folders and files. I have to individually change using
sudo chmod 777 foldername
How can I do this recursively.
Also why do I have to always do it 777, I tried 755 for folders and 644 for files, but that won't work.
permissions
permissions
edited Sep 21 '13 at 13:32
Braiam
51.2k20135219
51.2k20135219
asked Mar 16 '11 at 14:45
Nikhil
4302610
4302610
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Just add the -R
option to recursively change the permissions of files. An example, recursively add read and write permissions for the owner and group on foldername
:
chmod -R ug+rw foldername
Permissions will be like 664 or 775.
Setting the permissions to 777 is highly discouraged. You get errors in either Apache or your editor regarding permissions because apache runs under a different user (www-data
) than you.
If you want to write to /var/www
, add yourself to the www-data
group and set umask+permissions accordingly.
- Add yourself to the
www-data
group:sudo adduser $USER www-data
- Change the ownership of the files in
/var/www
:sudo chown -R www-data:www-data /var/www
- Change the umask, so newly created files by Apache grants write permissions to the group too. Add
umask 007
to/etc/apache2/envvars
. - Grant yourself (technically, the group
www-data
) write permissions:sudo chmod -R g+w /var/www
.
yeah I was adding r flag in wrong place, I was adding it after the o+w for chmod.
– JohnMerlino
Jul 27 '14 at 5:51
Also, if you try to usechmod -r blablabla
(small -r instead of -R) You might end up removing read permissions for everyone...
– Cyril Duchon-Doris
Jun 22 '15 at 14:42
After these instructions, it's a good idea to check that there are no.htaccess
files with write permissions for apache.find /var/www/ | grep .htaccess | xargs ls -l
.
– reynoldsnlp
Sep 25 at 2:10
add a comment |
bruteforce:
sudo find foldername -exec chmod a+rwx {} ";"
What does not work? Be more specific!
sudo find foldername -type d -exec chmod 755 {} ";"
sudo find foldername -type f -exec chmod 644 {} ";"
when you're inside the folder, remove "foldername"
– Enrique
Feb 11 '14 at 13:12
3
...and replace it with .
– djjeck
Dec 24 '14 at 8:15
add a comment |
You should not need 777 for anything. Worst case, you'll need to change the owner of certain files and directories to the "www-data" user.
sudo find /var/www -type d -print0 | xargs -0 chmod 755
sudo find /var/www -type f -print0 | xargs -0 chmod 644
sudo find /var/www/some/subset -print0 | xargs -0 chown www-data:www-data
If you're using Lekensteyn's group membership method, change 755 to 775 and 644 to 664 respectively above, and then force the group stickiness:
sudo find /var/www/some/subset -type d -print0 | xargs -0 chmod g+s
add a comment |
You can change the subfolders and files on Nautilus. As you can see on the image below. In order to have the permissons on buttons, you can enable the option on Ubuntu Tweak.
UseLANG=C [command]
to get English translations.
– Lekensteyn
Mar 16 '11 at 15:17
add a comment |
If you want to have all of your files be readable to the world (ie. it's just a static set of HTML files/images), then use this command:
chmod -R a+r <base directory>
That will recursively go through all of the files & subdirectories and add read permission to them.
WARNING: Don't do this for files that are executable! Only files that should be visible by everybody.
Are you saying "don't dochmod -R a+x
on anything", or "don't dochmod -R a+r
on executables"?
– aleclarson
Dec 8 at 14:14
I fixed it. The later is true. Be careful about allowing others access to executables that you've created.
– Ryan Shillington
Dec 8 at 15:49
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f30629%2fhow-can-i-recursively-change-the-permissions-of-files-and-directories%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just add the -R
option to recursively change the permissions of files. An example, recursively add read and write permissions for the owner and group on foldername
:
chmod -R ug+rw foldername
Permissions will be like 664 or 775.
Setting the permissions to 777 is highly discouraged. You get errors in either Apache or your editor regarding permissions because apache runs under a different user (www-data
) than you.
If you want to write to /var/www
, add yourself to the www-data
group and set umask+permissions accordingly.
- Add yourself to the
www-data
group:sudo adduser $USER www-data
- Change the ownership of the files in
/var/www
:sudo chown -R www-data:www-data /var/www
- Change the umask, so newly created files by Apache grants write permissions to the group too. Add
umask 007
to/etc/apache2/envvars
. - Grant yourself (technically, the group
www-data
) write permissions:sudo chmod -R g+w /var/www
.
yeah I was adding r flag in wrong place, I was adding it after the o+w for chmod.
– JohnMerlino
Jul 27 '14 at 5:51
Also, if you try to usechmod -r blablabla
(small -r instead of -R) You might end up removing read permissions for everyone...
– Cyril Duchon-Doris
Jun 22 '15 at 14:42
After these instructions, it's a good idea to check that there are no.htaccess
files with write permissions for apache.find /var/www/ | grep .htaccess | xargs ls -l
.
– reynoldsnlp
Sep 25 at 2:10
add a comment |
Just add the -R
option to recursively change the permissions of files. An example, recursively add read and write permissions for the owner and group on foldername
:
chmod -R ug+rw foldername
Permissions will be like 664 or 775.
Setting the permissions to 777 is highly discouraged. You get errors in either Apache or your editor regarding permissions because apache runs under a different user (www-data
) than you.
If you want to write to /var/www
, add yourself to the www-data
group and set umask+permissions accordingly.
- Add yourself to the
www-data
group:sudo adduser $USER www-data
- Change the ownership of the files in
/var/www
:sudo chown -R www-data:www-data /var/www
- Change the umask, so newly created files by Apache grants write permissions to the group too. Add
umask 007
to/etc/apache2/envvars
. - Grant yourself (technically, the group
www-data
) write permissions:sudo chmod -R g+w /var/www
.
yeah I was adding r flag in wrong place, I was adding it after the o+w for chmod.
– JohnMerlino
Jul 27 '14 at 5:51
Also, if you try to usechmod -r blablabla
(small -r instead of -R) You might end up removing read permissions for everyone...
– Cyril Duchon-Doris
Jun 22 '15 at 14:42
After these instructions, it's a good idea to check that there are no.htaccess
files with write permissions for apache.find /var/www/ | grep .htaccess | xargs ls -l
.
– reynoldsnlp
Sep 25 at 2:10
add a comment |
Just add the -R
option to recursively change the permissions of files. An example, recursively add read and write permissions for the owner and group on foldername
:
chmod -R ug+rw foldername
Permissions will be like 664 or 775.
Setting the permissions to 777 is highly discouraged. You get errors in either Apache or your editor regarding permissions because apache runs under a different user (www-data
) than you.
If you want to write to /var/www
, add yourself to the www-data
group and set umask+permissions accordingly.
- Add yourself to the
www-data
group:sudo adduser $USER www-data
- Change the ownership of the files in
/var/www
:sudo chown -R www-data:www-data /var/www
- Change the umask, so newly created files by Apache grants write permissions to the group too. Add
umask 007
to/etc/apache2/envvars
. - Grant yourself (technically, the group
www-data
) write permissions:sudo chmod -R g+w /var/www
.
Just add the -R
option to recursively change the permissions of files. An example, recursively add read and write permissions for the owner and group on foldername
:
chmod -R ug+rw foldername
Permissions will be like 664 or 775.
Setting the permissions to 777 is highly discouraged. You get errors in either Apache or your editor regarding permissions because apache runs under a different user (www-data
) than you.
If you want to write to /var/www
, add yourself to the www-data
group and set umask+permissions accordingly.
- Add yourself to the
www-data
group:sudo adduser $USER www-data
- Change the ownership of the files in
/var/www
:sudo chown -R www-data:www-data /var/www
- Change the umask, so newly created files by Apache grants write permissions to the group too. Add
umask 007
to/etc/apache2/envvars
. - Grant yourself (technically, the group
www-data
) write permissions:sudo chmod -R g+w /var/www
.
edited May 28 '16 at 15:49
Ramratan Gupta
12410
12410
answered Mar 16 '11 at 15:06
Lekensteyn
120k48263354
120k48263354
yeah I was adding r flag in wrong place, I was adding it after the o+w for chmod.
– JohnMerlino
Jul 27 '14 at 5:51
Also, if you try to usechmod -r blablabla
(small -r instead of -R) You might end up removing read permissions for everyone...
– Cyril Duchon-Doris
Jun 22 '15 at 14:42
After these instructions, it's a good idea to check that there are no.htaccess
files with write permissions for apache.find /var/www/ | grep .htaccess | xargs ls -l
.
– reynoldsnlp
Sep 25 at 2:10
add a comment |
yeah I was adding r flag in wrong place, I was adding it after the o+w for chmod.
– JohnMerlino
Jul 27 '14 at 5:51
Also, if you try to usechmod -r blablabla
(small -r instead of -R) You might end up removing read permissions for everyone...
– Cyril Duchon-Doris
Jun 22 '15 at 14:42
After these instructions, it's a good idea to check that there are no.htaccess
files with write permissions for apache.find /var/www/ | grep .htaccess | xargs ls -l
.
– reynoldsnlp
Sep 25 at 2:10
yeah I was adding r flag in wrong place, I was adding it after the o+w for chmod.
– JohnMerlino
Jul 27 '14 at 5:51
yeah I was adding r flag in wrong place, I was adding it after the o+w for chmod.
– JohnMerlino
Jul 27 '14 at 5:51
Also, if you try to use
chmod -r blablabla
(small -r instead of -R) You might end up removing read permissions for everyone...– Cyril Duchon-Doris
Jun 22 '15 at 14:42
Also, if you try to use
chmod -r blablabla
(small -r instead of -R) You might end up removing read permissions for everyone...– Cyril Duchon-Doris
Jun 22 '15 at 14:42
After these instructions, it's a good idea to check that there are no
.htaccess
files with write permissions for apache. find /var/www/ | grep .htaccess | xargs ls -l
.– reynoldsnlp
Sep 25 at 2:10
After these instructions, it's a good idea to check that there are no
.htaccess
files with write permissions for apache. find /var/www/ | grep .htaccess | xargs ls -l
.– reynoldsnlp
Sep 25 at 2:10
add a comment |
bruteforce:
sudo find foldername -exec chmod a+rwx {} ";"
What does not work? Be more specific!
sudo find foldername -type d -exec chmod 755 {} ";"
sudo find foldername -type f -exec chmod 644 {} ";"
when you're inside the folder, remove "foldername"
– Enrique
Feb 11 '14 at 13:12
3
...and replace it with .
– djjeck
Dec 24 '14 at 8:15
add a comment |
bruteforce:
sudo find foldername -exec chmod a+rwx {} ";"
What does not work? Be more specific!
sudo find foldername -type d -exec chmod 755 {} ";"
sudo find foldername -type f -exec chmod 644 {} ";"
when you're inside the folder, remove "foldername"
– Enrique
Feb 11 '14 at 13:12
3
...and replace it with .
– djjeck
Dec 24 '14 at 8:15
add a comment |
bruteforce:
sudo find foldername -exec chmod a+rwx {} ";"
What does not work? Be more specific!
sudo find foldername -type d -exec chmod 755 {} ";"
sudo find foldername -type f -exec chmod 644 {} ";"
bruteforce:
sudo find foldername -exec chmod a+rwx {} ";"
What does not work? Be more specific!
sudo find foldername -type d -exec chmod 755 {} ";"
sudo find foldername -type f -exec chmod 644 {} ";"
answered Mar 16 '11 at 15:05
user unknown
4,86122151
4,86122151
when you're inside the folder, remove "foldername"
– Enrique
Feb 11 '14 at 13:12
3
...and replace it with .
– djjeck
Dec 24 '14 at 8:15
add a comment |
when you're inside the folder, remove "foldername"
– Enrique
Feb 11 '14 at 13:12
3
...and replace it with .
– djjeck
Dec 24 '14 at 8:15
when you're inside the folder, remove "foldername"
– Enrique
Feb 11 '14 at 13:12
when you're inside the folder, remove "foldername"
– Enrique
Feb 11 '14 at 13:12
3
3
...and replace it with .
– djjeck
Dec 24 '14 at 8:15
...and replace it with .
– djjeck
Dec 24 '14 at 8:15
add a comment |
You should not need 777 for anything. Worst case, you'll need to change the owner of certain files and directories to the "www-data" user.
sudo find /var/www -type d -print0 | xargs -0 chmod 755
sudo find /var/www -type f -print0 | xargs -0 chmod 644
sudo find /var/www/some/subset -print0 | xargs -0 chown www-data:www-data
If you're using Lekensteyn's group membership method, change 755 to 775 and 644 to 664 respectively above, and then force the group stickiness:
sudo find /var/www/some/subset -type d -print0 | xargs -0 chmod g+s
add a comment |
You should not need 777 for anything. Worst case, you'll need to change the owner of certain files and directories to the "www-data" user.
sudo find /var/www -type d -print0 | xargs -0 chmod 755
sudo find /var/www -type f -print0 | xargs -0 chmod 644
sudo find /var/www/some/subset -print0 | xargs -0 chown www-data:www-data
If you're using Lekensteyn's group membership method, change 755 to 775 and 644 to 664 respectively above, and then force the group stickiness:
sudo find /var/www/some/subset -type d -print0 | xargs -0 chmod g+s
add a comment |
You should not need 777 for anything. Worst case, you'll need to change the owner of certain files and directories to the "www-data" user.
sudo find /var/www -type d -print0 | xargs -0 chmod 755
sudo find /var/www -type f -print0 | xargs -0 chmod 644
sudo find /var/www/some/subset -print0 | xargs -0 chown www-data:www-data
If you're using Lekensteyn's group membership method, change 755 to 775 and 644 to 664 respectively above, and then force the group stickiness:
sudo find /var/www/some/subset -type d -print0 | xargs -0 chmod g+s
You should not need 777 for anything. Worst case, you'll need to change the owner of certain files and directories to the "www-data" user.
sudo find /var/www -type d -print0 | xargs -0 chmod 755
sudo find /var/www -type f -print0 | xargs -0 chmod 644
sudo find /var/www/some/subset -print0 | xargs -0 chown www-data:www-data
If you're using Lekensteyn's group membership method, change 755 to 775 and 644 to 664 respectively above, and then force the group stickiness:
sudo find /var/www/some/subset -type d -print0 | xargs -0 chmod g+s
answered Mar 17 '11 at 7:02
Kees Cook
13.8k75791
13.8k75791
add a comment |
add a comment |
You can change the subfolders and files on Nautilus. As you can see on the image below. In order to have the permissons on buttons, you can enable the option on Ubuntu Tweak.
UseLANG=C [command]
to get English translations.
– Lekensteyn
Mar 16 '11 at 15:17
add a comment |
You can change the subfolders and files on Nautilus. As you can see on the image below. In order to have the permissons on buttons, you can enable the option on Ubuntu Tweak.
UseLANG=C [command]
to get English translations.
– Lekensteyn
Mar 16 '11 at 15:17
add a comment |
You can change the subfolders and files on Nautilus. As you can see on the image below. In order to have the permissons on buttons, you can enable the option on Ubuntu Tweak.
You can change the subfolders and files on Nautilus. As you can see on the image below. In order to have the permissons on buttons, you can enable the option on Ubuntu Tweak.
edited Mar 16 '11 at 15:21
answered Mar 16 '11 at 15:12
Alfredo Hernández
1,9451937
1,9451937
UseLANG=C [command]
to get English translations.
– Lekensteyn
Mar 16 '11 at 15:17
add a comment |
UseLANG=C [command]
to get English translations.
– Lekensteyn
Mar 16 '11 at 15:17
Use
LANG=C [command]
to get English translations.– Lekensteyn
Mar 16 '11 at 15:17
Use
LANG=C [command]
to get English translations.– Lekensteyn
Mar 16 '11 at 15:17
add a comment |
If you want to have all of your files be readable to the world (ie. it's just a static set of HTML files/images), then use this command:
chmod -R a+r <base directory>
That will recursively go through all of the files & subdirectories and add read permission to them.
WARNING: Don't do this for files that are executable! Only files that should be visible by everybody.
Are you saying "don't dochmod -R a+x
on anything", or "don't dochmod -R a+r
on executables"?
– aleclarson
Dec 8 at 14:14
I fixed it. The later is true. Be careful about allowing others access to executables that you've created.
– Ryan Shillington
Dec 8 at 15:49
add a comment |
If you want to have all of your files be readable to the world (ie. it's just a static set of HTML files/images), then use this command:
chmod -R a+r <base directory>
That will recursively go through all of the files & subdirectories and add read permission to them.
WARNING: Don't do this for files that are executable! Only files that should be visible by everybody.
Are you saying "don't dochmod -R a+x
on anything", or "don't dochmod -R a+r
on executables"?
– aleclarson
Dec 8 at 14:14
I fixed it. The later is true. Be careful about allowing others access to executables that you've created.
– Ryan Shillington
Dec 8 at 15:49
add a comment |
If you want to have all of your files be readable to the world (ie. it's just a static set of HTML files/images), then use this command:
chmod -R a+r <base directory>
That will recursively go through all of the files & subdirectories and add read permission to them.
WARNING: Don't do this for files that are executable! Only files that should be visible by everybody.
If you want to have all of your files be readable to the world (ie. it's just a static set of HTML files/images), then use this command:
chmod -R a+r <base directory>
That will recursively go through all of the files & subdirectories and add read permission to them.
WARNING: Don't do this for files that are executable! Only files that should be visible by everybody.
edited Dec 8 at 15:48
answered Jan 26 '15 at 17:46
Ryan Shillington
1114
1114
Are you saying "don't dochmod -R a+x
on anything", or "don't dochmod -R a+r
on executables"?
– aleclarson
Dec 8 at 14:14
I fixed it. The later is true. Be careful about allowing others access to executables that you've created.
– Ryan Shillington
Dec 8 at 15:49
add a comment |
Are you saying "don't dochmod -R a+x
on anything", or "don't dochmod -R a+r
on executables"?
– aleclarson
Dec 8 at 14:14
I fixed it. The later is true. Be careful about allowing others access to executables that you've created.
– Ryan Shillington
Dec 8 at 15:49
Are you saying "don't do
chmod -R a+x
on anything", or "don't do chmod -R a+r
on executables"?– aleclarson
Dec 8 at 14:14
Are you saying "don't do
chmod -R a+x
on anything", or "don't do chmod -R a+r
on executables"?– aleclarson
Dec 8 at 14:14
I fixed it. The later is true. Be careful about allowing others access to executables that you've created.
– Ryan Shillington
Dec 8 at 15:49
I fixed it. The later is true. Be careful about allowing others access to executables that you've created.
– Ryan Shillington
Dec 8 at 15:49
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f30629%2fhow-can-i-recursively-change-the-permissions-of-files-and-directories%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown