Bash

Posts tagged with #bash
Total: 12

Colorize pattern on CLI

Notes | 2025-05-07 (updated 2025-10-25) | 1 min read
#bash #grep #productivity

Colorize a pattern in the given input using a neat regex and colorization hack in grep ($ matching all lines but not being able to be highlighted).

color () {
  # Color highlight the pattern in the incoming stream, writing to stdout
  # This effectively matches our PATTERN andy any "$" (line end)
  # But only our PATTERN can be highlighted, line end characters aren't actually there to be highlighted
  local PATTERN=$1

  if [ -z "$1" ]; then
    echo "Usage: color <pattern>"
    echo "Description: Greps input with --color=always -E 'PATTERN|\$' "
    echo "Example: echo \"hello world\" | color \"world\""
    return 1

  fi
  grep --color=always "$PATTERN\|\$"
}

Troubleshooting Intermittent DNS Resolution Issues

Notes | 2025-02-28 (updated 2025-10-25) | 1 min read
#bash #dns #troubleshooting

DNS is something so fundamental to most of our systems functioning that it’s often overlooked in initial troubleshooting, it’s also incredibly hard to troubleshoot if it’s only intermittently failing.

Read more…

Running Multiple Server Processes From One Script

Notes | 2025-02-23 (updated 2025-10-25) | 1 min read
#bash #microservices #scripting

Doing local development on a bunch of interconnected services I often want to start multiple long running server processes.

This is the basic script I use for that.

Read more…

Cleanup After Script Exit

Notes | 2024-09-03 (updated 2025-10-25) | 1 min read
#bash #linux #scripting

Many of my scripts work with temporary files, usually relative to the scripts directory1, while at the same time using set -e to exit as soon as something fails.

In this scenario the script leaves behind these temporary files by default, which is not desirable.

We can however do a proper cleanup using the trap concept.

Read more…

Find files and folders with spaces

Notes | 2024-06-27 (updated 2025-10-25) | 1 min read
#bash #find #powershell

On Linux/Unix/MacOS:

find . | grep " "

On Windows:

Get-ChildItem -Path "." -Recurse -Filter "* *" | Format-Table FullName

Bash: Find All Folders Containing File With Name

Notes | 2024-03-01 (updated 2025-10-25) | 1 min read
#bash #scripting

fileName="my-file.yaml"
find . -type f -name "$fileName" -printf "%h\n"

Working With Dates in Bash and Other Shells

Notes | 2024-02-22 (updated 2025-10-25) | 1 min read
#bash #linux #scripting

Often times we need the current date (and time) when scripting inside bash or other shells. For example when creating a backup file or writing to a log.

Read more…

Navigate to Script Directory

Notes | 2024-01-28 (updated 2025-10-25) | 1 min read
#bash #linux #scripting

Often times when writing scripts I want to reference files in the same directory, but keep the script portable in case it is part of a git repository being checked out somewhere else or just the folder getting moved.

Read more…

Copy & Paste Is Dangerous

Posts | 2023-10-07 (updated 2025-10-22) | 2 min read
#bash #security #writeup

Copy & paste from untrusted sources on the internet into the terminal is a really bad idea! Early in my career I did it too and still often see others doing it.

Read more…

DigitalOcean CLI Cheat Sheet

Notes | 2023-04-15 (updated 2025-10-25) | 1 min read
#bash #digitalocean #doctl #infrastructure #productivity

Read more…