devnull.land

Miscellaneous bits and bobs from the tech world

Using `xargs` to `cd` into places and do things

9/23/2022, 11:13:13 AM


You can't cd in xargs because xargs is not a shell... or something. You have to invoke bash.

ls -1 directory | xargs -n1 -I{} bash -c 'cd {}; echo foobar'

Use -t if you want to see the resulting command executed.