Master the Art of the Command Line: Essential Bash Tips and Tricks
This comprehensive guide introduces the open‑source "The Art of Command Line" project and provides a curated collection of Bash fundamentals, daily usage shortcuts, file handling tricks, system debugging tools, one‑liners, and platform‑specific tips for Linux, macOS and Windows, helping engineers boost productivity and command‑line mastery.
Introduction
The article summarizes the popular GitHub repository https://github.com/jlevy/the-art-of-command-line, which provides a compact reference of essential command‑line techniques for both beginners and experienced users.
1. Bash Basics
Read the Bash manual with man bash and become familiar with vim ( vi) as a text editor.
Use documentation tools: man, apropos, help, type.
Redirect I/O with > (overwrite), >> (append), and pipe with |. Understand the difference between > and >>.
Employ glob patterns ( *, ?, [...]) and proper quoting.
Manage background jobs using &, ctrl‑z, jobs, fg, bg, kill, etc.
Set up SSH keys and agents with ssh, ssh‑agent, ssh‑add.
2. Daily Command‑Line Usage
Navigate history with Tab completion, ctrl‑r, and history expansions ( !!, !$, !n).
Switch between vi and emacs keymaps: set -o vi / set -o emacs.
Edit long commands in an external editor: set EDITOR=vim and press ctrl‑x ctrl‑e.
Change directories with cd, cd ~, or cd -. Use $HOME for scripts.
3. File and Data Processing
Search files: find . -name "pattern", locate pattern, grep / ag.
Convert formats: lynx -dump -stdin, pandoc, xmlstarlet, jq, shyaml, csvkit suite.
Text manipulation: awk, sed, cut, paste, sort, uniq, comm, tr.
Archive handling: gzip, bzip2, xz, tar, zip, unzip.
Permissions and attributes: chmod, chown, chattr, getfacl, setfacl.
Create empty or sparse files: truncate, fallocate, xfs_mkfile.
Split and join files: split, csplit, join.
4. System Debugging and Monitoring
Resource monitors: top, htop, iostat, iotop, free, vmstat.
Network inspection: netstat, ss, iftop, nethogs, mtr, wireshark / tshark.
Tracing and profiling: strace, ltrace, gdb, perf, systemtap ( stap).
Inspect /proc files ( /proc/cpuinfo, /proc/meminfo, etc.) for low‑level details.
Historical performance data: sar, glances, dstat.
5. One‑Liners
Typical patterns include using sort | uniq for set operations, counting fields with awk '{print $1}' | wc -l, and extracting log statistics via pipelines such as grep pattern file | cut -d' ' -f2 | sort | uniq -c.
6. Lesser‑Known but Useful Tools
expr, m4, yes, cal, env, printenv, look, fold, column, expand / unexpand, nl, seq, bc, factor, gpg, nc, socat, dd, file, tree, stat, time, timeout, lockfile, logrotate, watch, when‑changed, tac, shuf, comm, strings, tr, iconv / uconv, units, apg, xz, ldd, nm, ab / wrk, mtr, cssh, rsync, wireshark / tshark, ngrep, host / dig, lsof, dstat, glances, iostat, mpstat, vmstat, htop, last, w, id, sar, iftop / nethogs, ss, dmesg, sysctl, hdparm, lsblk, lshw / lscpu / lspci / lsusb / dmidecode, fortune, ddate, sl.
7. macOS‑Specific Tips
Install GNU core utilities via Homebrew ( brew install coreutils) or MacPorts.
Copy/paste with pbcopy and pbpaste.
Configure the Option key as Meta in Terminal preferences.
Open files or apps with open or open -a "AppName".
Search with Spotlight using mdfind and view metadata with mdls.
Prefer GNU versions of commands (e.g., gawk, gsed) when script portability matters.
Check OS version with sw_vers.
8. Windows‑Specific Tips
System administration via wmic.
Network utilities: ping, ipconfig, tracert, netstat.
Execute built‑in tasks with Rundll32.
9. Cygwin / WSL / MinGW
Install Cygwin for a full Unix‑like environment on Windows.
Use Windows Subsystem for Linux (WSL) for native Linux tools.
MinGW/MSYS provides the GNU toolchain ( gcc, make, gawk, grep) for native Windows builds.
Lightweight Bash‑like shells such as cash are available.
Access the Windows clipboard via /dev/clipboard, launch files with cygstart, and query the registry with regtool.
Convert Windows paths: /cygdrive/c ↔ C:\ using cygpath.
10. Further Resources
Awesome‑shell: https://github.com/alebcay/awesome-shell Awesome‑osx‑command‑line: https://github.com/herrbischoff/awesome-osx-command-line Unofficial Bash strict mode: http://redsymbol.net/articles/unofficial-bash-strict-mode/ ShellCheck static analysis: https://github.com/koalaman/shellcheck Filename handling in shells: http://www.dwheeler.com/essays/filenames-in-shell.html Data Science at the Command Line:
http://datascienceatthecommandline.com/#tools11. Disclaimer
While the guide contains many useful shortcuts, writing clear and maintainable scripts is more important than clever one‑liners. Use these techniques responsibly and share improvements under the Creative Commons Attribution‑ShareAlike 4.0 International license.
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.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
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.
