Commands for Terminal

https://www.notion.so/Commands-for-Terminal-9f9f65c1bde74874a7e5582c101ca9e1

Useful Aliases

Add following aliases in your ~/.bash_profile

1
2
3
4
5
6
7
alias ..='cd ..'
alias ...='cd ../../'
alias b='brew'
alias c='clear'
alias l='ls -lah'
alias su='sudo -i'
alias root='sudo -i'

How to parse JSON string in the terminal

Install jq via following link to parse the string.

bookmark

1
curl 'https://api.github.com/repos/jqlang/jq/commits?per_page=5' | jq '.[0]'

How to find the largest files or folders on a file system

To find the largest folders on a file system pass the -a option. This will change the behavior of du to write size counts for files as well as folders. Run the following as root to see the ten largest files or folders on a system. This can be useful if you are dealing with out-of-disk space issues on a system.

1
2
3
4
5
6
du -a / | sort -n -r | head -n 10
5351116 /
2462616 /usr
2153492 /home
2153472 /home/george
1571924 /usr/lib

How to sort by file or folder size

To sort by file size pass the output of du to sort and use the -n (numeric) and -r (reverse) options.

1
2
3
4
5
du ~/go | sort -n -r | less
170440  /home/george/go
132816  /home/george/go/src
74024   /home/george/go/src/github.com
57072   /home/george/go/src/golang.org
This post is licensed under CC BY 4.0 by the author.