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.
grep -xFf file1 file2
text='3 blue; 5 green'; [[ $text =~ ([0-9]+)" "(blue|green) ]] && { echo "count = ${BASH_REMATCH[1]}"; echo "color = ${BASH_REMATCH[2]}"; }
awk -F'|' 'NR == FNR { $1 = ""; $2 = ""; seen[$0]++ } NR != FNR { orig = $0; $1 = ""; $2 = ""; if (!seen[$0]) print orig }' first.txt second.txt
f=/path/to/file; sed -e "s/pattern/replacement/" "$f" > "$f".bak && mv "$f".bak "$f"
head -c 100 /path/to/file
curl -s 'https://api.github.com/orgs/github/repos' | python -m json.tool
curl -s 'https://api.github.com/orgs/github/repos' | jq -r '.[] | [.id, .name, .stargazers_count] | @csv'
echo '{"foo": "bar \" baz"}' | jq -r .foo
while IFS= read -r line || [[ $line ]]; do ...; done < /path/to/input
w | tail -n +3 | cut -d ' ' -f1 | sort -u
IFS=, read -r first_name _ city _ <<< "John,Doe,New York,Times Square"
cut -d ':' -f 1,3 /etc/passwd | sort -t ':' -k2n - | tr ':' '\t'
echo "${PATH//:/\\n}"
awk '/^#[0-9]*$/ {split($0, arr, "#"); print "#", strftime("%c", arr[2]); getline; print }' < /path/to/.bash_history
echo "${PATH//:/\\n}" | awk '{print length, $0}' | sort -n | cut -f2- -d' '
history | awk '{print $2}' | sort | uniq -c | sort -nr | head
grep -ril '$SEARCH_PATTERN' src | sed -i 's/$FIND_PATTERN/$REPLACE_PATTERN/g'
for ITEM in $(cat values_to_search.txt); do (egrep $ITEM full_values_list.txt && echo $ITEM found) | grep "found" >> exit_FOUND.txt; done
cat post-list.csv | split -l 30 - --filter='jq -R . | jq --slurp -c .' | xargs -d "\n" -I % sh -c 'curl -H "Content-Type: application/json" -X POST -d '"'"'{"type":1,"entries":%}'"'"' http://127.0.0.1:8080/purge-something && sleep 30'
rename 's/[\r\n]//g' *
w3m https://www.archlinux.org/ | sed -n "/Latest News/,/Older News/p" | head -n -1
... | perl -MList::Util=shuffle -e 'print shuffle <>;'
behave -d | grep "scenarios passed" | cut -d, -f4 | sed -e 's/^[[:space:]]*//' | sed 's/untested/scenarios/g'
seq 5 | shuf