Skip to content

Instantly share code, notes, and snippets.

@Faheetah
Created October 12, 2021 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Faheetah/d4d3a4f4fae82d79002bbc51b3b5ed90 to your computer and use it in GitHub Desktop.
Save Faheetah/d4d3a4f4fae82d79002bbc51b3b5ed90 to your computer and use it in GitHub Desktop.
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
pwd
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