Operating System - HP-UX
1751704 Members
5756 Online
108781 Solutions
New Discussion юеВ

Need help with a find command

 
SOLVED
Go to solution
wvsa
Regular Advisor

Need help with a find command

Good evening all;

Looking for some help regarding a find command. I need to go through all the /home directoris and change all files used during the user login process, eg. .profile, .sh_history, etc that have permissions of 644 and change them to 600. Need the find command to skip directories, don't want to change the permissions on the .ssh directory for example.

Thank you in advance for your input


Norm

9 REPLIES 9
kemo
Trusted Contributor
Solution

Re: Need help with a find command

find /home -type f -name ".*" -perm 644 -exec chmod 600 {} +
Hakki Aydin Ucar
Honored Contributor

Re: Need help with a find command

I think , it must be;

find /home -type f -name ".*" -perm 644 -exec chmod 600 {} \;
Dennis Handly
Acclaimed Contributor

Re: Need help with a find command

>Hakki: I think, it must be;

Nothing wrong with the Posix standard: -exec ... {} +
Especially if you want performance.

Note: -name ".*" changes all dot files, not just "files used during the user login process". Even in subdirectories.
James R. Ferguson
Acclaimed Contributor

Re: Need help with a find command

Hi:

To add to Dennis's comments, have a look at the 'find(1)' manpages under the '-exec' option. The differences between the ';' and the '+' terminator (including performance) are nicely discussed with examples there:

http://bizsupport.austin.hp.com/bc/docs/support/SupportManual/c02258880/c02258880.pdf

As usual, the manpages are your friend :-)

Regards!

...JRF...
wvsa
Regular Advisor

Re: Need help with a find command

Dennis;

You have identified the source of my problem, you can't use ".*" as this will indeed change the .. perms, not good.

So how can I get around this, is it possible with the find command?

Thank you for your input.

Norm
Patrick Wallek
Honored Contributor

Re: Need help with a find command

>>You have identified the source of my
>>problem, you can't use ".*" as this will
>>indeed change the .. perms, not good.

This should only happen if you do NOT specify the item type you are looking for.

If you use the example above where '-type f' is specified then you should only get regular files and not directories.

Steven Schweda
Honored Contributor

Re: Need help with a find command

> [...] you can't use ".*" as this will
> indeed change the .. perms, not good.

Really? Did you try it? And "-type f"
didn't help?

As usual, showing actual commands with their
actual output can be more helpful than vague
descriptions or interpretations (or
speculations).


man find

Look for "!". It should work with something
like
-name ..
too. If you really needed to do that.
wvsa
Regular Advisor

Re: Need help with a find command

All;

Thank you for all your responses, as it turns out I was making it more difficult than it should be.

Thread closed.
Dennis Handly
Acclaimed Contributor

Re: Need help with a find command

>Steven: Did you try it? And "-type f" didn't help?

Right. You don't need -type f because find(1) automatically skips . and .. because it wouldn't make progress if it looked at them.
You do have to worry when using ls(1) though.