How To Get BIOS Serial Numbers On Linux

The quickest way to get a BIOS serial number on Linux: sudo dmidecode -s system-serial-number That’s usually all you need. dmidecode reads the DMI/SMBIOS table and prints the serial number directly. Other options If dmidecode isn’t available or doesn’t return what you need: # lshw sudo lshw -C bios | grep serial # /sys class interface (no sudo needed) cat /sys/class/dmi/id/product_serial The /sys/class/dmi/id/ path is the cleanest option if you want to avoid sudo. It exposes several DMI fields: ...

25 November 2024 · Shafiq Alibhai

Shrinking PDFs with Ghostscript on the command line

I needed to shrink a PDF last week — something I don’t do often enough to remember the flags. Ghostscript is the tool, and it’s already on most Linux machines or a quick apt install ghostscript away. The command is: gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen \ -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf The bit that actually matters is -dPDFSETTINGS=/screen. That’s the quality dial. /screen gives you the smallest file — fine for emailing or uploading, rubbish if you need to print anything. ...

1 April 2024 · Shafiq Alibhai

Remove lines matching a pattern from files recursively in Linux

find . -name "*.md" -type f -exec sed -i '/pattern/d' {} \; This one-liner walks the directory tree, finds every .md file, and strips out any line that matches the given pattern. The sed -i edits each file in place, and the {} gets swapped out for whatever path find hands it. Breaking it down find . -name "*.md" -type f does the walking. The -type f bit is important – without it, find would also match directories and pass them to sed, which would error out. The -exec ... \; at the end runs the command for each file individually. ...

27 April 2023 · Shafiq Alibhai