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.

The robust way to read lines in a loop

while IFS= read -r line || [[ $line ]]; do ...; done < /path/to/input

September 28, 2023bashoneliners

Generate a sequence of numbers using Brace Expansion

for i in {1..10}; do echo "$i"; done

October 25, 2019diego

Generate a sequence of numbers using a simple for loop

for ((i=1; i<=10; ++i)); do echo $i; done

November 4, 2014bashoneliners

Run command multiple times with a for loop and a sequence expression

for i in {1..10}; do date; sleep 1; done

August 19, 2012bashoneliners

Unpack all of the .tar.bz2 files in current directory

for FILE in *; do tar -jxf $FILE; done

October 17, 2011versorge