Skip to content

Instantly share code, notes, and snippets.

@vvzen
Last active October 11, 2020 11:41
Show Gist options
  • Save vvzen/b1927e3de82a5cd6068143d25815a1d1 to your computer and use it in GitHub Desktop.
Save vvzen/b1927e3de82a5cd6068143d25815a1d1 to your computer and use it in GitHub Desktop.
CLI oneliners accumulated during my life, tested on macOS
# This stuff was tested on zsh. It should work on bash but won't work on tcsh for sure!
# Dumb way to sort du output by size and only list up to the 50 top dirs that we can access
# |& is used to pipe stderr to the next command
#
du -k |& grep -v "Permission denied" | sort -nr | cut -f2 | head -n 50 | xargs du -sh |& grep -v "Permission denied" |& grep -v "No such" |& grep -v "Operation not"
# Compute the percentage of something
# 710 here is final expected number of files, we use `ls | wc -l` to get the current num of files
# then we pipe it into bc to do the math, then print to the console and save to file at the same time using tee
# scale=4 sets the float precision of bc
# In alternative, dc could be used instead of bc
echo "scale=4;`ls | wc -l | sed 's/ //g'` / 710 * 100" | bc | tee progress.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment