How to Chown a directory recursively including hidden files or directoriesBash snippet to move all files in a...
How does 取材で訪れた integrate into this sentence?
Calculate the frequency of characters in a string
Print a physical multiplication table
Bash - pair each line of file
What can I do if I am asked to learn different programming languages very frequently?
gerund and noun applications
Why are there no stars visible in cislunar space?
World War I as a war of liberals against authoritarians?
Do native speakers use "ultima" and "proxima" frequently in spoken English?
Hausdorff dimension of the boundary of fibres of Lipschitz maps
Print last inputted byte
Wrapping homogeneous Python objects
What does "Four-F." mean?
Comment Box for Substitution Method of Integrals
Help prove this basic trig identity please!
Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?
Recruiter wants very extensive technical details about all of my previous work
Help rendering a complicated sum/product formula
Loading the leaflet Map in Lightning Web Component
Generic TVP tradeoffs?
How to terminate ping <dest> &
Is it insecure to send a password in a `curl` command?
What (if any) is the reason to buy in small local stores?
Unfrosted light bulb
How to Chown a directory recursively including hidden files or directories
Bash snippet to move all files in a directory into that directoryCan't modify or chown files on readynas nfs shareHow can I recursively verify the permissions within a given subdirectory?exclude all hidden files and directories in solarisOnly allow a user to CHMOD and CHOWN in their home directory or a specified directoryCannot login to Solaris due to chown on /usr directoryCannot login to Solaris due to chown on /usr directoryChange group owner of file, but not the ownerLimit sudo to only one directory and it's subdirectories by sudoers fileUsing chown: Any substantial difference between assigning ownership of the entire directory vs just the files in it?
Seems like chown with the recursive flag will not work on hidden directories or files. Is there any simple workaround for that?
unix chown
add a comment |
Seems like chown with the recursive flag will not work on hidden directories or files. Is there any simple workaround for that?
unix chown
add a comment |
Seems like chown with the recursive flag will not work on hidden directories or files. Is there any simple workaround for that?
unix chown
Seems like chown with the recursive flag will not work on hidden directories or files. Is there any simple workaround for that?
unix chown
unix chown
asked Jun 30 '10 at 20:23
tobytoby
266136
266136
add a comment |
add a comment |
8 Answers
8
active
oldest
votes
I'm pretty sure the -R
flag does work - it always has for me anyway. What won't work, and what tripped me up early in my command line usage, is using *
in a directory with hidden files/directories. So doing
$ chown -R /home/user/*
will not do the hidden files and directories. However if you follow it with
$ chown -R /home/user/.[^.]*
then you will do all the hidden files, (but not .
or ..
as /home/user/.*
would do). Having said all that, I would expect
$ chown -R /home/user
to get all the hidden files and directories inside /home/user
- though that will of course also change the permissions of the directory itself, which might not be what you intended.
2
Doing achown
on the directory has the side effect that you change the permissions on the directory itself as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:44
A+ worked like a charm for me.
– SuperFamousGuy
Feb 5 '15 at 0:11
I triedchown nginx:nginx -R /path/to/.[^.]*
and it only changed ownership to .dot hidden files. not all.
– Pathros
Jun 23 '18 at 17:35
add a comment |
"chown -R" works, but an alternative would be using find.
find /path/to/dir -exec chown USER {} ;
5
note that with GNU find, using+
instead of;
as the terminator to the -exec will be more efficient as it will use the minimum needed number of forks to chown instead of one fork per file/directory
– stew
May 14 '12 at 2:31
add a comment |
i believe the following command should work for this
chown -hR userid:usergroup /nameofdirectory/nameofsubdir/
1
-h affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)
– R. van Twisk
Feb 24 '17 at 10:29
add a comment |
You can change the dotglob
attribute temporarily to expand . files and then revert it.
shopt -s dotglob; chown -R user:group FOLDER; shopt -u dotglob
More on dotglob
can be found here
add a comment |
Also, if you're like me you'll probably be running chown mostly from the current directory. I was accustomed to running it like this: chown rails.rails -R *
. Simply changing the asterisk to a dot (short for the current directory) like this: chown rails.rails -R .
brings in all hidden directories.
2
With the side effect that you change the permissions on the current directory as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:39
add a comment |
Using for-loop with ls -A
option, We can find all hidden files and directory exclude .
and ..
and then change the ownership for all hidden files and directory.
for i in `ls -A | grep "^."`;do chown -R user:group $i;done
Use xargs
option with ls -A
ls -A | grep "^." | xargs chown user:group
For More details Click Here and Visit my Site
add a comment |
To chown ALL files in current directory and subdirectories for current user;
find . -exec chown $(whoami) {} ;
or if user can't chown some files due to restricted permissions;
sudo find . -exec chown $(logname) {} ;
New contributor
add a comment |
You could do something like
for i in `ls -A`;do chown -R user:group $i;done
The -A
(capital A) is important as it excludes '.' and '..'
This will change only files and subdirectories in the current directory, not any lower levels. (Which may be what the OP wants.) It will also break on filenames and directory names with spaces (or tabs) in them.
– wfaulk
May 10 '12 at 22:48
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
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%2fserverfault.com%2fquestions%2f156437%2fhow-to-chown-a-directory-recursively-including-hidden-files-or-directories%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm pretty sure the -R
flag does work - it always has for me anyway. What won't work, and what tripped me up early in my command line usage, is using *
in a directory with hidden files/directories. So doing
$ chown -R /home/user/*
will not do the hidden files and directories. However if you follow it with
$ chown -R /home/user/.[^.]*
then you will do all the hidden files, (but not .
or ..
as /home/user/.*
would do). Having said all that, I would expect
$ chown -R /home/user
to get all the hidden files and directories inside /home/user
- though that will of course also change the permissions of the directory itself, which might not be what you intended.
2
Doing achown
on the directory has the side effect that you change the permissions on the directory itself as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:44
A+ worked like a charm for me.
– SuperFamousGuy
Feb 5 '15 at 0:11
I triedchown nginx:nginx -R /path/to/.[^.]*
and it only changed ownership to .dot hidden files. not all.
– Pathros
Jun 23 '18 at 17:35
add a comment |
I'm pretty sure the -R
flag does work - it always has for me anyway. What won't work, and what tripped me up early in my command line usage, is using *
in a directory with hidden files/directories. So doing
$ chown -R /home/user/*
will not do the hidden files and directories. However if you follow it with
$ chown -R /home/user/.[^.]*
then you will do all the hidden files, (but not .
or ..
as /home/user/.*
would do). Having said all that, I would expect
$ chown -R /home/user
to get all the hidden files and directories inside /home/user
- though that will of course also change the permissions of the directory itself, which might not be what you intended.
2
Doing achown
on the directory has the side effect that you change the permissions on the directory itself as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:44
A+ worked like a charm for me.
– SuperFamousGuy
Feb 5 '15 at 0:11
I triedchown nginx:nginx -R /path/to/.[^.]*
and it only changed ownership to .dot hidden files. not all.
– Pathros
Jun 23 '18 at 17:35
add a comment |
I'm pretty sure the -R
flag does work - it always has for me anyway. What won't work, and what tripped me up early in my command line usage, is using *
in a directory with hidden files/directories. So doing
$ chown -R /home/user/*
will not do the hidden files and directories. However if you follow it with
$ chown -R /home/user/.[^.]*
then you will do all the hidden files, (but not .
or ..
as /home/user/.*
would do). Having said all that, I would expect
$ chown -R /home/user
to get all the hidden files and directories inside /home/user
- though that will of course also change the permissions of the directory itself, which might not be what you intended.
I'm pretty sure the -R
flag does work - it always has for me anyway. What won't work, and what tripped me up early in my command line usage, is using *
in a directory with hidden files/directories. So doing
$ chown -R /home/user/*
will not do the hidden files and directories. However if you follow it with
$ chown -R /home/user/.[^.]*
then you will do all the hidden files, (but not .
or ..
as /home/user/.*
would do). Having said all that, I would expect
$ chown -R /home/user
to get all the hidden files and directories inside /home/user
- though that will of course also change the permissions of the directory itself, which might not be what you intended.
edited May 29 '12 at 10:14
answered Jun 30 '10 at 22:46
Hamish DownerHamish Downer
6,53752947
6,53752947
2
Doing achown
on the directory has the side effect that you change the permissions on the directory itself as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:44
A+ worked like a charm for me.
– SuperFamousGuy
Feb 5 '15 at 0:11
I triedchown nginx:nginx -R /path/to/.[^.]*
and it only changed ownership to .dot hidden files. not all.
– Pathros
Jun 23 '18 at 17:35
add a comment |
2
Doing achown
on the directory has the side effect that you change the permissions on the directory itself as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:44
A+ worked like a charm for me.
– SuperFamousGuy
Feb 5 '15 at 0:11
I triedchown nginx:nginx -R /path/to/.[^.]*
and it only changed ownership to .dot hidden files. not all.
– Pathros
Jun 23 '18 at 17:35
2
2
Doing a
chown
on the directory has the side effect that you change the permissions on the directory itself as well as all of its contents, which may or may not be what you want.– wfaulk
May 10 '12 at 22:44
Doing a
chown
on the directory has the side effect that you change the permissions on the directory itself as well as all of its contents, which may or may not be what you want.– wfaulk
May 10 '12 at 22:44
A+ worked like a charm for me.
– SuperFamousGuy
Feb 5 '15 at 0:11
A+ worked like a charm for me.
– SuperFamousGuy
Feb 5 '15 at 0:11
I tried
chown nginx:nginx -R /path/to/.[^.]*
and it only changed ownership to .dot hidden files. not all.– Pathros
Jun 23 '18 at 17:35
I tried
chown nginx:nginx -R /path/to/.[^.]*
and it only changed ownership to .dot hidden files. not all.– Pathros
Jun 23 '18 at 17:35
add a comment |
"chown -R" works, but an alternative would be using find.
find /path/to/dir -exec chown USER {} ;
5
note that with GNU find, using+
instead of;
as the terminator to the -exec will be more efficient as it will use the minimum needed number of forks to chown instead of one fork per file/directory
– stew
May 14 '12 at 2:31
add a comment |
"chown -R" works, but an alternative would be using find.
find /path/to/dir -exec chown USER {} ;
5
note that with GNU find, using+
instead of;
as the terminator to the -exec will be more efficient as it will use the minimum needed number of forks to chown instead of one fork per file/directory
– stew
May 14 '12 at 2:31
add a comment |
"chown -R" works, but an alternative would be using find.
find /path/to/dir -exec chown USER {} ;
"chown -R" works, but an alternative would be using find.
find /path/to/dir -exec chown USER {} ;
answered Jun 30 '10 at 20:34
hayalcihayalci
3,21511831
3,21511831
5
note that with GNU find, using+
instead of;
as the terminator to the -exec will be more efficient as it will use the minimum needed number of forks to chown instead of one fork per file/directory
– stew
May 14 '12 at 2:31
add a comment |
5
note that with GNU find, using+
instead of;
as the terminator to the -exec will be more efficient as it will use the minimum needed number of forks to chown instead of one fork per file/directory
– stew
May 14 '12 at 2:31
5
5
note that with GNU find, using
+
instead of ;
as the terminator to the -exec will be more efficient as it will use the minimum needed number of forks to chown instead of one fork per file/directory– stew
May 14 '12 at 2:31
note that with GNU find, using
+
instead of ;
as the terminator to the -exec will be more efficient as it will use the minimum needed number of forks to chown instead of one fork per file/directory– stew
May 14 '12 at 2:31
add a comment |
i believe the following command should work for this
chown -hR userid:usergroup /nameofdirectory/nameofsubdir/
1
-h affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)
– R. van Twisk
Feb 24 '17 at 10:29
add a comment |
i believe the following command should work for this
chown -hR userid:usergroup /nameofdirectory/nameofsubdir/
1
-h affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)
– R. van Twisk
Feb 24 '17 at 10:29
add a comment |
i believe the following command should work for this
chown -hR userid:usergroup /nameofdirectory/nameofsubdir/
i believe the following command should work for this
chown -hR userid:usergroup /nameofdirectory/nameofsubdir/
edited May 14 '12 at 2:13
hayalci
3,21511831
3,21511831
answered Jun 30 '10 at 22:51
MattrixHaxMattrixHax
10112
10112
1
-h affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)
– R. van Twisk
Feb 24 '17 at 10:29
add a comment |
1
-h affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)
– R. van Twisk
Feb 24 '17 at 10:29
1
1
-h affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)
– R. van Twisk
Feb 24 '17 at 10:29
-h affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)
– R. van Twisk
Feb 24 '17 at 10:29
add a comment |
You can change the dotglob
attribute temporarily to expand . files and then revert it.
shopt -s dotglob; chown -R user:group FOLDER; shopt -u dotglob
More on dotglob
can be found here
add a comment |
You can change the dotglob
attribute temporarily to expand . files and then revert it.
shopt -s dotglob; chown -R user:group FOLDER; shopt -u dotglob
More on dotglob
can be found here
add a comment |
You can change the dotglob
attribute temporarily to expand . files and then revert it.
shopt -s dotglob; chown -R user:group FOLDER; shopt -u dotglob
More on dotglob
can be found here
You can change the dotglob
attribute temporarily to expand . files and then revert it.
shopt -s dotglob; chown -R user:group FOLDER; shopt -u dotglob
More on dotglob
can be found here
answered Aug 17 '16 at 6:44
stdcallstdcall
1427
1427
add a comment |
add a comment |
Also, if you're like me you'll probably be running chown mostly from the current directory. I was accustomed to running it like this: chown rails.rails -R *
. Simply changing the asterisk to a dot (short for the current directory) like this: chown rails.rails -R .
brings in all hidden directories.
2
With the side effect that you change the permissions on the current directory as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:39
add a comment |
Also, if you're like me you'll probably be running chown mostly from the current directory. I was accustomed to running it like this: chown rails.rails -R *
. Simply changing the asterisk to a dot (short for the current directory) like this: chown rails.rails -R .
brings in all hidden directories.
2
With the side effect that you change the permissions on the current directory as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:39
add a comment |
Also, if you're like me you'll probably be running chown mostly from the current directory. I was accustomed to running it like this: chown rails.rails -R *
. Simply changing the asterisk to a dot (short for the current directory) like this: chown rails.rails -R .
brings in all hidden directories.
Also, if you're like me you'll probably be running chown mostly from the current directory. I was accustomed to running it like this: chown rails.rails -R *
. Simply changing the asterisk to a dot (short for the current directory) like this: chown rails.rails -R .
brings in all hidden directories.
answered May 10 '12 at 21:49
CraigCraig
13917
13917
2
With the side effect that you change the permissions on the current directory as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:39
add a comment |
2
With the side effect that you change the permissions on the current directory as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:39
2
2
With the side effect that you change the permissions on the current directory as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:39
With the side effect that you change the permissions on the current directory as well as all of its contents, which may or may not be what you want.
– wfaulk
May 10 '12 at 22:39
add a comment |
Using for-loop with ls -A
option, We can find all hidden files and directory exclude .
and ..
and then change the ownership for all hidden files and directory.
for i in `ls -A | grep "^."`;do chown -R user:group $i;done
Use xargs
option with ls -A
ls -A | grep "^." | xargs chown user:group
For More details Click Here and Visit my Site
add a comment |
Using for-loop with ls -A
option, We can find all hidden files and directory exclude .
and ..
and then change the ownership for all hidden files and directory.
for i in `ls -A | grep "^."`;do chown -R user:group $i;done
Use xargs
option with ls -A
ls -A | grep "^." | xargs chown user:group
For More details Click Here and Visit my Site
add a comment |
Using for-loop with ls -A
option, We can find all hidden files and directory exclude .
and ..
and then change the ownership for all hidden files and directory.
for i in `ls -A | grep "^."`;do chown -R user:group $i;done
Use xargs
option with ls -A
ls -A | grep "^." | xargs chown user:group
For More details Click Here and Visit my Site
Using for-loop with ls -A
option, We can find all hidden files and directory exclude .
and ..
and then change the ownership for all hidden files and directory.
for i in `ls -A | grep "^."`;do chown -R user:group $i;done
Use xargs
option with ls -A
ls -A | grep "^." | xargs chown user:group
For More details Click Here and Visit my Site
edited Jul 8 '18 at 13:07
answered Jul 8 '18 at 12:48
Ranjeet_Automation_TesterRanjeet_Automation_Tester
112
112
add a comment |
add a comment |
To chown ALL files in current directory and subdirectories for current user;
find . -exec chown $(whoami) {} ;
or if user can't chown some files due to restricted permissions;
sudo find . -exec chown $(logname) {} ;
New contributor
add a comment |
To chown ALL files in current directory and subdirectories for current user;
find . -exec chown $(whoami) {} ;
or if user can't chown some files due to restricted permissions;
sudo find . -exec chown $(logname) {} ;
New contributor
add a comment |
To chown ALL files in current directory and subdirectories for current user;
find . -exec chown $(whoami) {} ;
or if user can't chown some files due to restricted permissions;
sudo find . -exec chown $(logname) {} ;
New contributor
To chown ALL files in current directory and subdirectories for current user;
find . -exec chown $(whoami) {} ;
or if user can't chown some files due to restricted permissions;
sudo find . -exec chown $(logname) {} ;
New contributor
New contributor
answered 2 mins ago
5p0ng3b0b5p0ng3b0b
1
1
New contributor
New contributor
add a comment |
add a comment |
You could do something like
for i in `ls -A`;do chown -R user:group $i;done
The -A
(capital A) is important as it excludes '.' and '..'
This will change only files and subdirectories in the current directory, not any lower levels. (Which may be what the OP wants.) It will also break on filenames and directory names with spaces (or tabs) in them.
– wfaulk
May 10 '12 at 22:48
add a comment |
You could do something like
for i in `ls -A`;do chown -R user:group $i;done
The -A
(capital A) is important as it excludes '.' and '..'
This will change only files and subdirectories in the current directory, not any lower levels. (Which may be what the OP wants.) It will also break on filenames and directory names with spaces (or tabs) in them.
– wfaulk
May 10 '12 at 22:48
add a comment |
You could do something like
for i in `ls -A`;do chown -R user:group $i;done
The -A
(capital A) is important as it excludes '.' and '..'
You could do something like
for i in `ls -A`;do chown -R user:group $i;done
The -A
(capital A) is important as it excludes '.' and '..'
edited May 10 '12 at 22:46
wfaulk
5,31363767
5,31363767
answered Jun 30 '10 at 20:33
ZypherZypher
34.3k44492
34.3k44492
This will change only files and subdirectories in the current directory, not any lower levels. (Which may be what the OP wants.) It will also break on filenames and directory names with spaces (or tabs) in them.
– wfaulk
May 10 '12 at 22:48
add a comment |
This will change only files and subdirectories in the current directory, not any lower levels. (Which may be what the OP wants.) It will also break on filenames and directory names with spaces (or tabs) in them.
– wfaulk
May 10 '12 at 22:48
This will change only files and subdirectories in the current directory, not any lower levels. (Which may be what the OP wants.) It will also break on filenames and directory names with spaces (or tabs) in them.
– wfaulk
May 10 '12 at 22:48
This will change only files and subdirectories in the current directory, not any lower levels. (Which may be what the OP wants.) It will also break on filenames and directory names with spaces (or tabs) in them.
– wfaulk
May 10 '12 at 22:48
add a comment |
Thanks for contributing an answer to Server Fault!
- 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%2fserverfault.com%2fquestions%2f156437%2fhow-to-chown-a-directory-recursively-including-hidden-files-or-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