Josh Unwin

joshua unwin

FRONT END DEVELOPER

  • Tree

    Climate activist

  • Clapperboard

    Background in film workflow

React | JS | Rails | Python
my blog & more
Back

Bash One Liners

Josh Unwin

Joshua Unwin •

Edit


Find & Execute

find /path/to/source -iname "*.jpg" -not -name ".*" -exec cp -nv {} /path/to/destination \;


Duplicate all directories of the same name

find $1 -type d -name ORIGINAL -exec bash -c 'cp -av $1 $(dirname $1)/RENAME' _ {} \;

This looks for all directories named ORIGINAL, then clones them into the same directory they exist in, naming the copy RENAME.



Copy all DOCUMENTATION folders to new location using SHOOTDAY folder name

find SOURCE_DIR -type d -iname '*DOCUMENTATION*' -exec bash -c 'SD=$(echo $1 | grep -Eoi "\d\w*_SHOOTDAY_\w*\d"); cp -R $1 DESTINATION/$SD' _ {} \;```

This looks for all directories with DOCUMENTATION in the name, tries to extract the shootday name from the path and then clones to a specified destination, using the shootday as the name.

Stop, remove and recreate a docker postgres image

docker ps -a | awk '$2 == "postgres" { print $1 }' | xargs docker stop | xargs docker rm && make docker-build-local

Grabs the container_id for a docker postgres container, stops it, removes it, and then runs the make command to rebuild.