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.

Recursively remove all "node_modules" folders

find . -name node_modules -exec rm -rf {} +

March 29, 2020tg-z

Create a txt files with 10000 rows

for FILE in *.full ; do split -l 100000 $FILE; mv -f xaa `echo "$FILE" | cut -d'.' -f1`.txt; rm -f x*; done

August 22, 2018Kifli88

Remove all container from an specific network (docker)

docker ps -a -f network=$NETWORK --format='{{.ID}}' | xargs docker rm -f

August 17, 2018gatero

Have script run itself in a virtual terminal

tty >/dev/null || { urxvt -e /bin/sh -c "tty >/tmp/proc$$; while test x; do sleep 1; done" & while test ! -f /tmp/proc$$; do sleep .1; done; FN=$(cat /tmp/proc$$); rm /tmp/proc$$; exec >$FN 2>$FN <$FN; }

March 9, 2018openiduser111

Delete orphan vi and vim undo files

find . -type f -iname '*.un~' | while read UNDOFILE ; do FILE=$( echo "$UNDOFILE" | sed -r -e 's/.un~$//' -e 's&/\.([^/]*)&/\1&' ) ; [[ -e "$FILE" ]] || rm "$UNDOFILE" ; done

September 2, 2014rafaeln

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

Remove files and directories whose name is a timestamp older than a certain time

ls | grep '....-..-..-......' | xargs -I {} bash -c "[[ x{} < x$(date -d '3 days ago' +%Y-%m-%d-%H%M%S) ]] && rm -rfv {}"

May 7, 2013openiduser95

Remove all the versioned-but-empty directories from a Subversion checkout

find . -name .svn -type d | while read ss; do dir=$(dirname "$ss"); test $(ls -a "$dir" | wc -l) == 3 && echo "svn rm \"$dir\""; done

November 27, 2011bashoneliners

Delete unversioned files in a Subversion checkout directory and all subdirectories

svn st | grep ^? | sed -e 's/^? *//' | xargs -i{} echo rm -fr "{}"

October 3, 2011janos