Skip to content

Instantly share code, notes, and snippets.

@dzungtran
Last active December 14, 2017 11:18
Show Gist options
  • Save dzungtran/ed05134f89f52c6d1e4a39b006466756 to your computer and use it in GitHub Desktop.
Save dzungtran/ed05134f89f52c6d1e4a39b006466756 to your computer and use it in GitHub Desktop.
[Updating] Awesome bash commands will help to save time for your life
# USER GUIDE:
# Do not run this script directly
# Compress multiple folders, each into its own zip archive
# BEGIN
for i in */; do zip -r "${i%/}.zip" "$i"; done
# OR
for i in *
do
[ -d "$i" ] && zip -r "$i.zip" "$i"
done
# END
# Find all file in current folder matched with pattern and remove them.
# BEGIN
find . -name "FILE-TO-FIND" -exec rm -rf {} \;
# OR
find . -type f -name "FILE-TO-FIND" -exec rm -f {} \;
# EXPLAIN:
# -name "FILE-TO-FIND" : File pattern.
# -exec rm -rf {} \; : Delete all files matched by file pattern.
# -type f : Only match files and do not include directory names.
# END
# Find all file extension
# BEGIN
find . -type f -name '*.*' | sed 's|.*\.||' | sort -u
# END
# Delete all empty folder
# BEGIN
find . -type d -empty -delete
# END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment