Skip to main content
clarify subject
Link
Stéphane Chazelas
  • 587.8k
  • 96
  • 1.1k
  • 1.7k

Using xargs for Running more commandsthan one command with xargs

English contractions use apostrophes.
Source Link
Jeff Schaller
  • 68.9k
  • 35
  • 122
  • 268

Is it possible to use find + xargs in order to invoke more than one command? I am trying to find all files whose size is greater than 100 chars. and less than 1000 chars , change their permissions and print list of files into file. I can do it with exec e.g

find . -maxdepth 1 -size +100c -size -1000c -exec chmod a+r {} \; -print > testfile 

But is there any way how to achieve this with xargs?

 find . -maxdepth 1 -size +100c -size -1000c -print0 | xargs -0 -I '{}' chmod a+r '{}' -print >testfile 

the last print wontwon't execute or throws error , is. Is there a way how to achieve it with xargs?

Is it possible to use find + xargs in order to invoke more than one command? I am trying to find all files whose size is greater than 100 chars. and less than 1000 chars , change their permissions and print list of files into file. I can do it with exec e.g

find . -maxdepth 1 -size +100c -size -1000c -exec chmod a+r {} \; -print > testfile 

But is there any way how to achieve this with xargs?

 find . -maxdepth 1 -size +100c -size -1000c -print0 | xargs -0 -I '{}' chmod a+r '{}' -print >testfile 

the last print wont execute or throws error , is there a way how to achieve it with xargs?

Is it possible to use find + xargs in order to invoke more than one command? I am trying to find all files whose size is greater than 100 chars. and less than 1000 chars , change their permissions and print list of files into file. I can do it with exec e.g

find . -maxdepth 1 -size +100c -size -1000c -exec chmod a+r {} \; -print > testfile 

But is there any way how to achieve this with xargs?

 find . -maxdepth 1 -size +100c -size -1000c -print0 | xargs -0 -I '{}' chmod a+r '{}' -print >testfile 

the last print won't execute or throws error. Is there a way to achieve it with xargs?

edited tags
Link
trolkura
  • 417
  • 1
  • 6
  • 15
Source Link
trolkura
  • 417
  • 1
  • 6
  • 15
Loading