bashoneliners.com

Welcome to bashoneliners.com, a curated collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We aim to make each published one-liner to be of high quality: useful, easy to read, follows best practices, with clear, detailed, accurate explanation. These one-liners should help you automate tasks, troubleshoot problems, whether it be in system administration, file management, networking or programming.

Print the list of your Git commits this month

git log --since='last month' --author="$(git config user.name)" --oneline

February 25, 2019bashoneliners

Scan entire Git repo for dangerous Amazon Web Service IDs

git grep -Ew '[A-Z0-9]{20}'

September 5, 2018bashoneliners

Scan entire Git repos for dangerous Amazon Web Service IDs

git ls-tree --full-tree -r --name-only HEAD | xargs egrep -w '[A-Z0-9]{20}'

August 31, 2018johntellsall

Perform git commit with a random message from whatthecommit.com

git commit -m "$(w3m whatthecommit.com | head -n 1)"

January 5, 2018Jab2870

Test git archive before actually creating an archive // fake dry run

git archive master some/project/subdir | tar t

December 22, 2015openiduser146

Remove .DS_Store from the repository you happen to staging by mistake

find . -name .DS_Store -exec git rm --ignore-unmatch --cached {} +

February 22, 2014Kuwana

Count the lines of each file extension in a list of files

git ls-files | xargs wc -l | awk -F ' +|\\.|/' '{ sumlines[$NF] += $2 } END { for (ext in sumlines) print ext, sumlines[ext] }'

November 9, 2013bashoneliners

Export a git project to a directory

git archive master | tar x -C /path/to/dir/to/export

January 12, 2012bashoneliners