Operations 8 min read

Essential Linux Commands with Real‑World Examples

This guide introduces ten useful Linux command‑line tools—including pgrep, pstree, bc, split, nl, mkfifo, ldd, col, xmlwf, and lsof—explaining their purpose, typical usage patterns, and providing concrete command‑line examples to help users manage processes, files, and system information efficiently.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Essential Linux Commands with Real‑World Examples

1) pgrep – Lists process IDs matching a pattern. Example:

$ pgrep -u hchen
22441
22444

It is equivalent to ps -ef | egrep '^hchen' | awk '{print $2}' 2) pstree – Displays the process hierarchy as a tree. Example output shows the parent‑child relationships of system services and user processes.

3) bc – An arbitrary‑precision calculator useful for mathematical operations such as square‑root calculations. A sample script sqrt demonstrates how to compute square roots via

#!/bin/bash
if [ $# -eq 0 ]; then
    echo 'Usage: sqrt number'
    exit 1
else
    echo -e "sqrt($1)
quit
" | bc -q -i
fi

Running the script yields results like ./sqrt 36 → 6, ./sqrt 2.0000 → 1.4142, etc.

4) split – Divides a large file into smaller chunks. Example:

[hchen@RHELSVR5 applebak]# split -b 50m largefile.tar.gz LF_

Resulting files LF_aa, LF_ab, … can be recombined with cat LF_* > largefile.tar.gz 5) nl – Numbers lines of a file, similar to cat but adds line numbers. Example: nl stdio.h | head -n 10 6) mkfifo – Creates a named pipe for inter‑process communication. Example creation and usage:

mkfifo /tmp/hchenpipe
ls -l /tmp   # shows the pipe
ls -al > /tmp/hchenpipe   # blocks until another process reads
head /tmp/hchenpipe       # reads and unblocks the writer

7) ldd – Lists shared libraries required by an executable. Example for /usr/bin/java shows each linked library and its path.

8) col – Converts formatted man pages to plain text. Example:

# PAGER=cat
# man less | col -b > less.txt

9) xmlwf – Validates an XML file, reporting malformed tags. Example workflow downloads an RSS feed, runs xmlwf, and fixes a mismatched tag.

10) lsof – Lists open files and network sockets. Example filters TCP listeners and established connections, showing processes such as httpd, sshd, and mysqld.

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.

ShellSysadmincommand-linefile-manipulationprocess-management
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.