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.

Do something in another directory without going there

(cd /path/to/somewhere; tar c .) > somewhere.tar

April 2, 2012bashoneliners

Recursively remove all empty sub-directories from a directory tree

find . -depth  -type d  -empty -exec rmdir {} \;

January 31, 2012openiduser16

Come back quickly to the current directory after doing some temporary work somewhere else

pushd /some/where/else; work; cd /somewhere; work; cd /another/place; popd

January 15, 2012bashoneliners

Recursively remove all empty sub-directories from a directory tree

find . -type d | tac | xargs rmdir 2>/dev/null

November 29, 2011bashoneliners

Remove spaces recursively from all subdirectories of a directory

find /path/to/dir -type d | tac | while read LINE; do target=$(dirname "$LINE")/$(basename "$LINE" | tr -d ' '); echo mv "$LINE" "$target"; done

September 20, 2011bashoneliners