Fundamentals 8 min read

Unlock Hidden Linux Gems: Master fold, column, sg, xxd, pwdx, and write

This guide explores lesser‑known Linux /usr/bin utilities—fold, column, sg, xxd, pwdx, and write—showing how each command works, providing example usages, and explaining practical scenarios where they simplify text formatting, group permission handling, hex dumping, process directory inspection, and inter‑user messaging.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Unlock Hidden Linux Gems: Master fold, column, sg, xxd, pwdx, and write

In this article we dive into the hidden corners of /usr/bin, uncovering several useful but often overlooked Linux utilities and demonstrating practical ways to use them.

fold

The fold command wraps input lines to a specified width, either by byte count or by spaces, making it handy for formatting long text streams or enforcing line‑length limits in code or configuration files. echo "12345678" | fold -w 7 The output will be:

1234567
8
fold command output example
fold command output example

This is useful for breaking long text streams into manageable chunks or enforcing line‑length constraints.

column

The column utility formats text into aligned columns, effectively creating simple tables directly from the command line. It is easier to remember than constructing equivalent awk scripts.

echo -e "one two three
1 2 3
93139 777777 999999" | column -t

The resulting output is:

one      two     three
1        2       3
93139    777777  999999
column command formatted table
column command formatted table

This tool quickly turns loosely‑structured data into a readable table, automatically adjusting column widths.

sg

The sg command runs a command with the permissions of a specified group, similar to newgrp but without changing the current shell group.

sg sudo ls
sg command example
sg command example

After execution, the command returns to the original group context. This is handy for testing group permissions or temporarily running a program as another group.

xxd

xxd

creates a hexadecimal dump of a file and can also reverse the process. It is useful for inspecting binary data or generating hex representations. xxd linuxmi Typical output:

00000000: 6c69 6e75 786d 690a
xxd hex dump example
xxd hex dump example

You can also write the dump directly to a file:

xxd linuxmi 93139
xxd output redirected to file
xxd output redirected to file

pwdx

The pwdx utility, part of the classic ps family, reports the current working directory of a running process given its PID.

ps aux | grep cron
finding cron PID
finding cron PID

Assuming the PID is 612, run:

sudo pwdx 612
pwdx output showing /var/spool/cron
pwdx output showing /var/spool/cron

This quickly reveals the directory from which a process believes it is running, a valuable troubleshooting aid.

write

The write command sends a message directly to another logged‑in user's terminal. It dates back to early Unix (Version 6, 1975) and remains a simple way to communicate across sessions. write <username> After invoking, you type the message; it appears instantly on the target user's console. The interaction is one‑way and intrusive, so it should be used judiciously.

Although modern messaging tools exist, write is a historical piece of Unix that can still serve niche purposes.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

command-linecolumnwrite()foldpwdxsgxxd
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.