Xargs Command Snippets


Modified:   June 13, 2022
Published:   November 12, 2021

Tags:
Ref: https://web.archive.org/web/20211112045447/https://flaviocopes.com/linux-command-xargs/

Simple command snippet that most likely be used imo would be.

1
2
3
4
ls -f | xargs -I % -p echo "testxargs-%"
ls -f | xargs -I {} /bin/bash -c 'echo test1-{}; echo test2-{}'
ls -f | xargs -I % /bin/bash -c 'echo test1-%; echo test2-%'
ls -f | xargs -i -pt echo "testxargs-{}"
  • ls -f: List all files
  • -I allows you to get the output into a placeholder.
  • -p print a confirmation prompt with the action it’s going to take:
  • -t print command line on the stderr before executing it.


Let me know if you have any questions or comments.
It will help me to improve/learn.


< Older   Further Reading   Newer >