- zip folder using name of folder (replace
folder
)
zip -r folder{.zip,}
- recursive find and replace in files
# on mac
find . -type f -name '*.txt' -exec sed -i '' 's/oldword/newword/' {} +
# on ubuntu
find . -type f -name '*.txt' -exec sed -i 's/oldword/newword/' {} +
- edit cron tab
env EDITOR=nano crontab -e
- view current cron tabs
crontab -l
- recursive image resize (without upscale)
This technique works but affects colors, alternate approach using sips
below
find . -name '*.jpg' -exec mogrify -resize 2000^ {} +
# multiple filetypes
find . -type f \( -name "*.jpg" -or -name "*.png" \) -exec mogrify -resize 2000^ {} +
# single file (resize width)
sips --resampleWidth 500 file.jpg
# single file (resize longer size)
sips -Z 500 file.jpg
The issue is sips
will upscale an image if below the input size, which is usually not the desired behavior. We implement a conditional in order to check to see if an image is greater than the desired width first, before doing the resize.
#!/bin/bash
# ./resize-all.sh 500
# will resize all images (recursively), to specified width
find . -type f \( -name "*.jpg" -or -name "*.png" \) |\
while read FILENAME
do
size=($(sips -g pixelWidth -g pixelHeight "${FILENAME}" | grep -o '[0-9]*$'))
if [[ ${size[0]} -gt $1 ]]; then
sips --resampleWidth $1 "${FILENAME}"
fi
done