Bash One-liners: Linux, If, Else, For loop, Sed, Awk

Examples of useful bash one-liners


Bash One-linersUseful bash One-liners can improve your efficiency and make your work more enjoyable. Below is a collection of helpful bash one-liners.

Overview

Run a command against multiple targets in a single line

Find a directory that contains keyword

Find all files modified in the last week

Find your external IP with curl

Find your external IP with dig

Tcpdump with timestamp in file name

Delete dynamic and static arp for /24 subnet

Custom watch function (ctrl+z SIGINT to stop)

Add function to current session or to ~/.bashrc:

Use function:

Tail file until keyword

Log SSH session

Function to print columns (shortcut to … | awk ‘{print $4, $9}’)

Add function to current session or to ~/.bashrc:

Use function:

List open files (-n skips dns resolution)

Do not save command history of current session

Copy files with progress indicator

Check if file exists

Add remote host public key to known hosts