Operating System - HP-UX
1821245 Members
2724 Online
109632 Solutions
New Discussion юеВ

Re: Chown multiple dot files

 
SOLVED
Go to solution
Coolmar
Esteemed Contributor

Chown multiple dot files

Hi,

Is there a way to chown multiple dot files in a directory? Obviously, chown .* is not the way to go, but I am tired of chowing each and every dot file in a directory.

Thanks,
S
11 REPLIES 11
Ranjith_5
Honored Contributor

Re: Chown multiple dot files

Hi Sally,

can we have

# chown -R owner:group


Regards,
Syam
Alan Meyer_4
Respected Contributor
Solution

Re: Chown multiple dot files

find . -type f -name '.*' -prune -exec owner:group {} \;
" I may not be certified, but I am certifiable... "
Coolmar
Esteemed Contributor

Re: Chown multiple dot files

That does all the regular files but not the dot files (ie: .profile, .dt, .abc, etc)
Mel Burslan
Honored Contributor

Re: Chown multiple dot files

chown XXX .[a-z,A-Z,0-9]*

this will change the ownership of most every dot file in a given directory.

________________________________
UNIX because I majored in cryptology...
Alan Meyer_4
Respected Contributor

Re: Chown multiple dot files

oops

find . -type f -name '.*' -prune -exec chown owner:group {} \;
" I may not be certified, but I am certifiable... "
Andy Torres
Trusted Contributor

Re: Chown multiple dot files

They're usually the first files in a long listing ("ll"). If you know how many there are, try this:

ll | grep -v total | head -7 | awk '{print $9}'

The 7 would be the number of files in the directory that you want.

You can put that into a for-do loop or a maybe an xargs pipe.

Not so elegant, but I hope that helps.
Coolmar
Esteemed Contributor

Re: Chown multiple dot files

Thanks Alan
Alan Meyer_4
Respected Contributor

Re: Chown multiple dot files

NOTE:
It will also chown the . files in subdirectories downstream from the current directiory.
" I may not be certified, but I am certifiable... "
Mel Burslan
Honored Contributor

Re: Chown multiple dot files

one caveat for Alan's command:

as .. (i.e. the upper directory) is found as a result of the find command, it may try to change the ownership of the files in the directory above which may wreak havoc in certain cases.
________________________________
UNIX because I majored in cryptology...
Alan Meyer_4
Respected Contributor

Re: Chown multiple dot files

My tests of the included find command show that it does not go to the parent directory, but it does travel down the subdirectories below.
" I may not be certified, but I am certifiable... "
Bill Hassell
Honored Contributor

Re: Chown multiple dot files

Let regexp do the work for you (find is not necessary). You already know that .* will match . and .. (not good!) so just tell regexp to not include a match if the second character is a dot:

chown user1:group2 .[!.]*

As with any sweeping command using filename matching, always verify the results with a preview:

echo chown user1:group2 .[!.]*

Oops. This will not match . or .. but it does match directories and that might not be desired. In that case, use find to locate only files.


Bill Hassell, sysadmin