Skip to content

Instantly share code, notes, and snippets.

View Do something with all files in a

I've been using xargs for years without truly understanding what it did. I assumed it repeated the same command on each file but instead it runs the command passing all the files as arguments.

To run a command on multiple files - 1 file at a time - do this:

for file in $DIRECTORY/*; do ${YOUR_COMMAND_HERE} ${file}; done

For example: to revert local changes in a git-managed directory:

View stones.js
(function(exports) {
var bands = [
name: "The Beatles",
members: [
name: "George Harrison",
instrument: "Lead Guitar",
bio: "Blah blah blah",
songs: ["While my guitar gently weeps", "Here comes the sun"]
  1. Sean Higgins
  2. Adam Ahern
  3. Brendan Sheehan
  4. Caleb Bourke
  5. Rian McCormack
  6. Jack Murphy
  7. Cian Murphy
  8. Ian Elliot
  9. Sam Metcalfe
  10. Conor Lee
  1. Warmup
    • Jumping Jacks x 10
    • Seals x 10 (clap in front)
    • High Knees
    • Lunges
    • Side-shuffle
    • Soldier Kicks
    • Sprints
  2. Clear the goal game 2 teams, aim is for each team to score as many goals as possible in 2 minutes.