Skip to content

Instantly share code, notes, and snippets.

@Psmths
Created February 7, 2021 03:52
Show Gist options
  • Save Psmths/6fab6e5de97360b0fffabeb25c899a45 to your computer and use it in GitHub Desktop.
Save Psmths/6fab6e5de97360b0fffabeb25c899a45 to your computer and use it in GitHub Desktop.
Bash one-liners

BASH One-Liners

Print unique file extensions in a directory (recursive)

find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

Count instances of multiple file extensions

#!/bin/bash
extensions=(flac mp3 wav ogg)

for i in "${extensions[@]}"
do
        count=$(find $1 -name "*.$i" | wc -l)

        if [ $count != "0" ]; then
                echo -e "$i:\t"$count
        fi
done

Get public-facing IPv4 address

NOTE: Uses 3rd party service.

curl ifconfig.me

Auto-Generate Google TTS mp3 File

Note: You need a GCP API key to use this. Argument 1 is the text to convert, argument 2 is the name of the mp3 file.

curl -H "Content-Type: application/json; charset=utf-8" \
  --data "{
    'input':{
      'text':'$1'
    },
    'voice':{
      'languageCode':'en-gb',
      'name':'en-GB-Wavenet-C',
      'ssmlGender':'FEMALE'
    },
    'audioConfig':{
      'audioEncoding':'MP3'
    }
  }" "https://texttospeech.googleapis.com/v1/text:synthesize?key=[your api key here]" | jq -r '.audioContent' | base64 -d > $2.mp3

Get Current NIST Beacon Random Value

curl -s https://beacon.nist.gov/beacon/2.0/pulse/time/$(date '+%s') | jq --raw-output '.pulse.localRandomValue'

Website Mirroring with Curl

wget \
     --recursive \
     --no-clobber \
     --page-requisites \
     --html-extension \
     --convert-links \
     --restrict-file-names=windows \
     --domains website.org \
     --no-parent \
         www.website.org/

SSH Remote File System Mounting

This command will allow you to mount a remote directory to your local device using only SSH. Note that if the server only accepts publickey authentication you will need to specify the absolute path to the desired identity as shown below.

sshfs -o allow_other,default_permissions,IdentityFile=/home/user/.ssh/id_ed25519,debug,uid=myuid,gid=mygid \
user@serveraddress:/server/remote/directory <local_directory>

Find Broken Website Links

This one line command utilizes wget to crawl a website. I have used this to monitor for broken links on my website with much success.

wget --spider -r -nd -nv -H -l 5 -w 1 -o output.log  https://example.com/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment