Tech Tips Hub

Essential regex and Linux commands tailored for ICS developers using structured text and Linux environments with a cybersecurity twist

Useful Regex Commands

Explore a curated list of regex commands tailored for efficient coding and text manipulation tasks.

black cordless headphones beside closed black laptop computer and smartphoneblack cordless headphones beside closed black laptop computer and smartphone
Linux Command Guide

Discover essential Linux commands to help with disk imaging and compression

tilt-shift photography of green computer motherboardtilt-shift photography of green computer motherboard

Linux Commands Cheat Sheet

Some useful Linux commands when working with disk imaging and compression

Linux Commands for Disk Imaging & Compression

Disk Management & Partitioning

1. Erase Everything on a Disk

(Ensure to check the correct device with lsblk first!)

sudo dd if=/dev/zero of=/dev/sdb bs=1M count=2042 status=progress

sync # Ensures data is fully written before continuing

Use shred for a more secure wipe:

sudo shred -v -n 3 /dev/sdb

2. Create a Partition Table (MBR or GPT)

sudo parted /dev/sdb mklabel msdos # Use "gpt" instead for GPT

3. Create a Partition Taking Up the Entire Disk

sudo parted /dev/sdb mkpart primary 1MiB 100%

4. Format the Partition to ext4

sudo mkfs.ext4 /dev/sdb1

5. Label the ext4 File System

sudo e2label /dev/sdb1 "64_GB_USB"

Creating & Managing Disk Images

6. Create an Image of a Specific Partition

sudo dd if=/dev/sdb1 of=/home/data/tools.img bs=1M status=progress

7. Create an Image of a Partition with a Specific Size

sudo dd if=/dev/sdb1 of=/home/data/tools.img bs=1M count=1946 status=progress

8. Create an Image from a Specific Directory

tar -cvpzf /home/data/tools.tar.gz /path/to/tools_directory

9. Restore an Image onto a Partition

sudo dd if=/home/data/tools.img of=/dev/sdb1 bs=1M status=progress

10. Mount an Image File as a Loopback Device

sudo mount -o loop /home/data/tools.img /mnt

Unmount with:

sudo umount /mnt

Burning & Deploying Images

11. Burn the tools.img File onto an SD Card or USB Drive

sudo dd if=/home/data/tools.img of=/dev/sdb bs=4M status=progress

sync # Ensures the data is fully written

12. Verify the Image Write was Successful

sha256sum /home/data/tools.img

sha256sum /dev/sdb # Compare checksums

Working with Tar Compression

13. Compress an Entire Directory

tar -zcvf tools.tar.gz /path/to/tools_directory

14. Compress a Single File

tar -zcvf tools.tar.gz /path/to/filename

15. Compress Multiple Directories

tar -zcvf tools.tar.gz dir1 dir2 dir3

16. Extract a tar.gz File

tar -zxvf tools.tar.gz -C /destination/path/

17. Create a .tar.gz File While Excluding Unnecessary Files

tar --exclude="*.log" --exclude="*.cache" -zcvf tools.tar.gz /path/to/tools_directory

Additional Useful Commands

18. Find Available Disks and Partitions

lsblk

sudo fdisk -l

19. Check if a Disk is Mounted Before Writing an Image

mount | grep /dev/sdb

20. Resize an ext4 Filesystem After Writing an Image

sudo resize2fs /dev/sdb1

With this guide, you can efficiently package your tools into an image, burn it onto a USB or SD card, and ensure the integrity of the process.

Regex Commands Cheat Sheet

Whitespace & Formatting

  1. Find empty spaces between characters or words
    \s+\B
    (Useful for removing unintended spaces between words or symbols.)

  2. Find empty spaces at the beginning of a word or sentence
    ^[ \t]+
    (Helpful to trim leading spaces or tabs at the start of a line.)

  3. Find empty spaces at the end of a word or sentence
    [ \t]+$
    (Helpful to trim trailing spaces or tabs at the end of a line.)

  4. Find empty spaces (when you need to delete only spaces but not newlines/CR)
    [ ]
    (Ensures lines remain separate while removing spaces, if using for instance notepad++ for manipulating data.)

  5. Find tab spaces and remove them (e.g., fixing misformatted spacing in code)
    [\t]
    (Helpful to replace tabs with nothing or another desired character.)

Character & String Manipulation

  1. Find (select) all characters before a specific character (e.g., everything before = sign)
    ^[^=]*=
    (Useful for extracting keys in key-value pairs.)

  2. Find (select) all characters after a specific character (e.g., everything after :)
    \:(.*)
    (Useful to for example extracting values in key-value pairs.)

  3. Find || using escape characters (e.g., replacing with OR for CODESYS IEC code compatibility)
    \|\|
    (Matches || to replace it with OR or other alternatives.)

  4. Find all expressions in brackets (e.g., text (example) text → match (example))
    \([^)]+\)
    (Useful to extract or manipulate content within parentheses.)

Advanced Parsing & Data Processing

  1. Find all digits (numbers) in a document
    \d+
    (Selects all numeric values, useful for extracting or modifying numbers.)

  2. Find all non-digit characters
    \D+
    (Selects everything that is not a number, useful for isolating text.)

  3. Find all words that start with a specific letter (e.g., words starting with "a")
    \ba\w*
    (Matches words that begin with a given letter.)

  4. Find duplicate words next to each other (e.g., "the the")
    \b(\w+)\s+\1\b
    (Helps in correcting repeated words in a document.)

  5. Find email addresses in a document
    \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b
    (Useful for extracting email addresses from text.)

  6. Find all lines that contain only numbers
    ^\d+$
    (Selects lines where only numbers appear.)

  7. Find all lines that do not contain numbers
    ^(?!.*\d).*$
    (Matches lines that contain no numbers at all.)

  8. Find all words in uppercase
    \b[A-Z]+\b
    (Useful for identifying constants or specific terms in uppercase.)

  9. Find all words in lowercase
    \b[a-z]+\b
    (Finds all lowercase words in a document.)

  10. Find all capitalized words (words that start with an uppercase letter)
    \b[A-Z][a-z]*\b
    (Great for identifying proper nouns or sentence starts.)

  11. Find all special characters (non-alphanumeric characters)
    [^a-zA-Z0-9\s]
    (Useful for sanitizing text or extracting symbols.)

photo of optical disc drive
photo of optical disc drive

Tech tips hub