Show me your Bash Functions / Aliases!
Fred Richards

Fred Richards @flrichar

About: Open Source Technologist -- Cloud Architecture, IaC, Containers, Networking -- openness in technology & business transparency.

Location:
East Coast, US. NY.
Joined:
Jul 4, 2019

Show me your Bash Functions / Aliases!

Publish Date: Sep 21 '19
12 4

Do any of you have your favorite bash functions or aliases? I've always been a fan of quick "lightning tips" that you can show maybe on one line, and do something specific.

Here are some of mine!


## timestamp dmesg with the current date, this sudo doesnt require password
alias datemsg='date | sudo tee /dev/kmsg'

## how many ms since the epoch?
alias epocms='date +%s%3N'

## ksm is kernel same-page merging for virtual machines,
## this allows me to keep tabs on performance and metrics
alias ksm-info='~/opt/ksm-info.sh'

( ksm-info is just a one-liner ...
for ki in /sys/kernel/mm/ksm/* ; do echo -n "$ki: " ; cat $ki ; done
...)

## normal mutt is gmail, mm == local mail
alias mm='mutt -f ~/Mail/fredr'

## python pretends to be jq sometimes
alias pj='python -m json.tool'

## run a lot of ansible playbooks ... plans == play ansible
alias plans='ansible-playbook'

### .bashrc functions

## check on kernel entropy for ssh, vpn, encryption
entropy () { cat /proc/sys/kernel/random/entropy_avail; }

## pipe colorfied jq to less while keeping colors
jql () { jq -C . $1 | less -R ; }
Enter fullscreen mode Exit fullscreen mode

Many other minor stuff too, like loading environment vars for Go or BC.
So what are some of yours?

Comments 4 total

  • lbonanomi
    lbonanomiSep 23, 2019

    Alert my terminal if someone else has logged-into the same box that I am using.

    unset MAIL; export MAILCHECK=1; export MAILPATH='/var/log/wtmp?You have company'
    
  • lbonanomi
    lbonanomiSep 24, 2019

    Do you use Github gists as a notebook?

    gist ()
    {
        GISTTMP=$(mktemp -d) && GISTFILE=$(basename $1) && GISTPATH=$(readlink -f $1)
        GIST_URL=$((echo curl -snk -X POST -d \'{\"files\":{\"$GISTFILE\":{\"content\":\".\"}}}\' https://api.github.com/gists | sh ) | awk -F'"' '/git_pull_url/ { print $4 }' | head -1 )
        (
            cd $GISTTMP
            git clone -q $GIST_URL
            cd $(ls)
            cat $GISTPATH > $GISTFILE;
            git add $GISTFILE && git commit -q -a -m "$GISTFILE" && git push -q
        )
    }
    
    
    • lbonanomi
      lbonanomiSep 27, 2019

      I also work with throwaway-VMs, so you may do well rm -rf-ing $GISTTMP when you're done

Add comment