find command question
I have to find the ownership of the file recursively and if the ownership is "A", I need to change it to B.
Can we do it in one line? |
We can, you can't ;)
But seriously, man chown, with particular interest in the --from option |
Can we use the find command to search and do it? If you can, why can't you share /:)
|
Well.. jamescondron already shared the solution. Also you have to read the man page of find and see how can you execute a command on the files found... see the action -exec. The reason for which we cannot give the exact solution is that your question smells as homework and according to the LQ rules, we cannot help so much. For obvious reasons.
|
Hi,
This should work: find /start/directory -user A -exec chown B {} \; First try this: find /start/directory -user A and check the output. If correct rerun the command with the -exec chown B {} \; part attached. This must be run by a user that has sufficient rights to do the chown command (probably root). Hope this helps. EDIT Thanks to saivin for pointing out the mistake in the chown command (changed in the above text) /EDIT |
Edit: While I typing and reading, the more experienced folk have given the answer....
Quote:
You cannot do anything recursively to one file---perhaps you mean a group of files / directories. I think you want something like: find <path> -user <name of owner> -exec chown <newname> '{}' \; "man find" for the details...... |
Thank you for all the help. It is not a home work. What I'm trying to archive is if the owner is A, I need to check the group and if the group is C, I need to change it to D. Can I do it in one line?
Thanks in advance. |
Quote:
Code:
saivin@sv-debian:~$ sudo find ~/test -user saivin -exec chown {} root \; |
How about this? Is this ok?
find /directory -group group_name -a -user owner_name -exec chgrp newgroup {}\; |
Is this ok?
find /directory -group group_name -a -user owner_name -exec chgrp newgroup {}\; |
I'm all set. Thanks a lot for all of you.
|
You're all doing it wrong, there is no need for a find command, please see my suggestion, and the man page
|
Quote:
Remember: *nix has more then one way of doing things......... I agree that some of those solutions are elegant, some are resource unfriendly, some are unreadable and some just are. In the end a solution for the problem is needed and the work must be done. Your solution is just one of the solutions for this problem, maybe it is the most elegant or fastest of them all, but that does not make all the other solutions wrong.... |
No, the Unix philosophy always has and always will be 'Best Tool For The Job'. The Unix philosophy has never been about multiple ways to solve a problem.
You could even, as Raymond (I think) did, put it down to the KISS principle; Keep It Simple, Stupid. Code:
find /start/directory -user A -exec chown B {} \; Code:
chown --from=A: B * |
@jamescondron: In theory you are 100% correct.
|
All times are GMT -5. The time now is 12:37 AM. |