I think I am fairly advanced in my use of find but EVERY time I use it I cannot for the life of me remember the method to close the -exec option. I spend a good deal of time reading every time I use it. Am I simply not using it enough or expecting too much of myself? Lets start with a typical example that gets me frustrated.
Directory structure has files with all incorrect permissions hidden files symbolic links etc. I want to change the ownership to a reasonable value
find . -type f -exec chown username {} \;
find . -type d -exec chown username {} \;
find . -type d -exec chgrp usergroup {} \;
find . -type f -exec chgrp usergroup {} \;
(Forgive me if the ending is backwards... I looked at it an hour ago and still I am not sure)
But I am scared to run it because of mounts, symbolic links, etc. I have made the ultimate goof of chmod .* and had it recurse upwards on me before. I know -xdev will forgo crossing partitions but I am not sure what will happen to the files living inside directories which are symbolic links.
So how does one master this beast that can kill crucial files?
Update pruning the best suggestions below and summarizing:
- Have a practice directory linked and mounted to other practice directories.
- Use xargs rather than the non-intuitive exec command.
- Use -exec echo {} for sanity and safety
- Semi colon is special and you are escaping it therefore the escape char is first
- The -or command can help you combine selection criteria.
I am a little confused about the print0 but xargs has always been a bit on the not easy to understand at first glance practice that I try and avoid.