Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bash tricks
# set a loop for running commands, will run unit tests on enter
while read; do go test ./...; done
# set a loop that runs once a second (like watch), can be used in cases watch doesn't fit as well
while sleep 1; do ls; done
# do something with the previous command
ls $(!!) # equivalent to ls $(pwd)
# reverse sort by third column and display top entry (useful for things like ps aux)
| sort -k 3 -r | head -1
# sort by unique entries and display the count, also sorted
| sort | uniq -c | sort
# sort by human readable sizes, in this example with du with depth 1 (syntax may vary by OS) and show top 20 for current folder
du -d 1 -h . | sort -nr | head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment