[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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.3, MX-18, Mandrake
Posts: 4,433
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 18.3+19.3, MX-18, Mandrake
Posts: 4,433
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 07:14 AM.
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.3, MX-18, Mandrake
Posts: 4,433
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.