{raw}
⤺ /text/useful

unixcommands.txt

rsync --archive --chown=sammy:sammy ~/.ssh /home/sammy

numfmt
e.g. numfmt --from=si --to=iec --format="%.1f" --round=down 64G

timeout 5s [command here]

Get child folders by size
du -hd 1 .
or du -h --max-depth 1 (on some systems)

.. and sort in reverse order of size
du -hd 1 . | sort -hr


on macOS, generate 100 random numbers between 1 and 100
jot -r 100 1 10

cal

curl .. --output filename.ext

nohup .. don't let cmd be hungup

alias netstat_tanp="lsof -Pnl +M -i4 -i6"
alias today='vim ~/notes/$(TS="Europe/London" date +%Y-%m-%d).txt'

# macOS only
alias shrug='echo -n "¯\_(ツ)_/¯" | pbcopy'

function gc() { grep -rnI "$@" * ;}
    function gcA() { grep -rnI -A 5 "$@" * ;}
    function gcB() { grep -rnI -B 5 "$@" * ;}
    function gcC() { grep -rnI -C 5 "$@" * ;}
    function gcf() { grep -rnIl "$@" * ;}


alias myip='curl -s https://api.ipify.org'
curl ipinfo.io

alias ix="curl -F 'f:1=<-' ix.io"
alias getmp3="youtube-dl -x --audio-format mp3 "

    function gen_passwd () {
        openssl rand 150 |\
        tr -dc  '[:graph:]' |\
        cut -c 1-${1:-13}
    }

tr -d iIlLOo0


# Show Disk Use of subdirectories, sort by size
    alias duss="sudo du -d 1 -h | sort -hr | egrep -v ^0"

ncdu - ncurses disk usage

# wrapper for easy extraction of compressed files
    function extract () {
      if [ -f $1 ] ; then
          case $1 in
              *.tar.xz)    tar xvJf $1    ;;
              *.tar.bz2)   tar xvjf $1    ;;
              *.tar.gz)    tar xvzf $1    ;;
              *.bz2)       bunzip2 $1     ;;
              *.rar)       unrar e $1     ;;
              *.gz)        gunzip $1      ;;
              *.tar)       tar xvf $1     ;;
              *.tbz2)      tar xvjf $1    ;;
              *.tgz)       tar xvzf $1    ;;
              *.apk)       unzip $1       ;;
              *.epub)      unzip $1       ;;
              *.xpi)       unzip $1       ;;
              *.zip)       unzip $1       ;;
              *.war)       unzip $1       ;;
              *.jar)       unzip $1       ;;
              *.Z)         uncompress $1  ;;
              *.7z)        7z x $1        ;;
              *)           echo "don't know how to extract '$1'..." ;;
          esac
      else
          echo "'$1' is not a valid file!"
      fi
    }


[command options arguments]
echo "abc"
clear
cd
pwd
ls
cd ~
cd ~/D [tab completion]
mkdir
touch
ls -l
wc
cat
less   .. arrows, spacebar, b, q
head
head -n 4
tail
echo "abc" > file.txt
echo "abc" >> file.txt
nano (ctrl+o, ctrl+x, ctrl+w)
mv
cp
rm
rm -r
man (/ to search, n for next, shift+n for prev)
apropos (searches unix commands)
whatis (searches commands for descriptions)
ls abc*
ls *.jpg
ls *01.*
mv 2017-* 2017/
grep "x" list.txt
egrep "i.g" list.txt
find . -name "states.txt"
find . -name "*.jpg"
history
head -n 5 ~/.bash_history
~/.bash_profile
alias docs='cd ~/Documents'
source ~/.bash_profile
diff a b
sdiff a b
md5
shasum
cat a | head -n 5
grep "" x | wc -l
ls -al | grep "x" | less
makefiles [see makefiles file]
#!/usr/bin/env bash
expr 5 + 5
expr 5 \* 2
bc
echo "22 / 7" | bc -l
a=5
echo $a
let a=$a+1
a="hi"
a=$(cat x | wc -l)
echo "blah $a"
$@ - arguments, $1, $2, $#
read a
$?
[[ 4 -gt 3 ]]
[[ 4 -gt 3 ]] && echo t || echo f
-ge, -eq, -ne, -le, -lt, -e (file exists), -d (dir exists), -z (length zero), -n (length non-zero)
[[ b =~ b ]] && echo t || echo f
[[ ! b =~ b ]]
[[ b != b ]]
  if [[ $1 -eq 4 ]]
  then
    echo "x"
  elif [[ $1 -gt 3 ]]
  then
    echo "y"
  else
    echo "z"
  fi
list=(a b c d)
echo ${list[0]}
echo ${list[*]}
${list[*]:2:2}
list+=(e f)
echo {0..9}

for i in {1..3}
do
  echo $i
done

for i in a b c
do
done

while [[ $count -gt 0 ]]
do
done

function hello {
  echo "Hello"
}

local sum=0

chmod u+x cmd
ls -l cmd

echo $HOME
export X=abc

git init
git status
git add
git rm --cached file
git commit -m "x"
git diff
.gitignore
git branch nameofbranch
git branch
git checkout branchname
git branch -d deletethisbranch
git checkout -b createandcheckout
git merge otherbranch
git push -u origin master
git clone
git remote -v
git push

ssh
scp
scp -r
curl -O
curl http://httpbin.org/get
ps -A
select-editor
crontab -e

tcp.rip