Skip to content

Instantly share code, notes, and snippets.

@lucidyan
Last active November 14, 2019 23:45
Show Gist options
  • Save lucidyan/3200d62e13d3fb598fdb73c3f595eef6 to your computer and use it in GitHub Desktop.
Save lucidyan/3200d62e13d3fb598fdb73c3f595eef6 to your computer and use it in GitHub Desktop.

Grep files with selected extensions only

find ./ -type f \( -iname \*.md -o -iname \*.txt \) -exec grep -Hi 'word' {} +

Show files opened in Sublime

cat $HOME/.config/sublime-text-3/Local/Auto\ Save\ Session.sublime_session |grep "\"file\":" |sed 's/^[[:space:]]*//g' |sed 's/^\"file\"\: \"//g' |sort -u | sed 's/[\",]*//ig'"

Convert all *.wav to *.mp3

parallel-moreutils -i -j$(nproc) ffmpeg -i {} -b:a 320k {}.mp3 -- ./*.wav && rename .wav.mp3 .mp3 ./*.mp3

Find broken *.jpg (old)

find $1 -name '*.jpg' -print0 | while IFS= read -r -d '' FILE; do
    #if [[ $(identify -format '%f' "$FILE" 2>/dev/null) != $FILE ]]; then
    ERR=$(djpeg -fast -grayscale -onepass "$FILE" 2>&1 >/dev/null)
    if [ ! -z "$ERR" ]; then
        echo "$FILE | $ERR"
    fi
done

Find broken *.jpg (NEW)

find $1 \( -iname '*.jpeg' -o -iname '*.jpg'  \) -print | xargs -0 echo | while read FILE; do
    FILENAME="$(echo $FILE | rev | cut -d '/' -f 1 | rev)"
    if [[ $(identify -format '%f' "$FILE" 2>/dev/null) != $FILENAME ]]; then
        echo "$FILENAME"
	echo "$FILE"
	echo "$(identify -format '%f' "$FILE" 2>&1 > /dev/null)"
	echo ""
    fi
done

Bash snippets

https://github.com/lucidyan/bash-snippets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment