Using chown command.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using chown command.
# 1  
Old 12-06-2017
Using chown command.

I am working on a test machine.
I just discovered that I have misunderstood the way the following command is run.
Code:
chown -Rv some_user:users /some_folder/*

This command do exactly what I want. Change the owner of every things from the named folder and in all child folders.
But of course it leave untouched all hidden object like '.some_dir' and '.some_file'
So I run the following command ( and problem arise )
Code:
chown -Rv some_user:users /some_folder/.*

I can see on the screen that the command is climbing up one directory level doing something like
Code:
..........
..........
..........
chown /some_folder/../some_other_folder/.......
..........
..........
..........

What is the correct command to change every things without climbing up one level.
# 2  
Old 12-06-2017
Do you have access rights to the hidden files that you are trying to change the owner of?

Often hidden files are configuration/shell/user files created by the system manager and the user cannot change them.

If you are the system manager then try using your root account to change the owner.

Last edited by hicksd8; 12-07-2017 at 12:28 PM..
# 3  
Old 12-06-2017
Code:
chown -Rv some_user:users /some_folder

should change the owner of the folder /some_folder and all its files and sub-directories.

If you don't want to change the ownership of /some_folder the following will work for all hidden files with the second character being lower-case letters:
Code:
chown -Rv some_user:users /some_folder/.[a-z]*

so it will pick up files such as .bashrc but not .SciTEUser.properties.

Obviously you can extend the pattern to allow upper-case and numerals if necessary.

Andrew
# 4  
Old 12-06-2017
You could also set the dotglob control setting to have the shell include filenames starting with a . in the results of pathname expansion:

Code:
$ shopt -s dotglob
$ ls -d *
.bash_profile    .bashrc    .exrc    bin
$ shopt -u dotglob
$ ls -d *
bin

# 5  
Old 12-07-2017
Attention: the SysV chown changes the target of symbolic links; normally you want to change the owner of the symbolic links so you need the -h option
(old Linux chown was different, like BSD chown).
In a shell glob the [!.] is any character but a dot. (A few shells have [^.] in addition, that is not portable).
Code:
chown -hRv some_user:users /some_folder/* /some_folder/.[!.]*

Perhaps you can include the parent directory? Then it becomes simple:
Code:
chown -hRv some_user:users /some_folder

# 6  
Old 12-07-2017
Quote:
Originally Posted by jcdole
But of course it leave untouched all hidden object like '.some_dir' and '.some_file'
chown does not ignore hidden files. Only ls does that, as a user convenience.

Those files must have been preserved for some other reason, probably different ownership than you expected, and that won't change until you fix that.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 12-07-2017
@Corona688.....Thanks for the concise explanation. I tried to say that in post#2 without success.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

chown of a Directory

Hi All, I need your help in changing the owner of a directory. I have a created a direcotry TEST with user "abc"....for the group "ftp". Now i wnated to change the owner of the directory TEST. i used the below command to do so: chown abc:sftp TEST This is giving me an error... (5 Replies)
Discussion started by: ch33ry
5 Replies

2. Solaris

chown

Hello My oracledatabase creats some xmlfiles. this files has the owner hugo. now I've a script (how runs als hugo2) and this script will insert this XMLFile into the database. But that doesn't work, because the owner of the files is wrong, and hugo has not the rights to insert this files into... (3 Replies)
Discussion started by: Street
3 Replies

3. AIX

Trouble in chown

I'm a owner of directories or files why I can't deliver the ownership of them up to other users? (1 Reply)
Discussion started by: kang
1 Replies

4. Web Development

ftp: missing chown command

hi, I'm connecting to a web server with ftp protocol and I would like to change some folders and files owner. I tried chown but it is not available. I typed "help" and this is the list I got. Is possible that the chown command is not installed on the server ? Or I don't have permissions ?... (8 Replies)
Discussion started by: aneuryzma
8 Replies

5. Shell Programming and Scripting

cp, chown, untar

hello i want shell script. i have a source.txt /home/user409/public_html/test/ /home/user09876/public_html/xdsss/ /home/user9765/public_html/320xxx/ . . . maybe 1000 lines i want . 1.read a source.txt 2.untar special.tar.gz into these directory in source.txt 3.i want to... (14 Replies)
Discussion started by: topic32428285
14 Replies

6. UNIX for Dummies Questions & Answers

chown

is there a difference in chown on a file or a directory? how do i chown a directory and all the contents? (2 Replies)
Discussion started by: BG_JrAdmin
2 Replies

7. UNIX for Dummies Questions & Answers

reg chown

hi i wrote a script to run 'C' executable which will create a new file, after that util is completed, i have to change the file ownership to some other user. for that i used "chown" for changing the file permission in Korn script :confused:but it is throwing error is "operation... (2 Replies)
Discussion started by: ilayans
2 Replies

8. UNIX for Advanced & Expert Users

chown issue

I have a strange problem in my Linux box (Suse). Recently I took over this box as admin even though I have no prior admin experience. Following is my issue I had following users under 'root' group initially user1 user2 user3 Since I did not like user ids under root group. I modifed these... (9 Replies)
Discussion started by: praveenkumar_l
9 Replies

9. AIX

chown

hello chown not change ownership before: 205:system ~kuku chown kuku:system ~kuku after no change 205:system ~kuku aix box can someone help me? ariec (2 Replies)
Discussion started by: ariec
2 Replies

10. UNIX for Dummies Questions & Answers

chown and permissions

how i could give to user permission(delete,execute and so on) and ownership to files? Thanks (1 Reply)
Discussion started by: ithost
1 Replies
Login or Register to Ask a Question