LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 10-25-2010, 05:03 AM   #1
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
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.
Old 10-25-2010, 05:44 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
You can change the glob expansion to include hidden files by setting the dotglob shell option:
Code:
shopt -s dotglob; chown -R owner:group *; shopt -u dotglob
 
1 members found this post helpful.
Old 10-25-2010, 05:47 AM   #3
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,987

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
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.
 
1 members found this post helpful.
Old 10-25-2010, 05:56 AM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
chown -R ; escape the dot

In the interest of "more ways to do things", you can also escape the "." to chown any/all files/directories:
Code:
root@reactor: ls -laR
.:
total 76
drwxr-xr-x 4 root root  4096 Oct 25 07:38 .
drwxr-xr-x 9 root root  4096 Oct 22 18:11 ..
-rw-r--r-- 1 root root    23 Oct 23 19:16 .dashfile.sh
drwxr-xr-x 2 root root  4096 Oct 25 07:43 .hidden_dir
drwxr-xr-x 2 root root  4096 Oct 24 20:02 Radio-test
-rw-r--r-- 1 root root    24 Oct 22 18:12 bashfile-space.sh
-rw-r--r-- 1 root root    23 Oct 22 18:12 bashfile.sh
-rw-r--r-- 1 root root    24 Oct 22 18:12 dashfile-space.sh
-rw-r--r-- 1 root root    23 Oct 22 18:12 dashfile.sh
-rwxr-xr-x 1 root root    78 Oct 23 22:15 getopts_tester.sh
-rw-r--r-- 1 root root 15933 Oct 22 21:00 script_locator.output
-rwxr-xr-x 1 root root  1381 Oct 23 12:15 script_locator.sh
-rw-r--r-- 1 root root    22 Oct 22 18:12 shfile-space.sh
-rw-r--r-- 1 root root    21 Oct 22 18:13 shfile.sh
-rw-r--r-- 1 root root   485 Oct 22 20:15 somefile
-rwxr-xr-x 1 root root    24 Oct 23 13:26 testing

./.hidden_dir:
total 8
drwxr-xr-x 2 root root 4096 Oct 25 07:43 .
drwxr-xr-x 4 root root 4096 Oct 25 07:38 ..
-rw-r--r-- 1 root root    0 Oct 25 07:43 .hidden_file



root@reactor: chown -R sasha:users \.*
root@reactor: ls -laR
.:
total 76
drwxr-xr-x 4 sasha users  4096 Oct 25 07:38 .
drwxr-xr-x 9 sasha users  4096 Oct 22 18:11 ..
-rw-r--r-- 1 sasha users    23 Oct 23 19:16 .dashfile.sh
drwxr-xr-x 2 sasha users  4096 Oct 25 07:43 .hidden_dir
drwxr-xr-x 2 sasha users  4096 Oct 24 20:02 Radio-test
-rw-r--r-- 1 sasha users    24 Oct 22 18:12 bashfile-space.sh
-rw-r--r-- 1 sasha users    23 Oct 22 18:12 bashfile.sh
-rw-r--r-- 1 sasha users    24 Oct 22 18:12 dashfile-space.sh
-rw-r--r-- 1 sasha users    23 Oct 22 18:12 dashfile.sh
-rwxr-xr-x 1 sasha users    78 Oct 23 22:15 getopts_tester.sh
-rw-r--r-- 1 sasha users 15933 Oct 22 21:00 script_locator.output
-rwxr-xr-x 1 sasha users  1381 Oct 23 12:15 script_locator.sh
-rw-r--r-- 1 sasha users    22 Oct 22 18:12 shfile-space.sh
-rw-r--r-- 1 sasha users    21 Oct 22 18:13 shfile.sh
-rw-r--r-- 1 sasha users   485 Oct 22 20:15 somefile
-rwxr-xr-x 1 sasha users    24 Oct 23 13:26 testing

./.hidden_dir:
total 8
drwxr-xr-x 2 sasha users 4096 Oct 25 07:43 .
drwxr-xr-x 4 sasha users 4096 Oct 25 07:38 ..
-rw-r--r-- 1 sasha users    0 Oct 25 07:43 .hidden_file
 
2 members found this post helpful.
Old 10-25-2010, 06:27 AM   #5
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Original Poster
Rep: Reputation: Disabled
@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.

Thank you all for your input.

Last edited by JZL240I-U; 10-25-2010 at 06:28 AM.
 
Old 10-28-2010, 05:01 AM   #6
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Original Poster
Rep: Reputation: Disabled
@kilgoretrout: Works with path exactly as you said it would. Thanks again.
 
Old 10-28-2010, 06:04 AM   #7
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by JZL240I-U View Post
Works with path exactly as you said it would.
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.
 
1 members found this post helpful.
Old 10-28-2010, 02:22 PM   #8
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by neonsignal View Post
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"?
 
Old 10-28-2010, 05:14 PM   #9
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by JZL240I-U View Post
understand the exact difference between
Code:
chown -R owner:group * 
and 
chown -R owner:group .
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:
Code:
echo chown -R owner:group * 
echo chown -R owner:group .
echo chown -R owner:group .*

Last edited by neonsignal; 10-28-2010 at 05:21 PM.
 
2 members found this post helpful.
Old 10-29-2010, 04:34 AM   #10
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Original Poster
Rep: Reputation: Disabled
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:

http://www.linuxquestions.org/questi...ns-why-840925/


Last edited by JZL240I-U; 10-29-2010 at 04:40 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make the command line you type invisible sulekha Linux - Security 1 07-02-2010 07:52 AM
doubt in cp command for copying recursively directories and files mq15 Linux - Newbie 3 04-19-2010 10:47 AM
copying directories recursively with find command nanda22 Linux - Newbie 1 09-01-2008 07:39 AM
How do you Load files recursively from the command-line for console programs flupwatson Linux - General 4 08-25-2008 07:27 AM
Recursively browse graphics on CD from command line ewto Linux - Software 1 03-11-2005 10:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration