How can I make chown work recursively?
I've got a directory called pdfs
that contains a bunch of sub- and sub-sub-directories. I want to change ownership on all PDF files in all of the subfolders. I just tried this:
chown -R someuser:somegroup *.pdf
...but it didn't change ownership of the PDFs in subdirectories. The user and group do exist.
According to the man page for chown
, the -R
should mean recursive:
-R, --recursive
operate on files and directories recursively
What am I missing?
unix permissions
add a comment |
I've got a directory called pdfs
that contains a bunch of sub- and sub-sub-directories. I want to change ownership on all PDF files in all of the subfolders. I just tried this:
chown -R someuser:somegroup *.pdf
...but it didn't change ownership of the PDFs in subdirectories. The user and group do exist.
According to the man page for chown
, the -R
should mean recursive:
-R, --recursive
operate on files and directories recursively
What am I missing?
unix permissions
add a comment |
I've got a directory called pdfs
that contains a bunch of sub- and sub-sub-directories. I want to change ownership on all PDF files in all of the subfolders. I just tried this:
chown -R someuser:somegroup *.pdf
...but it didn't change ownership of the PDFs in subdirectories. The user and group do exist.
According to the man page for chown
, the -R
should mean recursive:
-R, --recursive
operate on files and directories recursively
What am I missing?
unix permissions
I've got a directory called pdfs
that contains a bunch of sub- and sub-sub-directories. I want to change ownership on all PDF files in all of the subfolders. I just tried this:
chown -R someuser:somegroup *.pdf
...but it didn't change ownership of the PDFs in subdirectories. The user and group do exist.
According to the man page for chown
, the -R
should mean recursive:
-R, --recursive
operate on files and directories recursively
What am I missing?
unix permissions
unix permissions
edited Mar 22 '11 at 16:45
Pops
4,723246390
4,723246390
asked Mar 22 '11 at 16:29
Nathan LongNathan Long
10.9k2880125
10.9k2880125
add a comment |
add a comment |
7 Answers
7
active
oldest
votes
Recursive mode only works on directories, not files. By using the glob '*.pdf' the shell is passing the file list to chown, which sees these are files, and changes the permissions on the files it sees, and that's it.
Remember, in shells, the glob is evaluated by the shell, not the command. If the glob matches files, they are passed to the command and the command never knows a glob existed. (This is different than how Windows Command prompt used to do things). If you have a dir, with the contents something like:
machine:$ ls -F
file1.pdf file2.pdf other.txt subdir/
And you typed:
chown -R someuser:somegroup *.pdf
The shell would first make the list:
file1.pdf file2.pdf
and then run your command:
chown -R someuser:somegroup file1.pdf file2.pdf
See, there's no directory for -R to act on. It does what you asked it - change ownership on the two files on the command line, ignoring that quirky -R flag.
To do what you want, to use the '*.pdf' as a pattern for this directory and subdirectories, you can use find
, which can find files that match a filename pattern (or many other criterea) and pass to a subcommand
find . -type f -name '*.pdf' | xargs chown someuser:somegroup
This starts in current dir '.' to look for files (filetype f) of name pattern '*.pdf'
then passes to xargs, which constructs a command line to chmod. Notice the quotes around the pattern '*.pdf'
, remember that the shell will create a glob if it can, but you want the pattern passed to find
, so you need to quote it.
Because filenames may have spaces in them, you want to use a trick to make it filename-with-spaces safe:
find . -type f -name '*.pdf' -print0 | xargs -0 chown someuser:somegroup
In bash 3 and lower, this is the way you need to do it. More powerful globbing is available in bash 4 (with shopt -s globstar
)and other shells. The same in zsh, using a recursive glob **
:
chown -R someuser:somegroup ./**/*.pdf
1
Edited to reflect that bash 4 withshopt -s globstar
does recursive globbing.
– kojiro
Mar 22 '11 at 22:54
@kojiro thanks! as you can tell I still use bash3
– Rich Homolka
Mar 22 '11 at 22:58
2
Per the man page shown by the original poster, I found the chown -R did indeed change owner on folders AND files. No need for find. Using Mint 15.
– gwideman
Sep 28 '13 at 12:23
@gwideman I know this is old... But yes, of course -R does recursive. The OP just had an issue with a very specific type of recursion, an extension and "file type is file" filtered one
– Rich Homolka
Mar 7 '15 at 23:40
@RichHomolka Ah. OP said the files were in a directory called 'pdfs', so I assumed the problem was in how to specify pdfs as the directory to recurse, and that all contained files were pdfs, so no need to select them specifically. But you may well be right, if the job is to select only pdf files, and leave others unchanged.
– gwideman
Mar 8 '15 at 23:51
add a comment |
It's not complicated.
chown -R someuser:somegroup /your/folder/here/*
This will apply chown to all files and all subdirectories and sub-subdirectories of the specified folder. Use with care.
Clearly someone answer it since 4 years, but ty for the warning.
– Francisco Tapia
Nov 9 '15 at 17:22
2
This question is currently #1 on Google, so it's important to note the correct answer.
– Sprachprofi
Nov 10 '15 at 10:12
sure, the accepted one is more elegant, readable and complete
– Francisco Tapia
Nov 10 '15 at 11:59
2
Somehowsudo chown -R user ./
worked for me, butsudo chown -R user ./*
didn't
– Slav
Jun 4 '18 at 8:14
1
I know this is old, but though this answers the headline, does not answer the question. This is actually slightly worse than what OP had already tried.
– Rich Homolka
Jul 20 '18 at 15:29
add a comment |
You can use the find
utility:
find . -name '*.pdf' -exec chown someuser:somegroup {} +
Please don't forget the quotes around *.pdf
. Otherwise the shell will try to expand it. This means already the shell will replace *.pdf
with the names of all PDF files found in the current directory. But that's not what you want. You want to find the PDF files located in subdirectories. Btw.: That's also the problem with your chown
command.
1
I had to look up the+
, neat trick for performance.-exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way thatxargs
builds its command lines. Only one instance of{}
is allowed within the command. The command is executed in the starting directory.
– Patrick M
Jan 13 '14 at 18:28
@PatrickM one (minor) other advantage to + vs ; .... plus isn’t a shell meta character and doesn’t have to be escaped
– Rich Homolka
Jul 20 '18 at 14:36
add a comment |
The command
chown -R someuser:somegroup *.pdf
will only recurse down directories if the directory name ends in .pdf. You need something like:
find . -name "*.pdf" -exec chown someuser:somegroup {} ;
Technically it will only go to one level down. whether you call that true recursion or not is an exercise for the user :)
– Rich Homolka
Apr 6 '15 at 21:28
add a comment |
to change the ownership of a directory recursively simply use:
sudo chown -R <username>:<groupname> <dir name>
here username = the new user who should be owner of directory
groupname = the new group which should be owner of directory
every file/directory has a user owner and a group owner
This does not do what the OP asked. This changes ownership of everything, OP asked for a specific set of files.
– Rich Homolka
Jan 15 '17 at 18:50
add a comment |
I use tree
instead:
sudo tree -fai ~/.blabla | xargs -L1 -I{} sudo chown youruser:youruser {}
Also take care to not run recursive chown or chmod on '/' directory or other system directory.
add a comment |
To become the owner of all files in a directory, use
find directory -type f -name '*' | sudo xargs -d 'n' chown $USER
instead of
sudo chown $USER directory*
or
sudo chown --recursive $USER directory
which might not work if there are too many arguments produced by * (too many files in the directory) or which does not not do what you want respectively.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f260925%2fhow-can-i-make-chown-work-recursively%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
Recursive mode only works on directories, not files. By using the glob '*.pdf' the shell is passing the file list to chown, which sees these are files, and changes the permissions on the files it sees, and that's it.
Remember, in shells, the glob is evaluated by the shell, not the command. If the glob matches files, they are passed to the command and the command never knows a glob existed. (This is different than how Windows Command prompt used to do things). If you have a dir, with the contents something like:
machine:$ ls -F
file1.pdf file2.pdf other.txt subdir/
And you typed:
chown -R someuser:somegroup *.pdf
The shell would first make the list:
file1.pdf file2.pdf
and then run your command:
chown -R someuser:somegroup file1.pdf file2.pdf
See, there's no directory for -R to act on. It does what you asked it - change ownership on the two files on the command line, ignoring that quirky -R flag.
To do what you want, to use the '*.pdf' as a pattern for this directory and subdirectories, you can use find
, which can find files that match a filename pattern (or many other criterea) and pass to a subcommand
find . -type f -name '*.pdf' | xargs chown someuser:somegroup
This starts in current dir '.' to look for files (filetype f) of name pattern '*.pdf'
then passes to xargs, which constructs a command line to chmod. Notice the quotes around the pattern '*.pdf'
, remember that the shell will create a glob if it can, but you want the pattern passed to find
, so you need to quote it.
Because filenames may have spaces in them, you want to use a trick to make it filename-with-spaces safe:
find . -type f -name '*.pdf' -print0 | xargs -0 chown someuser:somegroup
In bash 3 and lower, this is the way you need to do it. More powerful globbing is available in bash 4 (with shopt -s globstar
)and other shells. The same in zsh, using a recursive glob **
:
chown -R someuser:somegroup ./**/*.pdf
1
Edited to reflect that bash 4 withshopt -s globstar
does recursive globbing.
– kojiro
Mar 22 '11 at 22:54
@kojiro thanks! as you can tell I still use bash3
– Rich Homolka
Mar 22 '11 at 22:58
2
Per the man page shown by the original poster, I found the chown -R did indeed change owner on folders AND files. No need for find. Using Mint 15.
– gwideman
Sep 28 '13 at 12:23
@gwideman I know this is old... But yes, of course -R does recursive. The OP just had an issue with a very specific type of recursion, an extension and "file type is file" filtered one
– Rich Homolka
Mar 7 '15 at 23:40
@RichHomolka Ah. OP said the files were in a directory called 'pdfs', so I assumed the problem was in how to specify pdfs as the directory to recurse, and that all contained files were pdfs, so no need to select them specifically. But you may well be right, if the job is to select only pdf files, and leave others unchanged.
– gwideman
Mar 8 '15 at 23:51
add a comment |
Recursive mode only works on directories, not files. By using the glob '*.pdf' the shell is passing the file list to chown, which sees these are files, and changes the permissions on the files it sees, and that's it.
Remember, in shells, the glob is evaluated by the shell, not the command. If the glob matches files, they are passed to the command and the command never knows a glob existed. (This is different than how Windows Command prompt used to do things). If you have a dir, with the contents something like:
machine:$ ls -F
file1.pdf file2.pdf other.txt subdir/
And you typed:
chown -R someuser:somegroup *.pdf
The shell would first make the list:
file1.pdf file2.pdf
and then run your command:
chown -R someuser:somegroup file1.pdf file2.pdf
See, there's no directory for -R to act on. It does what you asked it - change ownership on the two files on the command line, ignoring that quirky -R flag.
To do what you want, to use the '*.pdf' as a pattern for this directory and subdirectories, you can use find
, which can find files that match a filename pattern (or many other criterea) and pass to a subcommand
find . -type f -name '*.pdf' | xargs chown someuser:somegroup
This starts in current dir '.' to look for files (filetype f) of name pattern '*.pdf'
then passes to xargs, which constructs a command line to chmod. Notice the quotes around the pattern '*.pdf'
, remember that the shell will create a glob if it can, but you want the pattern passed to find
, so you need to quote it.
Because filenames may have spaces in them, you want to use a trick to make it filename-with-spaces safe:
find . -type f -name '*.pdf' -print0 | xargs -0 chown someuser:somegroup
In bash 3 and lower, this is the way you need to do it. More powerful globbing is available in bash 4 (with shopt -s globstar
)and other shells. The same in zsh, using a recursive glob **
:
chown -R someuser:somegroup ./**/*.pdf
1
Edited to reflect that bash 4 withshopt -s globstar
does recursive globbing.
– kojiro
Mar 22 '11 at 22:54
@kojiro thanks! as you can tell I still use bash3
– Rich Homolka
Mar 22 '11 at 22:58
2
Per the man page shown by the original poster, I found the chown -R did indeed change owner on folders AND files. No need for find. Using Mint 15.
– gwideman
Sep 28 '13 at 12:23
@gwideman I know this is old... But yes, of course -R does recursive. The OP just had an issue with a very specific type of recursion, an extension and "file type is file" filtered one
– Rich Homolka
Mar 7 '15 at 23:40
@RichHomolka Ah. OP said the files were in a directory called 'pdfs', so I assumed the problem was in how to specify pdfs as the directory to recurse, and that all contained files were pdfs, so no need to select them specifically. But you may well be right, if the job is to select only pdf files, and leave others unchanged.
– gwideman
Mar 8 '15 at 23:51
add a comment |
Recursive mode only works on directories, not files. By using the glob '*.pdf' the shell is passing the file list to chown, which sees these are files, and changes the permissions on the files it sees, and that's it.
Remember, in shells, the glob is evaluated by the shell, not the command. If the glob matches files, they are passed to the command and the command never knows a glob existed. (This is different than how Windows Command prompt used to do things). If you have a dir, with the contents something like:
machine:$ ls -F
file1.pdf file2.pdf other.txt subdir/
And you typed:
chown -R someuser:somegroup *.pdf
The shell would first make the list:
file1.pdf file2.pdf
and then run your command:
chown -R someuser:somegroup file1.pdf file2.pdf
See, there's no directory for -R to act on. It does what you asked it - change ownership on the two files on the command line, ignoring that quirky -R flag.
To do what you want, to use the '*.pdf' as a pattern for this directory and subdirectories, you can use find
, which can find files that match a filename pattern (or many other criterea) and pass to a subcommand
find . -type f -name '*.pdf' | xargs chown someuser:somegroup
This starts in current dir '.' to look for files (filetype f) of name pattern '*.pdf'
then passes to xargs, which constructs a command line to chmod. Notice the quotes around the pattern '*.pdf'
, remember that the shell will create a glob if it can, but you want the pattern passed to find
, so you need to quote it.
Because filenames may have spaces in them, you want to use a trick to make it filename-with-spaces safe:
find . -type f -name '*.pdf' -print0 | xargs -0 chown someuser:somegroup
In bash 3 and lower, this is the way you need to do it. More powerful globbing is available in bash 4 (with shopt -s globstar
)and other shells. The same in zsh, using a recursive glob **
:
chown -R someuser:somegroup ./**/*.pdf
Recursive mode only works on directories, not files. By using the glob '*.pdf' the shell is passing the file list to chown, which sees these are files, and changes the permissions on the files it sees, and that's it.
Remember, in shells, the glob is evaluated by the shell, not the command. If the glob matches files, they are passed to the command and the command never knows a glob existed. (This is different than how Windows Command prompt used to do things). If you have a dir, with the contents something like:
machine:$ ls -F
file1.pdf file2.pdf other.txt subdir/
And you typed:
chown -R someuser:somegroup *.pdf
The shell would first make the list:
file1.pdf file2.pdf
and then run your command:
chown -R someuser:somegroup file1.pdf file2.pdf
See, there's no directory for -R to act on. It does what you asked it - change ownership on the two files on the command line, ignoring that quirky -R flag.
To do what you want, to use the '*.pdf' as a pattern for this directory and subdirectories, you can use find
, which can find files that match a filename pattern (or many other criterea) and pass to a subcommand
find . -type f -name '*.pdf' | xargs chown someuser:somegroup
This starts in current dir '.' to look for files (filetype f) of name pattern '*.pdf'
then passes to xargs, which constructs a command line to chmod. Notice the quotes around the pattern '*.pdf'
, remember that the shell will create a glob if it can, but you want the pattern passed to find
, so you need to quote it.
Because filenames may have spaces in them, you want to use a trick to make it filename-with-spaces safe:
find . -type f -name '*.pdf' -print0 | xargs -0 chown someuser:somegroup
In bash 3 and lower, this is the way you need to do it. More powerful globbing is available in bash 4 (with shopt -s globstar
)and other shells. The same in zsh, using a recursive glob **
:
chown -R someuser:somegroup ./**/*.pdf
edited Apr 1 '15 at 18:54
answered Mar 22 '11 at 16:47
Rich HomolkaRich Homolka
25.4k64367
25.4k64367
1
Edited to reflect that bash 4 withshopt -s globstar
does recursive globbing.
– kojiro
Mar 22 '11 at 22:54
@kojiro thanks! as you can tell I still use bash3
– Rich Homolka
Mar 22 '11 at 22:58
2
Per the man page shown by the original poster, I found the chown -R did indeed change owner on folders AND files. No need for find. Using Mint 15.
– gwideman
Sep 28 '13 at 12:23
@gwideman I know this is old... But yes, of course -R does recursive. The OP just had an issue with a very specific type of recursion, an extension and "file type is file" filtered one
– Rich Homolka
Mar 7 '15 at 23:40
@RichHomolka Ah. OP said the files were in a directory called 'pdfs', so I assumed the problem was in how to specify pdfs as the directory to recurse, and that all contained files were pdfs, so no need to select them specifically. But you may well be right, if the job is to select only pdf files, and leave others unchanged.
– gwideman
Mar 8 '15 at 23:51
add a comment |
1
Edited to reflect that bash 4 withshopt -s globstar
does recursive globbing.
– kojiro
Mar 22 '11 at 22:54
@kojiro thanks! as you can tell I still use bash3
– Rich Homolka
Mar 22 '11 at 22:58
2
Per the man page shown by the original poster, I found the chown -R did indeed change owner on folders AND files. No need for find. Using Mint 15.
– gwideman
Sep 28 '13 at 12:23
@gwideman I know this is old... But yes, of course -R does recursive. The OP just had an issue with a very specific type of recursion, an extension and "file type is file" filtered one
– Rich Homolka
Mar 7 '15 at 23:40
@RichHomolka Ah. OP said the files were in a directory called 'pdfs', so I assumed the problem was in how to specify pdfs as the directory to recurse, and that all contained files were pdfs, so no need to select them specifically. But you may well be right, if the job is to select only pdf files, and leave others unchanged.
– gwideman
Mar 8 '15 at 23:51
1
1
Edited to reflect that bash 4 with
shopt -s globstar
does recursive globbing.– kojiro
Mar 22 '11 at 22:54
Edited to reflect that bash 4 with
shopt -s globstar
does recursive globbing.– kojiro
Mar 22 '11 at 22:54
@kojiro thanks! as you can tell I still use bash3
– Rich Homolka
Mar 22 '11 at 22:58
@kojiro thanks! as you can tell I still use bash3
– Rich Homolka
Mar 22 '11 at 22:58
2
2
Per the man page shown by the original poster, I found the chown -R did indeed change owner on folders AND files. No need for find. Using Mint 15.
– gwideman
Sep 28 '13 at 12:23
Per the man page shown by the original poster, I found the chown -R did indeed change owner on folders AND files. No need for find. Using Mint 15.
– gwideman
Sep 28 '13 at 12:23
@gwideman I know this is old... But yes, of course -R does recursive. The OP just had an issue with a very specific type of recursion, an extension and "file type is file" filtered one
– Rich Homolka
Mar 7 '15 at 23:40
@gwideman I know this is old... But yes, of course -R does recursive. The OP just had an issue with a very specific type of recursion, an extension and "file type is file" filtered one
– Rich Homolka
Mar 7 '15 at 23:40
@RichHomolka Ah. OP said the files were in a directory called 'pdfs', so I assumed the problem was in how to specify pdfs as the directory to recurse, and that all contained files were pdfs, so no need to select them specifically. But you may well be right, if the job is to select only pdf files, and leave others unchanged.
– gwideman
Mar 8 '15 at 23:51
@RichHomolka Ah. OP said the files were in a directory called 'pdfs', so I assumed the problem was in how to specify pdfs as the directory to recurse, and that all contained files were pdfs, so no need to select them specifically. But you may well be right, if the job is to select only pdf files, and leave others unchanged.
– gwideman
Mar 8 '15 at 23:51
add a comment |
It's not complicated.
chown -R someuser:somegroup /your/folder/here/*
This will apply chown to all files and all subdirectories and sub-subdirectories of the specified folder. Use with care.
Clearly someone answer it since 4 years, but ty for the warning.
– Francisco Tapia
Nov 9 '15 at 17:22
2
This question is currently #1 on Google, so it's important to note the correct answer.
– Sprachprofi
Nov 10 '15 at 10:12
sure, the accepted one is more elegant, readable and complete
– Francisco Tapia
Nov 10 '15 at 11:59
2
Somehowsudo chown -R user ./
worked for me, butsudo chown -R user ./*
didn't
– Slav
Jun 4 '18 at 8:14
1
I know this is old, but though this answers the headline, does not answer the question. This is actually slightly worse than what OP had already tried.
– Rich Homolka
Jul 20 '18 at 15:29
add a comment |
It's not complicated.
chown -R someuser:somegroup /your/folder/here/*
This will apply chown to all files and all subdirectories and sub-subdirectories of the specified folder. Use with care.
Clearly someone answer it since 4 years, but ty for the warning.
– Francisco Tapia
Nov 9 '15 at 17:22
2
This question is currently #1 on Google, so it's important to note the correct answer.
– Sprachprofi
Nov 10 '15 at 10:12
sure, the accepted one is more elegant, readable and complete
– Francisco Tapia
Nov 10 '15 at 11:59
2
Somehowsudo chown -R user ./
worked for me, butsudo chown -R user ./*
didn't
– Slav
Jun 4 '18 at 8:14
1
I know this is old, but though this answers the headline, does not answer the question. This is actually slightly worse than what OP had already tried.
– Rich Homolka
Jul 20 '18 at 15:29
add a comment |
It's not complicated.
chown -R someuser:somegroup /your/folder/here/*
This will apply chown to all files and all subdirectories and sub-subdirectories of the specified folder. Use with care.
It's not complicated.
chown -R someuser:somegroup /your/folder/here/*
This will apply chown to all files and all subdirectories and sub-subdirectories of the specified folder. Use with care.
answered Nov 9 '15 at 11:44
SprachprofiSprachprofi
50144
50144
Clearly someone answer it since 4 years, but ty for the warning.
– Francisco Tapia
Nov 9 '15 at 17:22
2
This question is currently #1 on Google, so it's important to note the correct answer.
– Sprachprofi
Nov 10 '15 at 10:12
sure, the accepted one is more elegant, readable and complete
– Francisco Tapia
Nov 10 '15 at 11:59
2
Somehowsudo chown -R user ./
worked for me, butsudo chown -R user ./*
didn't
– Slav
Jun 4 '18 at 8:14
1
I know this is old, but though this answers the headline, does not answer the question. This is actually slightly worse than what OP had already tried.
– Rich Homolka
Jul 20 '18 at 15:29
add a comment |
Clearly someone answer it since 4 years, but ty for the warning.
– Francisco Tapia
Nov 9 '15 at 17:22
2
This question is currently #1 on Google, so it's important to note the correct answer.
– Sprachprofi
Nov 10 '15 at 10:12
sure, the accepted one is more elegant, readable and complete
– Francisco Tapia
Nov 10 '15 at 11:59
2
Somehowsudo chown -R user ./
worked for me, butsudo chown -R user ./*
didn't
– Slav
Jun 4 '18 at 8:14
1
I know this is old, but though this answers the headline, does not answer the question. This is actually slightly worse than what OP had already tried.
– Rich Homolka
Jul 20 '18 at 15:29
Clearly someone answer it since 4 years, but ty for the warning.
– Francisco Tapia
Nov 9 '15 at 17:22
Clearly someone answer it since 4 years, but ty for the warning.
– Francisco Tapia
Nov 9 '15 at 17:22
2
2
This question is currently #1 on Google, so it's important to note the correct answer.
– Sprachprofi
Nov 10 '15 at 10:12
This question is currently #1 on Google, so it's important to note the correct answer.
– Sprachprofi
Nov 10 '15 at 10:12
sure, the accepted one is more elegant, readable and complete
– Francisco Tapia
Nov 10 '15 at 11:59
sure, the accepted one is more elegant, readable and complete
– Francisco Tapia
Nov 10 '15 at 11:59
2
2
Somehow
sudo chown -R user ./
worked for me, but sudo chown -R user ./*
didn't– Slav
Jun 4 '18 at 8:14
Somehow
sudo chown -R user ./
worked for me, but sudo chown -R user ./*
didn't– Slav
Jun 4 '18 at 8:14
1
1
I know this is old, but though this answers the headline, does not answer the question. This is actually slightly worse than what OP had already tried.
– Rich Homolka
Jul 20 '18 at 15:29
I know this is old, but though this answers the headline, does not answer the question. This is actually slightly worse than what OP had already tried.
– Rich Homolka
Jul 20 '18 at 15:29
add a comment |
You can use the find
utility:
find . -name '*.pdf' -exec chown someuser:somegroup {} +
Please don't forget the quotes around *.pdf
. Otherwise the shell will try to expand it. This means already the shell will replace *.pdf
with the names of all PDF files found in the current directory. But that's not what you want. You want to find the PDF files located in subdirectories. Btw.: That's also the problem with your chown
command.
1
I had to look up the+
, neat trick for performance.-exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way thatxargs
builds its command lines. Only one instance of{}
is allowed within the command. The command is executed in the starting directory.
– Patrick M
Jan 13 '14 at 18:28
@PatrickM one (minor) other advantage to + vs ; .... plus isn’t a shell meta character and doesn’t have to be escaped
– Rich Homolka
Jul 20 '18 at 14:36
add a comment |
You can use the find
utility:
find . -name '*.pdf' -exec chown someuser:somegroup {} +
Please don't forget the quotes around *.pdf
. Otherwise the shell will try to expand it. This means already the shell will replace *.pdf
with the names of all PDF files found in the current directory. But that's not what you want. You want to find the PDF files located in subdirectories. Btw.: That's also the problem with your chown
command.
1
I had to look up the+
, neat trick for performance.-exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way thatxargs
builds its command lines. Only one instance of{}
is allowed within the command. The command is executed in the starting directory.
– Patrick M
Jan 13 '14 at 18:28
@PatrickM one (minor) other advantage to + vs ; .... plus isn’t a shell meta character and doesn’t have to be escaped
– Rich Homolka
Jul 20 '18 at 14:36
add a comment |
You can use the find
utility:
find . -name '*.pdf' -exec chown someuser:somegroup {} +
Please don't forget the quotes around *.pdf
. Otherwise the shell will try to expand it. This means already the shell will replace *.pdf
with the names of all PDF files found in the current directory. But that's not what you want. You want to find the PDF files located in subdirectories. Btw.: That's also the problem with your chown
command.
You can use the find
utility:
find . -name '*.pdf' -exec chown someuser:somegroup {} +
Please don't forget the quotes around *.pdf
. Otherwise the shell will try to expand it. This means already the shell will replace *.pdf
with the names of all PDF files found in the current directory. But that's not what you want. You want to find the PDF files located in subdirectories. Btw.: That's also the problem with your chown
command.
answered Mar 22 '11 at 16:37
bmkbmk
1,5991011
1,5991011
1
I had to look up the+
, neat trick for performance.-exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way thatxargs
builds its command lines. Only one instance of{}
is allowed within the command. The command is executed in the starting directory.
– Patrick M
Jan 13 '14 at 18:28
@PatrickM one (minor) other advantage to + vs ; .... plus isn’t a shell meta character and doesn’t have to be escaped
– Rich Homolka
Jul 20 '18 at 14:36
add a comment |
1
I had to look up the+
, neat trick for performance.-exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way thatxargs
builds its command lines. Only one instance of{}
is allowed within the command. The command is executed in the starting directory.
– Patrick M
Jan 13 '14 at 18:28
@PatrickM one (minor) other advantage to + vs ; .... plus isn’t a shell meta character and doesn’t have to be escaped
– Rich Homolka
Jul 20 '18 at 14:36
1
1
I had to look up the
+
, neat trick for performance. -exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way that xargs
builds its command lines. Only one instance of {}
is allowed within the command. The command is executed in the starting directory.– Patrick M
Jan 13 '14 at 18:28
I had to look up the
+
, neat trick for performance. -exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way that xargs
builds its command lines. Only one instance of {}
is allowed within the command. The command is executed in the starting directory.– Patrick M
Jan 13 '14 at 18:28
@PatrickM one (minor) other advantage to + vs ; .... plus isn’t a shell meta character and doesn’t have to be escaped
– Rich Homolka
Jul 20 '18 at 14:36
@PatrickM one (minor) other advantage to + vs ; .... plus isn’t a shell meta character and doesn’t have to be escaped
– Rich Homolka
Jul 20 '18 at 14:36
add a comment |
The command
chown -R someuser:somegroup *.pdf
will only recurse down directories if the directory name ends in .pdf. You need something like:
find . -name "*.pdf" -exec chown someuser:somegroup {} ;
Technically it will only go to one level down. whether you call that true recursion or not is an exercise for the user :)
– Rich Homolka
Apr 6 '15 at 21:28
add a comment |
The command
chown -R someuser:somegroup *.pdf
will only recurse down directories if the directory name ends in .pdf. You need something like:
find . -name "*.pdf" -exec chown someuser:somegroup {} ;
Technically it will only go to one level down. whether you call that true recursion or not is an exercise for the user :)
– Rich Homolka
Apr 6 '15 at 21:28
add a comment |
The command
chown -R someuser:somegroup *.pdf
will only recurse down directories if the directory name ends in .pdf. You need something like:
find . -name "*.pdf" -exec chown someuser:somegroup {} ;
The command
chown -R someuser:somegroup *.pdf
will only recurse down directories if the directory name ends in .pdf. You need something like:
find . -name "*.pdf" -exec chown someuser:somegroup {} ;
answered Mar 22 '11 at 16:38
Mike ScottMike Scott
4,1001217
4,1001217
Technically it will only go to one level down. whether you call that true recursion or not is an exercise for the user :)
– Rich Homolka
Apr 6 '15 at 21:28
add a comment |
Technically it will only go to one level down. whether you call that true recursion or not is an exercise for the user :)
– Rich Homolka
Apr 6 '15 at 21:28
Technically it will only go to one level down. whether you call that true recursion or not is an exercise for the user :)
– Rich Homolka
Apr 6 '15 at 21:28
Technically it will only go to one level down. whether you call that true recursion or not is an exercise for the user :)
– Rich Homolka
Apr 6 '15 at 21:28
add a comment |
to change the ownership of a directory recursively simply use:
sudo chown -R <username>:<groupname> <dir name>
here username = the new user who should be owner of directory
groupname = the new group which should be owner of directory
every file/directory has a user owner and a group owner
This does not do what the OP asked. This changes ownership of everything, OP asked for a specific set of files.
– Rich Homolka
Jan 15 '17 at 18:50
add a comment |
to change the ownership of a directory recursively simply use:
sudo chown -R <username>:<groupname> <dir name>
here username = the new user who should be owner of directory
groupname = the new group which should be owner of directory
every file/directory has a user owner and a group owner
This does not do what the OP asked. This changes ownership of everything, OP asked for a specific set of files.
– Rich Homolka
Jan 15 '17 at 18:50
add a comment |
to change the ownership of a directory recursively simply use:
sudo chown -R <username>:<groupname> <dir name>
here username = the new user who should be owner of directory
groupname = the new group which should be owner of directory
every file/directory has a user owner and a group owner
to change the ownership of a directory recursively simply use:
sudo chown -R <username>:<groupname> <dir name>
here username = the new user who should be owner of directory
groupname = the new group which should be owner of directory
every file/directory has a user owner and a group owner
answered May 11 '16 at 1:38
KawaiKxKawaiKx
3852413
3852413
This does not do what the OP asked. This changes ownership of everything, OP asked for a specific set of files.
– Rich Homolka
Jan 15 '17 at 18:50
add a comment |
This does not do what the OP asked. This changes ownership of everything, OP asked for a specific set of files.
– Rich Homolka
Jan 15 '17 at 18:50
This does not do what the OP asked. This changes ownership of everything, OP asked for a specific set of files.
– Rich Homolka
Jan 15 '17 at 18:50
This does not do what the OP asked. This changes ownership of everything, OP asked for a specific set of files.
– Rich Homolka
Jan 15 '17 at 18:50
add a comment |
I use tree
instead:
sudo tree -fai ~/.blabla | xargs -L1 -I{} sudo chown youruser:youruser {}
Also take care to not run recursive chown or chmod on '/' directory or other system directory.
add a comment |
I use tree
instead:
sudo tree -fai ~/.blabla | xargs -L1 -I{} sudo chown youruser:youruser {}
Also take care to not run recursive chown or chmod on '/' directory or other system directory.
add a comment |
I use tree
instead:
sudo tree -fai ~/.blabla | xargs -L1 -I{} sudo chown youruser:youruser {}
Also take care to not run recursive chown or chmod on '/' directory or other system directory.
I use tree
instead:
sudo tree -fai ~/.blabla | xargs -L1 -I{} sudo chown youruser:youruser {}
Also take care to not run recursive chown or chmod on '/' directory or other system directory.
answered Jan 25 '18 at 13:36
Eduard FlorinescuEduard Florinescu
1,23352039
1,23352039
add a comment |
add a comment |
To become the owner of all files in a directory, use
find directory -type f -name '*' | sudo xargs -d 'n' chown $USER
instead of
sudo chown $USER directory*
or
sudo chown --recursive $USER directory
which might not work if there are too many arguments produced by * (too many files in the directory) or which does not not do what you want respectively.
add a comment |
To become the owner of all files in a directory, use
find directory -type f -name '*' | sudo xargs -d 'n' chown $USER
instead of
sudo chown $USER directory*
or
sudo chown --recursive $USER directory
which might not work if there are too many arguments produced by * (too many files in the directory) or which does not not do what you want respectively.
add a comment |
To become the owner of all files in a directory, use
find directory -type f -name '*' | sudo xargs -d 'n' chown $USER
instead of
sudo chown $USER directory*
or
sudo chown --recursive $USER directory
which might not work if there are too many arguments produced by * (too many files in the directory) or which does not not do what you want respectively.
To become the owner of all files in a directory, use
find directory -type f -name '*' | sudo xargs -d 'n' chown $USER
instead of
sudo chown $USER directory*
or
sudo chown --recursive $USER directory
which might not work if there are too many arguments produced by * (too many files in the directory) or which does not not do what you want respectively.
answered Jan 29 at 20:22
masterxilomasterxilo
25517
25517
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f260925%2fhow-can-i-make-chown-work-recursively%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