10 Essential Linux Commands Every Developer Should Master
This article introduces ten fundamental Linux commands—pgrep, pstree, bc, split, nl, mkfifo, ldd, col, xmlwf, and lsof—explaining their purposes, typical usage examples, and how they can help developers and system administrators work more efficiently on Unix-like systems.
01 pgrep
The pgrep command lists process IDs matching given criteria, similar to combining ps, egrep, and awk.
$ pgrep -u hchen22441 22444 ps -ef | egrep '^hchen' | awk '{print $2}'02 pstree
pstreedisplays the process hierarchy in a tree format, making it easy to visualize parent‑child relationships among running processes.
[hchen@RHELSVR5 ~]$ pstree
init-+-acpid
|-auditd-+-python
| `-{auditd}
|-automount---4*[{automount}]
|-backup.sh---sleep
|-dbus-daemon
|-httpd---10*[httpd]
... (truncated for brevity)03 bc
bcis an arbitrary‑precision calculator useful for mathematical operations such as computing square roots. The example script sqrt demonstrates its use.
#!/bin/bash
if [ $# -ne 1 ]; then
echo 'Usage: sqrt number'
exit 1
else
echo -e "sqrt($1)
quit
" | bc -q -i
fiRunning the script:
[hchen@RHELSVR5]$ ./sqrt 36
6
[hchen@RHELSVR5]$ ./sqrt 2.0000
1.4142
[hchen@RHELSVR5]$ ./sqrt 10.0000
3.162204 split
splitdivides a large file into smaller chunks of a specified size.
[hchen@RHELSVR5 applebak]# ls -l largefile.tar.gz
-rw-r--r-- 1 hchen hchen 436774774 04-17 02:00 largefile.tar.gz
[hchen@RHELSVR5 applebak]# split -b 50m largefile.tar.gz LF_
[hchen@RHELSVR5]# ls -l LF_*
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_aa
-rw-r--r-- 1 hchen hchen 52428800 05-10 18:34 LF_ab
... (additional parts) ...Recombine the parts:
[hchen@RHELSVR5]# cat LF_* > largefile.tar.gz05 nl
The nl command numbers lines of a file, similar to cat -n, but with more formatting options.
[hchen@RHELSVR5 include]# nl stdio.h | head -n 10
1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991,1994-2004,2005,2006 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8 The GNU C Library is distributed in the hope that it will be useful,06 mkfifo
mkfifocreates a named pipe, allowing inter‑process communication via a file in the filesystem.
[hchen@RHELSVR5 ~]# mkfifo /tmp/hchenpipe
[hchen@RHELSVR5 ~]# ls -l /tmp
prw-rw-r-- 1 hchen hchen 0 05-10 18:58 hchenpipeOne shell writes to the pipe (blocks until read): [hchen@RHELSVR5 ~]# ls -al > /tmp/hchenpipe Another shell reads from it, releasing the block:
[hchen@RHELSVR5 ~]# head /tmp/hchenpipe
drwx------ 8 hchen hchen 4096 05-10 18:27 .
drwxr-xr-x 7 root root 4096 03-05 00:06 ..
... (listing continues) ...07 ldd
lddshows the shared libraries required by an executable.
[hchen@RHELSVR5 ~]# ldd /usr/bin/java
linux-gate.so.1 => (0x00cd9000)
libgij.so.7rh => /usr/lib/libgij.so.7rh (0x00ed3000)
libgcj.so.7rh => /usr/lib/libgcj.so.7rh (0x00ed6000)
libpthread.so.0 => /lib/i686/nosegneg/libpthread.so.0 (0x00110000)
... (additional libraries) ...08 col
colfilters reverse line feeds, often used to convert man pages to plain text.
# PAGER=cat man less | col -b > less.txt09 xmlwf
xmlwfvalidates an XML file, reporting mismatched tags or other well‑formedness errors.
[hchen@RHELSVR5 ~]# curl 'https://coolshell.cn/?feed=rss2' > cocre.xml
[hchen@RHELSVR5 ~]# xmlwf cocre.xml
[hchen@RHELSVR5 ~]# perl -i -pe 's@<link>@<br>@g' cocre.xml
[hchen@RHELSVR5 ~]# xmlwf cocre.xml
cocre.xml:13:23: mismatched tag10 lsof
lsoflists open files and the processes that opened them, useful for diagnosing resource usage.
[root@RHELSVR5 ~]# lsof | grep TCPhttpd
548 apache 4u IPv6 14300967 TCP *:http (LISTEN)
... (additional entries) ...Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
