How to execute a command on each line of output from another command?

Hello :slight_smile:

new to bash not to programming.

I have an on-going need to change the owning group on sets of files and directories from the one they were created with or changed to on update to the one they need to have going forward.

find {target_root} -group wrong_group

gets me a newline delimited list of files that associate with the wrong group

chgrp correct_group {file}

makes the correct change to an arbitrary file

I need the way execute the latter command on each line of output from the former command?

Please help me out?

Try:

find {target_root} -group wrong_group -exec chgrp correct_group {} +

This command is more efficient, since it changes group ownership at once for as many pathnames as possible

1 Like

Wouldnt the easiest way be find 's -exec action?

1 Like

Yes perfect, thank you. What a useful option. Now to mark this solved...

Up at the top right of the thread there's an "Edit Tags" link. Click and enter "solved".