'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: ...

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. ...

How to count words in a PDF from the Linux command line

The simplest approach: pdftotext input.pdf - | wc -w pdftotext is in the poppler-utils package (sudo apt install poppler-utils or sudo yum install poppler-utils). The - sends output to stdout instead of a file. Other options pdfminer: pdf2txt.py input.pdf | wc -w Install with pip install pdfminer.six. Python with PyPDF2: import PyPDF2 with open("input.pdf", "rb") as f: reader = PyPDF2.PdfReader(f) total = sum(len(page.extract_text().split()) for page in reader.pages) print(total) Note: PyPDF2’s PdfFileReader and getPage() are deprecated in newer versions — use PdfReader and index into reader.pages instead. ...

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. ...

Installing PhantomJS on Ubuntu 22.10

PhantomJS is a headless browser, which means it runs without a graphical interface and lets you automate web page interactions through scripting. I needed it for some automated testing at work and ran into a few things worth writing down, mostly because half the guides out there are either outdated or assume you already know what you’re doing. The version we’re installing is 2.1.1, which is the last release. The project has been unmaintained since 2017, but it still does what it needs to do for basic scraping and screenshot tasks. ...

Deleting files by content match in Linux

There are two ways to interpret this question, and the answer changes completely depending on which one you mean. Deleting files by filename If you want to nuke every file whose name contains a particular string: find . -type f -name '*string*' -delete The -type f keeps it from touching directories. The -delete flag removes whatever find matches. Simple enough. A word of caution: test without -delete first. Run the same command and replace it with -print to see what would actually get deleted. I’ve lost files to typos in wildcard patterns more times than I care to admit. ...

Replace all dots in filenames except the extension on Linux

Had a directory full of files with dots in the names and needed them all cleaned up. Something like my.report.final.pdf should become my_report_final.pdf, not my_report_final..pdf or worse. This one-liner does the job: for f in *; do pre="${f%.*}"; suf="${f##*.}"; mv -i -- "$f" "${pre//./_}.${suf}"; done Here’s what each part does. ${f%.*} strips everything from the last dot onwards, giving you the filename without its extension. ${f##*.} grabs just the extension by stripping everything up to and including the final dot. Then ${pre//./_} replaces every dot in the base name with an underscore. ...

Count directories in the current folder with a one-liner

A common question that comes up when you’re first getting comfortable with the command line: how do you count just the directories in your current folder? The quick answer is: ls -1 | wc -l This pipes a one-per-line listing of everything in the current directory into wc -l, which counts lines. Simple enough. But there’s a catch. This counts everything – files, symlinks, hidden items, the lot. If you only want directories, you need to be a bit more selective. ...

Count files in a directory with a one-liner

Another quick command line question: how do you count just the files in a directory, excluding subdirectories and other stuff? The classic answer: ls -l . | egrep -c '^-' This lists everything in long format (ls -l), then counts lines that start with a hyphen – which is how ls marks regular files. Directories show up as d, symlinks as l, and so on, so the regex filters them out. It works, but it’s a bit of a trick and relies on understanding ls output format. A more straightforward approach uses find: ...

'Installing Multiple PHP Versions on Debian 9'

Sometimes you need more than one PHP version on the same server. Maybe an old project still runs on 5.6, another one needs 7.2, and you want to test something on 7.4 before committing. Debian’s default repositories only ship one version, so you need a third-party source. The Sury repository is the standard way to get multiple PHP versions on Debian. Ondrej Surý has maintained it for years and it’s trusted by most people running PHP on Debian. ...

How to run VLC player as root user

I ran into this a while back when I needed VLC running as root on a headless server, and the usual --no-sandbox flag didn’t cut it. VLC refuses to start as root by default, which makes sense from a security standpoint but is annoying when you actually need it. The fix is brutal and hacky, but it works: sed -i 's/geteuid/getppid/' /usr/bin/vlc What’s actually happening here? VLC’s startup script checks whether the effective user ID is zero (root). If it is, it bails out. By swapping geteuid with getppid, we’re telling the script to check the parent process ID instead of the effective UID. Since getppid() returns a number way bigger than zero, the check passes and VLC starts. ...

'How much memory is actually free?'

I keep forgetting this one, so here it is. vmstat -s -SM | grep "free memory" | awk -F" " '{print$1}' It pipes vmstat output through grep and awk to pull just the number – no units, no labels, just the gigabytes sitting there doing nothing.

OpenSUSE installer boot menu

'OpenSUSE 11.4 -- first look'

I grabbed the openSUSE 11.4 64-bit ISO last night and spent the afternoon installing it in a VM. Here’s the full walkthrough, screenshots and all. Boot menu. Standard options – Installation, Rescue System, media check. Nothing fancy, but it gets the job done. Welcome screen. The green chameleon is back, and so is the striped wallpaper that’s become the distro’s signature look. ...

Preserving File Permissions When Copying in Linux

Use the -p flag with cp to preserve file permissions: cp -p /aaa/bbb /ccc/ddd

GNUSL3S LINUX OS

GNUSL3S Linux

GNUSL3S Linux is a distribution built in Goa. It bundles a wide range of pre-installed software spanning bioinformatics (EMBOSS, Primer3), security tools for penetration testing, system administration utilities, and development editors. Boot from the DVD for a graphical interface with KDE, XFce, Fluxbox, or IceWM. Based on: Slackware, SLAX, Alixe, Davix Version: 10.05.xx Architecture: i486 (32-bit) Origin: Goa, India Status: Discontinued

Identifying Your Linux Distribution

Not sure which Linux distribution you’re running? Open a terminal and type: cat /etc/issue On Debian 4.0, for example, this outputs: Debian GNU/Linux 4.0 \n \l The \n and \l are escape sequences for the hostname and terminal device – they’re not part of the distribution name. This works on most distributions. Some also have /etc/os-release with more detail: cat /etc/os-release

The launch of Mandriva Linux 2010

Mandriva Linux 2010 is launching on November 3rd. Highlights from the announcement: KDE 4.3.1, GNOME 2.28, kernel 2.6.31.1, and Xorg 1.6.4 RC 1 with updated Intel graphics drivers. There’s also a Moblin 2 spin for netbooks. I’ve used Mandriva off and on over the years. The Control Centre has always been one of the better configuration tools in the Linux world. Worth keeping an eye on to see how this release shapes up.