nix, shell, perl, php, mysql and mac os x tips and tricks

Tuesday, March 22, 2016

recursively search and replace ambersands (or any character) in filenames

Replaces the ampersands with underscores in any file ending in .jpg (all subdirs)
find . -type f -iname "*.jpg" -exec rename 's/&/_/' {} \;
Same thing, but on systems that don't have 'rename' (like OS X)
find . -name '*.jpg' -type f -exec bash -c 'mv "$1" "${1/\/\&/_/}"' -- {} \;

Friday, March 11, 2016

wget a site for caching purposes (spider it)

Sometimes you want to crawl a site so that it gets cached on its server. This will "spider" a site and not download content
wget -r -l6 --spider -D