Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
walterhiggins / sample.json
Last active August 4, 2023 10:39
sample json
{
title: "This is the title",
person: {
name: "Walter",
gender: "Male"
}
items: [
{id: 5, name: "Jupiter"},
{id: 7, name: "Saturn"},
{id: 9, name: "Mars"}
var sounds = require('sounds');
function howl(event){
sounds.wolfHowl(event.block);
}
events.blockDestroy(howl);

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:

(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