Handy Bash Commands

From time to time I google for bash commands that ease some of the repetitive tasks of a developer. I created this page as to bundle all the commands that I've used and find handy to keep in one place.

Rename whitespace by underscode (tested on Mac)

for f in *\ *; do mv "$f" "${f// /_}"; done

`

Lowercase all filenames in a directory

for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done

Create a tar.gz from files that have changed since a day

find . -mtime -1 -type f -exec tar -rvf assets.tar.gz {} \;

Find file in directory and all sub-directories AND remove extension

#!/bin/sh
shopt -s globstar
 
for file in ./data/**/*.jpg
do
    # remove extension
    echo ${file%.*}
done