Skip to content

Instantly share code, notes, and snippets.

@teksrc
Last active August 28, 2019 02:54
Show Gist options
  • Select an option

  • Save teksrc/13738280064bced04262180a263aeea2 to your computer and use it in GitHub Desktop.

Select an option

Save teksrc/13738280064bced04262180a263aeea2 to your computer and use it in GitHub Desktop.

1.Commands

For Bash Snippets

Review article after installing

https://www.ostechnix.com/collection-useful-bash-scripts-heavy-commandline-users/

brew install bash-snippets

Peek inside files without actually opening them

cat file.jpg

See image in terminal

imgcat dog.gif

Basic copy the file contents to your clipboard

pbcopy < text.md

View what is using up your current port

lsof -i :80

Issue many commands instead typing them out individually one by one.

for ex npm i && npm start these are perfect for Aliases too if you are using them a lot

Open current directory in a Finder window:

open .

Run a wireless scan:

airport -s

Display a history of commands used in the terminal by the current user:

history

Scroll down, clearing the current view, but still persisting it above:

clear

Prevent Mac from sleeping for one hour (3,600 seconds):

caffeinate -u -t 3600

Open an application of any kind:

open itunes

Open a directory in a Finder window:

open /Users/mel/Documents

Compare and merge files and directores:

opendiff Contract1.rtf Contract2.rtf could be any two files similar

Show the time since last reboot and how busy the system is

uptime

Restart MacOS:

sudo shutdown -r now

Shutdown MacOS:

sudo shutdown now

Overview of current Power Management Settings:

pmset -g

Put display to sleep after 15 minutes of inactivity:

sudo pmset displaysleep 15

Put Computer to sleep after 30 minutes of inactivity:

sudo pmset sleep 30

Force Finder to show hidden files (to see . hidden files):

defaults write com.apple.finder AppleShowAllFiles TRUE

Force Finder to hide hidden files (ie: back to the default setting):

defaults write com.apple.finder AppleShowAllFiles FALSE

Count number of lines in the text in the Clipboard:

pbpaste | wc -l

Count number of words in the text in the Clipboard:

pbpaste | wc -w

Sort lines of text in the Clipboard and copy them back to the Clipboard:

pbpaste | sort | pbcopy

Reverse each line of text in the Clipboard (ie: make each line appear backwards) and copy them back to the Clipboard:

pbpaste | rev | pbcopy

Strip duplicate lines from lines of text in the Clipboard and copy only one instance of each duplicate line back to the Clipboard (output is sorted):

pbpaste | sort | uniq | pbcopy

Find duplicate lines from lines of text in the Clipboard and copy only one instance of each duplicate line (stripping non-duplicates) back to the Clipboard (output is sorted):

pbpaste | sort | uniq -d | pbcopy

Strip duplicate lines from lines of text in the Clipboard and copy only one instance of each line (stripping duplicates entirely) back to the Clipboard (output is sorted):

pbpaste | sort | uniq -u | pbcopy

Tidy up HTML in the Clipboard and copy it back to the Clipboard:

pbpaste | tidy | pbcopy

Display the first 5 lines from the Clipboard:

pbpaste | head -n 5

Display the last 5 lines from the Clipboard:

pbpaste | tail -n 5

Convert tabs to spaces for the lines in the Clipboard:

pbpaste | expand | pbcopy




2. Aliases

## Quick clear of terminal ##
alias c='clear'

## save time with history & jobs ##
alias h='history'
alias j='jobs -l'

## Colorize the ls output ##
alias ls='ls --color=auto'
 
## Use a long listing format ##
alias ll='ls -la'
 
## Show hidden files ##
alias l.='ls -d .* --color=auto'

## get rid of command not found ##
alias cd..='cd ..'
 
## a quick way to get out of current directory ##
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../..'

# Git alias
alias gcm="git checkout master"
alias gcr="git checkout release"
alias gnb=gnb
alias gfc=gfc
alias gcb="git checkout $1"
alias gma="git merge abort"
alias gmm="git merge master"
alias gpom="git push origin master" # dont judge me
alias gpro="git pull --rebase origin master"
alias gpru="git pull --rebase upstream master"
alias gra="git rebase --abort"
alias grc="git rebase --continue"

# Node/NPM alias
alias cra="create-react-app"
alias purge="rm -rf node_modules package-lock.json; npm i"
alias dev="npm run dev"
alias devs="npm run dev:s"

# System alias
alias bb='/bin/bash'

## Colorize the grep command output for ease of use (good for log files)##
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

## Start calculator with math support ##
alias bc='bc -l'

##Generate sha1 digest ##
alias sha1='openssl sha1'

## Create parent directories on demand ##
alias mkdir='mkdir -pv'

## install  colordiff package ##
alias diff='colordiff'

## Make mount command output pretty / readable ##
alias mount='mount |column -t'

## Create a new set of commands ##
alias path='echo -e ${PATH//:/\\n}'
alias now='date +"%T"'
alias nowtime=now
alias nowdate='date +"%d-%m-%Y"'

## Show open ports ##
alias ports='netstat -tulanp'

## Tune sudo and su ##
alias root='sudo -i'
alias su='sudo -i'

## Control web servers ##
alias nginxreload='sudo /usr/local/nginx/sbin/nginx -s reload'
alias nginxtest='sudo /usr/local/nginx/sbin/nginx -t'
alias lightyload='sudo /etc/init.d/lighttpd reload'
alias lightytest='sudo /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -t'
alias httpdreload='sudo /usr/sbin/apachectl -k graceful'
alias httpdtest='sudo /usr/sbin/apachectl -t && /usr/sbin/apachectl -t -D DUMP_VHOSTS'

## Get system memory, cpu usage, & gpu memory info quick ##

## pass options to free ##
alias meminfo='free -m -l -t'
 
## get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
 
## get top process eating cpu ##
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
 
## Get server cpu info ##
alias cpuinfo='lscpu'
 
## older system use /proc/cpuinfo ##
##alias cpuinfo='less /proc/cpuinfo' ##
 
## get GPU ram on desktop / laptop##
alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'

## Control Home Router ##

# Reboot a home "Linksy" Router / Gateway , use your own stuff.
alias rebootlinksys="curl -u 'admin:my-super-password' 'http://192.168.1.2/setup.cgi?todo=reboot'"
 

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