Skip to content

Bash Command Line

Run script in background without parent process

This &> /dev/null & disown %- makes the parent process/script not wait for it to finish.

my-script.sh "$@" &> /dev/null & disown %-

Rename all files sequentially

count=0 ; for i in *.jpg; do count="$(($count +1))"; mv "$i" $(printf "spelkamer_%02d.jpg" $count); done

Resize JPG files

Use an exclamation mark as -resize 800x600! to make it scale to 800x600 pixels and not use its original ratio.

for i in *.jpg; do convert -resize 800x533 "$i" -quality 80% "small/${i}" ; done

Prevent Variable expansion/substitution in HEREDOC

sudo /bin/su -c "cat << 'EOF' > /etc/init.d/my-script

EOF