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.

Scan all open local ports without any external programs

for i in {1..65535}; do (< "/dev/tcp/127.0.0.1/$i") &>/dev/null && { echo; echo "[+] Open Port at: $i"; }  || printf "."; done; echo

May 8, 2019Goeks1

Print wifi access points sorted by signal

iw dev IFACE scan | egrep "SSID|signal" | awk -F ":" '{print $2}' | sed 'N;s/\n/:/' | sort

June 16, 2018kazatca

Output an arbitrary number of open TCP or UDP ports in an arbitrary range

comm -23 <(seq "$FROM" "$TO") <(ss -tan | awk '{print $4}' | cut -d':' -f2 | grep "[0-9]\{1,5\}" | sort | uniq) | shuf | head -n "$HOWMANY"

February 9, 2018stefanobaghino

Blackhole ru zone

echo "address=/ru/0.0.0.0" | sudo tee /etc/NetworkManager/dnsmasq.d/dnsmasq-ru-blackhole.conf && sudo systemctl restart network-manager

November 14, 2017olshek_

Get the HTTP status code of a URL

curl -Lw '%{http_code}' -s -o /dev/null -I SOME_URL

June 19, 2017bashoneliners

Delete static and dynamic arp for /24 subnet

for i in {1..254}; do arp -d 192.168.0.$i; done

October 21, 2016dennyhalim.com

Extract your external IP address using dig

dig +short myip.opendns.com @resolver1.opendns.com

February 25, 2014bashoneliners

Get mac address from default interface OS X

netstat -rn | awk '/default/ { print $NF }' | head -1 | xargs -I {}  ifconfig {} | awk '/ether/ {print $2}'

August 21, 2013spotmac

Dump network traffic with tcpdump to file with time-stamp in its filename

date +"%Y-%m-%d_%H-%M-%Z" | xargs -I {} bash -c "sudo tcpdump -nq -s 0 -i eth0 -w ./dump-{}.pcap"

May 17, 2013kowalcj0

How to expand a CIDR notation to its IPs

for j in $(seq 0 255); do for i in $(seq 0 255) ; do seq -f "10.$j.$i.%g" 0 255; done; done

January 16, 2013EvaggelosBalaskas

How to set the ip address in Solaris 11

ipadm create-addr -T static -a 192.168.1.10/24 eth0/staticaddr

August 3, 2012bashoneliners

Add timestamp to the output of ping

ping some_host | while read LINE; do echo $(date): $LINE; done

October 10, 2011janos