[SOLVED] Command line: chown command recursively on invisible directories?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Rep:
Command line: chown command recursively on invisible directories?
I tried
Code:
chown -R owner:group *
which does not work on the invisible directories (why?). When I used ".*" as wildcard it changed all (visible) files including the parent directory (the one I was currently working in which is the "dot") .
I can change the invisible directories owner and group using dophin but how is it done from the command line?
Click here to see the post LQ members have rated as the most helpful post in this thread.
I never noticed that but it may be something in how the wild card designation "*" works in conjunction with the "R" flag. Normally, I would run the command using the full path to the directory whose files I wanted to recursively change the ownership of, eg:
$ chown -R owner:group <path to target directory>
Try it that way and see if it works on the hidden directories/files contained in your target directory.
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Original Poster
Rep:
@neonsignal: Thanks for an extremely concise, but to the point, correct and complete solution (man pages helped to understand the background, as usual ).
@kilgoretrout: I'll try it tomorrow, I'm not at home now.
@GrapefruiTgirl: True to the spirit, I see. And with the escaping scheme the least typing work. Kudos.
Keep in mind that using chown with the full path is no different to using it on '.', and will also change the ownership on the directory itself (which may be what you want).
ie, this:
Code:
chown -R owner:group /home/user/test/
will do the same as this:
Code:
cd /home/user/test
chown -R owner:group .
Last edited by neonsignal; 10-28-2010 at 06:14 AM.
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Original Poster
Rep:
Quote:
Originally Posted by neonsignal
Keep in mind that using chown with the full path is no different to using it on '.', and will also change the ownership on the directory itself (which may be what you want).
It is what I wanted. But I have a problem to understand the exact difference between
Code:
chown -R owner:group *
and
hown -R owner:group .
The first I tried with the unwanted results. But what is the difference for "bash"?
In the second of these, bash hands the '.' to chown. The chown is then applied to that file (which is the current working directory), and recursively to any files below it in the file hierarchy. Hidden files are not treated any differently by chown.
In the first of these, bash expands the '*' glob before handing the list to chown. The default is to expand it to a list of all the files in the current working directory, not including hidden files. So chown is being applied to this list, and recursively to files below that, but not to the current working directory. Since the names of hidden files were not even handed to chown, there is no reason for it to change them.
Incidentally, using '.*' has even worse side effects. Because not only does it include the current working directory, but it also includes the parent directory '..'. So the chown will not only be applied to the parent, but recursively to all the files/directories in the parent directory (ie, 'siblings' of the current working directory). Escaping the '.' does not change the behaviour, because the '.' is not a special character.
You can use echo to see the actual commands that would be run after the glob expansion, which may make it clearer:
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Original Poster
Rep:
Ahhh, now I get it. Again an exceptionally lucid answer. The trick with "echo" is super as well, I'll remember that one. Kudos and thanks, neonsignal .
P.S.: Anybody of all these gurus here ready for a take on this one:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.