<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Linux on Cheat Sheet</title><link>/tags/linux/</link><description>Recent content in Linux on Cheat Sheet</description><generator>Hugo</generator><language>en</language><lastBuildDate>Tue, 04 Aug 2026 00:00:00 +0000</lastBuildDate><atom:link href="/tags/linux/index.xml" rel="self" type="application/rss+xml"/><item><title>File I/O</title><link>/linux/system-programming/file-io/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/linux/system-programming/file-io/</guid><description>&lt;p&gt;Based on &lt;em&gt;The Linux Programming Interface&lt;/em&gt; Chapter 4 (File I/O: The Universal I/O Model) and Chapter 5 (File I/O: Further Details).
See &lt;a href="../../programming/go/std/io/"&gt;Go io package&lt;/a&gt; for equivalent abstractions (&lt;code&gt;io.Reader&lt;/code&gt;, &lt;code&gt;io.Writer&lt;/code&gt;, &lt;code&gt;io.Seeker&lt;/code&gt;) in Go.&lt;/p&gt;
&lt;h2 id="core-function-signatures"&gt;Core Function Signatures&lt;a class="anchor" href="#core-function-signatures"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;All I/O operations on regular files, devices, pipes, sockets, and terminals use these core system calls.&lt;/p&gt;
&lt;h3 id="1-open"&gt;1. open&lt;a class="anchor" href="#1-open"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Opens an existing file or creates a new file.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#57606a"&gt;#include&lt;/span&gt; &lt;span style="color:#57606a"&gt;&amp;lt;fcntl.h&amp;gt;&lt;/span&gt;&lt;span style="color:#57606a"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#cf222e"&gt;int&lt;/span&gt; &lt;span style="color:#6639ba"&gt;open&lt;/span&gt;&lt;span style="color:#1f2328"&gt;(&lt;/span&gt;&lt;span style="color:#cf222e"&gt;const&lt;/span&gt; &lt;span style="color:#cf222e"&gt;char&lt;/span&gt; &lt;span style="color:#0550ae"&gt;*&lt;/span&gt;pathname&lt;span style="color:#1f2328"&gt;,&lt;/span&gt; &lt;span style="color:#cf222e"&gt;int&lt;/span&gt; flags&lt;span style="color:#1f2328"&gt;,&lt;/span&gt; &lt;span style="color:#1f2328"&gt;...&lt;/span&gt; &lt;span style="color:#57606a"&gt;/* mode_t mode */&lt;/span&gt;&lt;span style="color:#1f2328"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Return:&lt;/strong&gt; New file descriptor (non-negative integer) on success; &lt;code&gt;-1&lt;/code&gt; on error (&lt;code&gt;errno&lt;/code&gt; set)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parameters:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;pathname&amp;gt;&lt;/code&gt;: Path to the target file&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;flags&amp;gt;&lt;/code&gt;: Bitwise OR of access mode and status flags&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;mode&amp;gt;&lt;/code&gt;: Permissions for newly created file (&lt;code&gt;0644&lt;/code&gt;, &lt;code&gt;0600&lt;/code&gt;, etc.), required only when &lt;code&gt;O_CREAT&lt;/code&gt; is specified&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="access-modes-specify-exactly-one"&gt;Access Modes (Specify exactly one)&lt;a class="anchor" href="#access-modes-specify-exactly-one"&gt;#&lt;/a&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;O_RDONLY&lt;/code&gt;: Open for read-only&lt;/li&gt;
&lt;li&gt;&lt;code&gt;O_WRONLY&lt;/code&gt;: Open for write-only&lt;/li&gt;
&lt;li&gt;&lt;code&gt;O_RDWR&lt;/code&gt;: Open for reading and writing&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="common-creation-and-status-flags"&gt;Common Creation and Status Flags&lt;a class="anchor" href="#common-creation-and-status-flags"&gt;#&lt;/a&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;O_CREAT&lt;/code&gt;: Create file if it does not exist&lt;/li&gt;
&lt;li&gt;&lt;code&gt;O_EXCL&lt;/code&gt;: Used with &lt;code&gt;O_CREAT&lt;/code&gt;; fail atomically if file already exists (&lt;code&gt;EEXIST&lt;/code&gt;). Prevents Time-of-Check to Time-of-Use (TOCTOU) race conditions when creating lock files (&lt;code&gt;app.lock&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;O_TRUNC&lt;/code&gt;: Truncate existing file length to zero&lt;/li&gt;
&lt;li&gt;&lt;code&gt;O_APPEND&lt;/code&gt;: Atomically updates file offset to end of file before each write. Prevents race conditions between multiple processes appending to the same file (eliminates &lt;code&gt;lseek(SEEK_END)&lt;/code&gt; race conditions)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;O_NONBLOCK&lt;/code&gt;: Open in non-blocking mode (useful for FIFOs, pipes, and sockets)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;O_CLOEXEC&lt;/code&gt;: Enable close-on-exec flag atomically. Prevents file descriptor leakage across &lt;code&gt;exec&lt;/code&gt; calls to child programs (stored in the process-private FD table)&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id="2-read"&gt;2. read&lt;a class="anchor" href="#2-read"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Reads data from an open file descriptor into a memory buffer.&lt;/p&gt;</description></item><item><title>locate vs type vs which vs whereis</title><link>/linux/cli/locate-vs-type-vs-which-vs-whereis/</link><pubDate>Mon, 15 Jun 2026 00:00:00 +0000</pubDate><guid>/linux/cli/locate-vs-type-vs-which-vs-whereis/</guid><description>&lt;h1 id="locate-vs-type-vs-which-vs-whereis"&gt;&lt;code&gt;locate&lt;/code&gt; vs &lt;code&gt;type&lt;/code&gt; vs &lt;code&gt;which&lt;/code&gt; vs &lt;code&gt;whereis&lt;/code&gt;&lt;a class="anchor" href="#locate-vs-type-vs-which-vs-whereis"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Comparison of different methods to locate commands and files in Linux.&lt;/p&gt;
&lt;h2 id="comparison"&gt;Comparison&lt;a class="anchor" href="#comparison"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;type&lt;/code&gt;&lt;/strong&gt;: The most reliable way to determine what the shell will execute. Since it is a shell built-in, it identifies shell built-ins, aliases, and functions that external tools miss.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;which&lt;/code&gt;&lt;/strong&gt;: Locates an executable in the user&amp;rsquo;s &lt;code&gt;PATH&lt;/code&gt;. It does not show shell built-ins or aliases by default.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;whereis&lt;/code&gt;&lt;/strong&gt;: Locates the binary, source, and manual page files for a command. It searches a predefined list of standard directories.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;locate&lt;/code&gt;&lt;/strong&gt;: Searches a pre-built database (&lt;code&gt;mlocate.db&lt;/code&gt;) of the entire filesystem. It is extremely fast but may not find recently created files until the database is updated (typically via &lt;code&gt;updatedb&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="usage"&gt;Usage&lt;a class="anchor" href="#usage"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="type"&gt;&lt;code&gt;type&lt;/code&gt;&lt;a class="anchor" href="#type"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-a&lt;/code&gt;&lt;/strong&gt;: Display all locations containing an executable named &lt;code&gt;&amp;lt;name&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-t&lt;/code&gt;&lt;/strong&gt;: Print a single word describing the type of the command (eg. &lt;code&gt;alias&lt;/code&gt;, &lt;code&gt;keyword&lt;/code&gt;, &lt;code&gt;function&lt;/code&gt;, &lt;code&gt;builtin&lt;/code&gt;, &lt;code&gt;file&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="locate"&gt;&lt;code&gt;locate&lt;/code&gt;&lt;a class="anchor" href="#locate"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-i&lt;/code&gt;&lt;/strong&gt;: Ignore case distinctions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-r&lt;/code&gt;&lt;/strong&gt;: Search using a basic regular expression.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="examples"&gt;Examples&lt;a class="anchor" href="#examples"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Identify command type&lt;/strong&gt;:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ &lt;span style="color:#6639ba"&gt;type&lt;/span&gt; &lt;span style="color:#6639ba"&gt;cd&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#6639ba"&gt;cd&lt;/span&gt; is a shell builtin&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Show all locations&lt;/strong&gt;:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ &lt;span style="color:#6639ba"&gt;type&lt;/span&gt; -a ls
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ls is aliased to &lt;span style="color:#0a3069"&gt;`&lt;/span&gt;ls --color&lt;span style="color:#0550ae"&gt;=&lt;/span&gt;auto&lt;span style="color:#f6f8fa;background-color:#82071e"&gt;&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ls is /usr/bin/ls&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Find binary and man page&lt;/strong&gt;:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ whereis grep
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;grep: /usr/bin/grep /usr/share/man/man1/grep.1.gz&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Locate all files with a specific name&lt;/strong&gt;:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ locate -i &amp;lt;filename&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>make</title><link>/linux/cli/make/</link><pubDate>Mon, 15 Jun 2026 00:00:00 +0000</pubDate><guid>/linux/cli/make/</guid><description>&lt;h1 id="make"&gt;&lt;code&gt;make&lt;/code&gt;&lt;a class="anchor" href="#make"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h2 id="makefile-syntax"&gt;Makefile Syntax&lt;a class="anchor" href="#makefile-syntax"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;Makefile&lt;/code&gt; consists of a set of rules. A rule has the following format:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-makefile" data-lang="makefile"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#6639ba"&gt;&amp;lt;target&amp;gt;&lt;/span&gt;&lt;span style="color:#0550ae"&gt;:&lt;/span&gt; &amp;lt;prerequisites&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&amp;lt;recipe&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Target&lt;/strong&gt;: Usually the name of a file generated by a program (eg. executables or objects). It can also be the name of an action to carry out (eg. &lt;code&gt;clean&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;: Files used as input to create the target. Multiple prerequisites are separated by spaces. A target is rebuilt if any of its prerequisites change.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recipe&lt;/strong&gt;: Actions that &lt;code&gt;make&lt;/code&gt; carries out. &lt;strong&gt;Important:&lt;/strong&gt; Every recipe line must begin with a tab character.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="multiple-prerequisites-example"&gt;Multiple Prerequisites Example&lt;a class="anchor" href="#multiple-prerequisites-example"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-makefile" data-lang="makefile"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#6639ba"&gt;main&lt;/span&gt;&lt;span style="color:#0550ae"&gt;:&lt;/span&gt; main.o utils.o
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	gcc -o main main.o utils.o
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="special-targets-and-variables"&gt;Special Targets and Variables&lt;a class="anchor" href="#special-targets-and-variables"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="phony"&gt;&lt;code&gt;.PHONY&lt;/code&gt;&lt;a class="anchor" href="#phony"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Defines targets that do not represent actual files. This prevents &lt;code&gt;make&lt;/code&gt; from failing to run a command if a file with the same name exists in the directory.&lt;/p&gt;</description></item><item><title>Process</title><link>/linux/system-programming/process/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/linux/system-programming/process/</guid><description>&lt;p&gt;Based on &lt;em&gt;The Linux Programming Interface&lt;/em&gt; Chapter 6 (Processes), Chapter 24 (Process Creation), Chapter 25 (Process Termination), Chapter 26 (Monitoring Child Processes), and Chapter 27 (Program Execution).&lt;/p&gt;
&lt;p&gt;The Linux process lifecycle is governed by the combination of four core system calls:&lt;/p&gt;
&lt;span class="book-katex" &gt;\( 
\mathbf{fork()} \longrightarrow \mathbf{execve()} \longrightarrow \mathbf{exit()} / \mathbf{\_exit()} \longrightarrow \mathbf{waitpid()}
 \)&lt;/span&gt;
&lt;hr&gt;
&lt;h2 id="1-process-virtual-memory-layout-tlpi-ch-6"&gt;1. Process Virtual Memory Layout (TLPI Ch 6)&lt;a class="anchor" href="#1-process-virtual-memory-layout-tlpi-ch-6"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The kernel allocates an independent virtual address space for each process, structured from low to high addresses as follows:&lt;/p&gt;</description></item><item><title>Shared Libraries</title><link>/linux/system-programming/shared-libraries/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/linux/system-programming/shared-libraries/</guid><description>&lt;p&gt;Based on &lt;em&gt;The Linux Programming Interface&lt;/em&gt; Chapter 41 (Fundamentals of Shared Libraries) and Chapter 42 (Advanced Features of Shared Libraries).&lt;/p&gt;
&lt;h1 id="shared-libraries"&gt;Shared Libraries&lt;a class="anchor" href="#shared-libraries"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;hr&gt;
&lt;h2 id="1-header-vs-static-vs-shared-library-tlpi-ch-41"&gt;1. Header vs Static vs Shared Library (TLPI Ch 41)&lt;a class="anchor" href="#1-header-vs-static-vs-shared-library-tlpi-ch-41"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;C libraries (eg. &lt;code&gt;glibc&lt;/code&gt;) separate compile-time declarations from link-time and runtime binaries.&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th style="text-align: left"&gt;Artifact&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Extension &amp;amp; Example Path&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Role&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Phase&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Header&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;.h&lt;/code&gt; (&lt;code&gt;/usr/include/dlfcn.h&lt;/code&gt;)&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Plain-text function signatures, types, and macros&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Compile time (&lt;code&gt;gcc -c&lt;/code&gt;)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Static Library&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;.a&lt;/code&gt; (&lt;code&gt;libc.a&lt;/code&gt;)&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Archive of &lt;code&gt;.o&lt;/code&gt; object files copied directly into the executable&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Link time (&lt;code&gt;gcc -static&lt;/code&gt;)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Shared Library&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;.so&lt;/code&gt; (&lt;code&gt;/lib/x86_64-linux-gnu/libc.so.6&lt;/code&gt;)&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Precompiled Position-Independent machine code loaded once into memory and shared across processes&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Runtime (&lt;code&gt;ld.so&lt;/code&gt; dynamic linker)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id="building-and-inspecting-shared-libraries"&gt;Building and Inspecting Shared Libraries&lt;a class="anchor" href="#building-and-inspecting-shared-libraries"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ gcc -fPIC -shared -Wall -o libfoo.so foo.c
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ ldd &amp;lt;binary&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ nm -D libfoo.so&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-fPIC&lt;/code&gt;: Generate Position-Independent Code so the library can be mapped at any virtual address&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-shared&lt;/code&gt;: Produce a shared object (&lt;code&gt;.so&lt;/code&gt;) instead of an executable requiring &lt;code&gt;main&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ldd&lt;/code&gt;: List shared libraries required by a binary and their resolved paths&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nm -D&lt;/code&gt;: Inspect exported dynamic symbols in a &lt;code&gt;.so&lt;/code&gt; file&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="2-dynamic-loading-api-dlopen--dlsym-tlpi-ch-42"&gt;2. Dynamic Loading API: &lt;code&gt;dlopen&lt;/code&gt; &amp;amp; &lt;code&gt;dlsym&lt;/code&gt; (TLPI Ch 42)&lt;a class="anchor" href="#2-dynamic-loading-api-dlopen--dlsym-tlpi-ch-42"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;glibc&lt;/code&gt; API for loading shared libraries into memory and resolving symbol addresses dynamically &lt;strong&gt;at runtime&lt;/strong&gt; rather than at program startup (&lt;code&gt;man 3 dlopen&lt;/code&gt;, &lt;code&gt;man 3 dlsym&lt;/code&gt;). The &lt;strong&gt;&lt;code&gt;RTLD_&lt;/code&gt;&lt;/strong&gt; prefix stands for &lt;strong&gt;R&lt;/strong&gt;un-&lt;strong&gt;T&lt;/strong&gt;ime &lt;strong&gt;L&lt;/strong&gt;ink-&lt;strong&gt;D&lt;/strong&gt;ynamic.&lt;/p&gt;</description></item><item><title>BASH_SOURCE</title><link>/linux/shell/bash-source/</link><pubDate>Tue, 04 Aug 2026 00:00:00 +0000</pubDate><guid>/linux/shell/bash-source/</guid><description>&lt;h1 id="bash_source"&gt;&lt;code&gt;BASH_SOURCE&lt;/code&gt;&lt;a class="anchor" href="#bash_source"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;BASH_SOURCE&lt;/code&gt; is an array variable that contains the source filenames where the corresponding shell function or script is defined.&lt;/p&gt;
&lt;h3 id="bash_source0-vs-0"&gt;&lt;code&gt;${BASH_SOURCE[0]}&lt;/code&gt; vs &lt;code&gt;$0&lt;/code&gt;&lt;a class="anchor" href="#bash_source0-vs-0"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;While &lt;code&gt;$0&lt;/code&gt; is often used to get the name of the script, it behaves differently depending on how the script is invoked. &lt;code&gt;${BASH_SOURCE[0]}&lt;/code&gt; is more reliable for finding the actual file path.&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th style="text-align: left"&gt;Context&lt;/th&gt;
 &lt;th style="text-align: left"&gt;&lt;code&gt;$0&lt;/code&gt;&lt;/th&gt;
 &lt;th style="text-align: left"&gt;&lt;code&gt;${BASH_SOURCE[0]}&lt;/code&gt;&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Interactive Shell&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;-bash&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;(empty)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Executing Script&lt;/strong&gt; (&lt;code&gt;./app.sh&lt;/code&gt;)&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;./app.sh&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;./app.sh&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Sourcing Script&lt;/strong&gt; (&lt;code&gt;source app.sh&lt;/code&gt;)&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;-bash&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;app.sh&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id="why-use-bash_source0"&gt;Why use &lt;code&gt;${BASH_SOURCE[0]}&lt;/code&gt;?&lt;a class="anchor" href="#why-use-bash_source0"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;When a script is &lt;strong&gt;sourced&lt;/strong&gt; (using &lt;code&gt;source&lt;/code&gt; or &lt;code&gt;.&lt;/code&gt;), &lt;code&gt;$0&lt;/code&gt; remains the name of the calling shell (eg. &lt;code&gt;-bash&lt;/code&gt;), whereas &lt;code&gt;${BASH_SOURCE[0]}&lt;/code&gt; correctly points to the script being sourced. This makes it the standard way to determine the script&amp;rsquo;s directory regardless of how it was executed.&lt;/p&gt;</description></item><item><title>Redirection</title><link>/linux/shell/redirection/</link><pubDate>Tue, 16 Jun 2026 00:00:00 +0000</pubDate><guid>/linux/shell/redirection/</guid><description>&lt;h1 id="redirection"&gt;Redirection&lt;a class="anchor" href="#redirection"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;The order of redirection matters because the shell processes them from left to right.&lt;/p&gt;
&lt;h2 id="-devnull-21-vs-21--devnull"&gt;&lt;code&gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;/code&gt; vs &lt;code&gt;2&amp;gt;&amp;amp;1 &amp;gt; /dev/null&lt;/code&gt;&lt;a class="anchor" href="#-devnull-21-vs-21--devnull"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="1--devnull-21"&gt;1. &lt;code&gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;/code&gt;&lt;a class="anchor" href="#1--devnull-21"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Both &lt;strong&gt;stdout&lt;/strong&gt; and &lt;strong&gt;stderr&lt;/strong&gt; are suppressed.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;&amp;gt; /dev/null&lt;/code&gt;: Redirects stdout to &lt;code&gt;/dev/null&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;2&amp;gt;&amp;amp;1&lt;/code&gt;: Redirects stderr to the current location of stdout (which is now &lt;code&gt;/dev/null&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="2-21--devnull"&gt;2. &lt;code&gt;2&amp;gt;&amp;amp;1 &amp;gt; /dev/null&lt;/code&gt;&lt;a class="anchor" href="#2-21--devnull"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Only &lt;strong&gt;stdout&lt;/strong&gt; is suppressed; &lt;strong&gt;stderr&lt;/strong&gt; is still printed to the terminal.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;2&amp;gt;&amp;amp;1&lt;/code&gt;: Redirects stderr to the current location of stdout (the terminal).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;gt; /dev/null&lt;/code&gt;: Redirects stdout to &lt;code&gt;/dev/null&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="heading"&gt;&lt;code&gt;&amp;amp;&amp;gt;&lt;/code&gt;&lt;a class="anchor" href="#heading"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A Bash shortcut to redirect both stdout and stderr to the same destination. &lt;code&gt;&amp;amp;&amp;gt; &amp;lt;file&amp;gt;&lt;/code&gt; is equivalent to &lt;code&gt;&amp;gt; &amp;lt;file&amp;gt; 2&amp;gt;&amp;amp;1&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Special Variables</title><link>/linux/shell/special-variables/</link><pubDate>Tue, 16 Jun 2026 00:00:00 +0000</pubDate><guid>/linux/shell/special-variables/</guid><description>&lt;h1 id="special-variables"&gt;Special Variables&lt;a class="anchor" href="#special-variables"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Commonly used special shell parameters and operators.&lt;/p&gt;
&lt;h2 id="parameters"&gt;Parameters&lt;a class="anchor" href="#parameters"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th style="text-align: left"&gt;Variable&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;$$&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;PID of the current shell&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;$?&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Exit status of the last executed command (&lt;code&gt;0&lt;/code&gt; for success)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;$#&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Number of positional parameters&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;$*&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;All positional parameters (as a single word)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;$@&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;All positional parameters (as separate words)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;$!&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;PID of the last background command&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;$0&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Name of the script or shell (See &lt;a href="../../linux/shell/bash-source/"&gt;&lt;code&gt;BASH_SOURCE&lt;/code&gt;&lt;/a&gt;)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;$1&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;First positional parameter&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id="-vs-"&gt;&lt;code&gt;$*&lt;/code&gt; vs &lt;code&gt;$@&lt;/code&gt;&lt;a class="anchor" href="#-vs-"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Both &lt;code&gt;$*&lt;/code&gt; and &lt;code&gt;$@&lt;/code&gt; represent all positional parameters starting from &lt;code&gt;$1&lt;/code&gt;. They &lt;strong&gt;do not include&lt;/strong&gt; &lt;code&gt;$0&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>awk</title><link>/linux/cli/awk/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/cli/awk/</guid><description>&lt;h1 id="awk"&gt;&lt;code&gt;awk&lt;/code&gt;&lt;a class="anchor" href="#awk"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;blockquote class='book-hint '&gt;
&lt;p&gt;&amp;ldquo;Many, many people use &lt;code&gt;awk&lt;/code&gt; only to do one thing—to pick a single field out of an input stream.&amp;rdquo;&lt;/p&gt;
&lt;div style="text-align: right;"&gt;&lt;i&gt;How Linux Works 11.10.2&lt;/i&gt;&lt;/div&gt;
&lt;/blockquote&gt;&lt;h2 id="basic-usage"&gt;Basic Usage&lt;a class="anchor" href="#basic-usage"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="field-selection"&gt;Field Selection&lt;a class="anchor" href="#field-selection"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Print specific columns using &lt;code&gt;$N&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#57606a"&gt;# Print the 5th field&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ls -l &lt;span style="color:#1f2328"&gt;|&lt;/span&gt; awk &lt;span style="color:#0a3069"&gt;&amp;#39;{print $5}&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="pattern-search"&gt;Pattern Search&lt;a class="anchor" href="#pattern-search"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Filter lines matching a pattern before performing an action.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#57606a"&gt;# Print the 5th field of lines containing &amp;#34;log&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ls -l &lt;span style="color:#1f2328"&gt;|&lt;/span&gt; awk &lt;span style="color:#0a3069"&gt;&amp;#39;/log/ {print $5}&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="built-in-variables"&gt;Built-in Variables&lt;a class="anchor" href="#built-in-variables"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="nr-number-of-records"&gt;&lt;code&gt;NR&lt;/code&gt; (Number of Records)&lt;a class="anchor" href="#nr-number-of-records"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Represents the current line number.&lt;/p&gt;</description></item><item><title>find</title><link>/linux/cli/find/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/cli/find/</guid><description>&lt;h1 id="find"&gt;&lt;code&gt;find&lt;/code&gt;&lt;a class="anchor" href="#find"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h3 id="general-usage"&gt;General Usage&lt;a class="anchor" href="#general-usage"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;find &amp;lt;path&amp;gt; &amp;lt;expression&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="common-flags"&gt;Common Flags&lt;a class="anchor" href="#common-flags"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-name&lt;/code&gt;&lt;/strong&gt;: Search by filename pattern (eg. &lt;code&gt;-name '*.log'&lt;/code&gt;). Single quotes are recommended to prevent the shell from expanding wildcards prematurely.
&lt;ul&gt;
&lt;li&gt;&lt;a href="../../linux/shell/process-order/"&gt;Shell Processing Order&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-type&lt;/code&gt;&lt;/strong&gt;: Filter by file type
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;f&lt;/code&gt;: file&lt;/li&gt;
&lt;li&gt;&lt;code&gt;d&lt;/code&gt;: directory&lt;/li&gt;
&lt;li&gt;&lt;code&gt;l&lt;/code&gt;: symbolic link&lt;/li&gt;
&lt;li&gt;&lt;code&gt;s&lt;/code&gt;: socket&lt;/li&gt;
&lt;li&gt;&lt;code&gt;p&lt;/code&gt;: named pipe (FIFO)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;b&lt;/code&gt;: block device&lt;/li&gt;
&lt;li&gt;&lt;code&gt;c&lt;/code&gt;: character device&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-print&lt;/code&gt;&lt;/strong&gt;: Display results to standard output (default).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-print0&lt;/code&gt;&lt;/strong&gt;: Separate results with a null character (&lt;code&gt;\0&lt;/code&gt;). Useful for filenames with spaces.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-exec&lt;/code&gt;&lt;/strong&gt;: Execute a command on the search results.
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;\;&lt;/code&gt; (Individual Execution):&lt;/strong&gt; Runs the command once for each result. The semicolon must be escaped (&lt;code&gt;\;&lt;/code&gt;) because it is a shell reserved character.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;+&lt;/code&gt; (Batch Execution):&lt;/strong&gt; Collects results and runs the command once with multiple arguments (similar to &lt;code&gt;xargs&lt;/code&gt;). Better for performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>grep</title><link>/linux/cli/grep/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/cli/grep/</guid><description>&lt;h1 id="grep"&gt;&lt;code&gt;grep&lt;/code&gt;&lt;a class="anchor" href="#grep"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h3 id="general-usage"&gt;General Usage&lt;a class="anchor" href="#general-usage"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;grep &amp;lt;options&amp;gt; &amp;lt;pattern&amp;gt; &amp;lt;file&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="common-flags"&gt;Common Flags&lt;a class="anchor" href="#common-flags"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-i, --ignore-case&lt;/code&gt;&lt;/strong&gt;: Ignore case distinctions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-v, --invert-match&lt;/code&gt;&lt;/strong&gt;: Invert the sense of matching, selecting non-matching lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-l, --files-with-matches&lt;/code&gt;&lt;/strong&gt;: Print only the names of files with matching lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-q, --quiet, --silent&lt;/code&gt;&lt;/strong&gt;: Do not write anything to standard output. Exit immediately with zero status if any match is found.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-n, --line-number&lt;/code&gt;&lt;/strong&gt;: Prefix each line of output with its 1-based line number.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-E, --extended-regexp&lt;/code&gt;&lt;/strong&gt;: Interpret patterns as extended regular expressions (ERE).
&lt;ul&gt;
&lt;li&gt;eg. &lt;code&gt;grep -E '&amp;lt;pattern1&amp;gt;|&amp;lt;pattern2&amp;gt;|...' &amp;lt;file&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-r, --recursive&lt;/code&gt;&lt;/strong&gt;: Read all files under each directory, recursively.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-A &amp;lt;num&amp;gt;, --after-context=&amp;lt;num&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Print &lt;code&gt;&amp;lt;num&amp;gt;&lt;/code&gt; lines of trailing context after matching lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-B &amp;lt;num&amp;gt;, --before-context=&amp;lt;num&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Print &lt;code&gt;&amp;lt;num&amp;gt;&lt;/code&gt; lines of leading context before matching lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-C &amp;lt;num&amp;gt;, --context=&amp;lt;num&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Print &lt;code&gt;&amp;lt;num&amp;gt;&lt;/code&gt; lines of output context.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="posix-character-classes"&gt;POSIX Character Classes&lt;a class="anchor" href="#posix-character-classes"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Used within bracket expressions &lt;code&gt;[ ]&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>pgrep</title><link>/linux/cli/pgrep/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/cli/pgrep/</guid><description>&lt;h1 id="pgrep"&gt;&lt;code&gt;pgrep&lt;/code&gt;&lt;a class="anchor" href="#pgrep"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-l&lt;/code&gt;&lt;/strong&gt;: List the process name in addition to the PID.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-a&lt;/code&gt;&lt;/strong&gt;: List the full command line in addition to the PID.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-u&lt;/code&gt;&lt;/strong&gt;: Select only processes whose effective user ID is listed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-f&lt;/code&gt;&lt;/strong&gt;: Match the pattern against the full command line (not just the process name).&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>ps</title><link>/linux/cli/ps/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/cli/ps/</guid><description>&lt;h1 id="ps"&gt;&lt;code&gt;ps&lt;/code&gt;&lt;a class="anchor" href="#ps"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;P&lt;/strong&gt;rocess &lt;strong&gt;S&lt;/strong&gt;tatus&lt;/p&gt;
&lt;h2 id="styles"&gt;Styles&lt;a class="anchor" href="#styles"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="bsd-style-aux"&gt;BSD Style (&lt;code&gt;aux&lt;/code&gt;)&lt;a class="anchor" href="#bsd-style-aux"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Does not use a dash before options.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;a&lt;/code&gt;&lt;/strong&gt;: Show processes for all users.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;u&lt;/code&gt;&lt;/strong&gt;: Display the process&amp;rsquo;s user/owner and detailed info, eg. CPU, Memory.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;x&lt;/code&gt;&lt;/strong&gt;: Show processes not attached to a terminal TTY.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;w&lt;/code&gt;&lt;/strong&gt;: Wide output. Use twice (&lt;code&gt;-ww&lt;/code&gt;) for unlimited width.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;p&lt;/code&gt;&lt;/strong&gt;: Select by process ID PID.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="dash-style--ef"&gt;Dash Style (&lt;code&gt;-ef&lt;/code&gt;)&lt;a class="anchor" href="#dash-style--ef"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Standard UNIX options.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-e&lt;/code&gt;&lt;/strong&gt;: Select all processes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-f&lt;/code&gt;&lt;/strong&gt;: Full-format listing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-o&lt;/code&gt;&lt;/strong&gt;: User-defined format.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;comm&lt;/code&gt;: Command name only.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;args&lt;/code&gt;: Command with all its arguments.&lt;/li&gt;
&lt;li&gt;eg. &lt;code&gt;ps -ef -o pid,comm,args&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-w&lt;/code&gt;&lt;/strong&gt;: Wide output.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-ww&lt;/code&gt;&lt;/strong&gt;: Unlimited width.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-p&lt;/code&gt;&lt;/strong&gt;: Select by PID.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>pstree</title><link>/linux/cli/pstree/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/cli/pstree/</guid><description>&lt;h1 id="pstree"&gt;&lt;code&gt;pstree&lt;/code&gt;&lt;a class="anchor" href="#pstree"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-p&lt;/code&gt;&lt;/strong&gt;: Show PIDs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-a&lt;/code&gt;&lt;/strong&gt;: Show command line arguments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-h&lt;/code&gt;&lt;/strong&gt;: Highlight the current process and its ancestors.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;-u&lt;/code&gt;&lt;/strong&gt;: Show user transitions (when the user differs from the parent).&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Scripting Tips</title><link>/linux/shell/script-tips/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/shell/script-tips/</guid><description>&lt;h1 id="scripting-tips"&gt;Scripting Tips&lt;a class="anchor" href="#scripting-tips"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Best practices and useful tools for shell scripting.&lt;/p&gt;
&lt;h3 id="set--e"&gt;&lt;code&gt;set -e&lt;/code&gt;&lt;a class="anchor" href="#set--e"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Add &lt;code&gt;set -e&lt;/code&gt; at the beginning of your script to make it exit immediately if any command fails. This prevents error propagation.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#57606a"&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#6639ba"&gt;set&lt;/span&gt; -e&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="if-with-grep"&gt;&lt;code&gt;if&lt;/code&gt; with &lt;code&gt;grep&lt;/code&gt;&lt;a class="anchor" href="#if-with-grep"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Since &lt;a href="../../linux/cli/grep/"&gt;&lt;code&gt;grep&lt;/code&gt;&lt;/a&gt; returns an exit code of &lt;code&gt;0&lt;/code&gt; on success and &lt;code&gt;1&lt;/code&gt; on failure, it can be used directly in an &lt;code&gt;if&lt;/code&gt; condition. Use &lt;code&gt;-q, --quiet&lt;/code&gt; to suppress output.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#cf222e"&gt;if&lt;/span&gt; grep -q &lt;span style="color:#0a3069"&gt;&amp;#34;pattern&amp;#34;&lt;/span&gt; &amp;lt;file&amp;gt;&lt;span style="color:#1f2328"&gt;;&lt;/span&gt; &lt;span style="color:#cf222e"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#6639ba"&gt;echo&lt;/span&gt; &lt;span style="color:#0a3069"&gt;&amp;#34;Pattern found&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#cf222e"&gt;fi&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="other-useful-tools"&gt;Other Useful Tools&lt;a class="anchor" href="#other-useful-tools"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="../../linux/cli/trap/"&gt;&lt;code&gt;trap&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="../../linux/cli/awk/"&gt;&lt;code&gt;awk&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="../../linux/cli/xargs/"&gt;&lt;code&gt;xargs&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>set -o vi</title><link>/linux/shell/bash-vi-mode/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/shell/bash-vi-mode/</guid><description>&lt;h1 id="set--o-vi"&gt;&lt;code&gt;set -o vi&lt;/code&gt;&lt;a class="anchor" href="#set--o-vi"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;You can use &lt;code&gt;vim&lt;/code&gt; keybindings in Bash to edit commands.&lt;/p&gt;
&lt;h3 id="configuration"&gt;Configuration&lt;a class="anchor" href="#configuration"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Add the following to your &lt;code&gt;~/.bashrc&lt;/code&gt; file:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#6639ba"&gt;set&lt;/span&gt; -o vi&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="motivation"&gt;Motivation&lt;a class="anchor" href="#motivation"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;For &lt;code&gt;vi&lt;/code&gt; users, leveraging editor muscle memory with commands like &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;dB&lt;/code&gt;, &lt;code&gt;w&lt;/code&gt;, and &lt;code&gt;b&lt;/code&gt; is more intuitive than memorizing shell-native shortcuts like &lt;code&gt;Ctrl+h&lt;/code&gt;, &lt;code&gt;Ctrl+w&lt;/code&gt;, &lt;code&gt;Alt+f&lt;/code&gt;, and &lt;code&gt;Alt+b&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="key-features-and-tips"&gt;Key Features and Tips&lt;a class="anchor" href="#key-features-and-tips"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Movement:&lt;/strong&gt; Supports &lt;code&gt;w&lt;/code&gt;, &lt;code&gt;W&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;B&lt;/code&gt; (words) and &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;F&lt;/code&gt;, &lt;code&gt;t&lt;/code&gt;, &lt;code&gt;T&lt;/code&gt; (character search).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;History Search:&lt;/strong&gt; In Normal mode, press &lt;code&gt;/&lt;/code&gt; to search your command history.
&lt;ul&gt;
&lt;li&gt;eg. Typing &lt;code&gt;/^kubectl&lt;/code&gt; finds recent &lt;code&gt;kubectl&lt;/code&gt; commands. Use &lt;code&gt;n&lt;/code&gt; and &lt;code&gt;N&lt;/code&gt; to navigate results.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Open in Editor (&lt;code&gt;v&lt;/code&gt;):&lt;/strong&gt; Pressing &lt;code&gt;v&lt;/code&gt; in Normal mode opens the current command in the editor defined by &lt;code&gt;&amp;lt;editor&amp;gt;&lt;/code&gt; (eg. &lt;code&gt;vim&lt;/code&gt;). Saving and exiting (&lt;code&gt;:wq&lt;/code&gt;) will execute the command immediately. This is extremely useful for complex multi-line or long commands.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="limitations"&gt;Limitations&lt;a class="anchor" href="#limitations"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;In-line search using &lt;code&gt;/&lt;/code&gt; is not supported (it is mapped to history search); use &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;t&lt;/code&gt;, etc., instead.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Shell Processing Order</title><link>/linux/shell/process-order/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/shell/process-order/</guid><description>&lt;h1 id="shell-processing-order"&gt;Shell Processing Order&lt;a class="anchor" href="#shell-processing-order"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;The logical sequence Bash follows when processing a command.&lt;/p&gt;
&lt;h3 id="tokenization"&gt;Tokenization&lt;a class="anchor" href="#tokenization"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The shell reads the input and breaks it into tokens based on metacharacters.&lt;/p&gt;
&lt;h3 id="alias-expansion"&gt;Alias Expansion&lt;a class="anchor" href="#alias-expansion"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Checks if the first word of the command is an alias and replaces it.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Bypassing Aliases:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;\COMMAND&lt;/code&gt;: Using a backslash (eg. &lt;code&gt;\ls&lt;/code&gt;) bypasses aliases.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;command COMMAND&lt;/code&gt;: Using the &lt;code&gt;command&lt;/code&gt; built-in bypasses both aliases and shell functions, ensuring the system binary or built-in is executed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="expansion"&gt;Expansion&lt;a class="anchor" href="#expansion"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Expansions are performed in the following order:&lt;/p&gt;</description></item><item><title>trap</title><link>/linux/cli/trap/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/cli/trap/</guid><description>&lt;h1 id="trap"&gt;&lt;code&gt;trap&lt;/code&gt;&lt;a class="anchor" href="#trap"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h3 id="usage"&gt;Usage&lt;a class="anchor" href="#usage"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Use &lt;code&gt;trap&lt;/code&gt; to clean up temporary files or resources when a script receives a signal.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#953800"&gt;TMPFILE1&lt;/span&gt;&lt;span style="color:#0550ae"&gt;=&lt;/span&gt;&lt;span style="color:#cf222e"&gt;$(&lt;/span&gt;mktemp /tmp/im1.XXXXXX&lt;span style="color:#cf222e"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#953800"&gt;TMPFILE2&lt;/span&gt;&lt;span style="color:#0550ae"&gt;=&lt;/span&gt;&lt;span style="color:#cf222e"&gt;$(&lt;/span&gt;mktemp /tmp/im2.XXXXXX&lt;span style="color:#cf222e"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#57606a"&gt;# Delete temp files on interrupt (`Ctrl+C`)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#6639ba"&gt;trap&lt;/span&gt; &lt;span style="color:#0a3069"&gt;&amp;#34;rm -f &lt;/span&gt;&lt;span style="color:#953800"&gt;$TMPFILE1&lt;/span&gt;&lt;span style="color:#0a3069"&gt; &lt;/span&gt;&lt;span style="color:#953800"&gt;$TMPFILE2&lt;/span&gt;&lt;span style="color:#0a3069"&gt;; exit 1&amp;#34;&lt;/span&gt; INT&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="signals"&gt;Signals&lt;a class="anchor" href="#signals"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Use &lt;code&gt;kill -l&lt;/code&gt; to see a list of all available signals on your system.&lt;/p&gt;</description></item><item><title>What are Interactive and Login Shells?</title><link>/linux/shell/interactive-login/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/shell/interactive-login/</guid><description>&lt;h1 id="what-are-interactive-and-login-shells"&gt;What are Interactive and Login Shells?&lt;a class="anchor" href="#what-are-interactive-and-login-shells"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Shell types are categorized by two orthogonal dimensions: &lt;strong&gt;Interactive&lt;/strong&gt; and &lt;strong&gt;Login&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id="1-technical-definitions"&gt;1. Technical Definitions&lt;a class="anchor" href="#1-technical-definitions"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="11-interactive-shell"&gt;1.1 Interactive Shell&lt;a class="anchor" href="#11-interactive-shell"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A shell is technically considered &lt;strong&gt;Interactive&lt;/strong&gt; if:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It is started without non-option arguments (unless &lt;code&gt;-s&lt;/code&gt; is specified) and without the &lt;code&gt;-c&lt;/code&gt; option, and both its &lt;strong&gt;standard input&lt;/strong&gt; and &lt;strong&gt;standard error&lt;/strong&gt; are connected to terminals (as determined by &lt;code&gt;isatty(3)&lt;/code&gt;). &lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
&lt;li&gt;It is explicitly started with the &lt;code&gt;-i&lt;/code&gt; flag.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Verification:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>xargs</title><link>/linux/cli/xargs/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>/linux/cli/xargs/</guid><description>&lt;h1 id="xargs"&gt;&lt;code&gt;xargs&lt;/code&gt;&lt;a class="anchor" href="#xargs"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h3 id="xargs-with-"&gt;&lt;code&gt;xargs&lt;/code&gt; with &lt;code&gt;{}&lt;/code&gt;&lt;a class="anchor" href="#xargs-with-"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Use &lt;code&gt;-I {}&lt;/code&gt; to define a placeholder (&lt;code&gt;{}&lt;/code&gt;) for the input, allowing you to place the argument anywhere in the command.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#57606a"&gt;# Rename all .txt files to .bak&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ls *.txt &lt;span style="color:#1f2328"&gt;|&lt;/span&gt; xargs -I &lt;span style="color:#0550ae"&gt;{}&lt;/span&gt; mv &lt;span style="color:#0550ae"&gt;{}&lt;/span&gt; &lt;span style="color:#0550ae"&gt;{}&lt;/span&gt;.bak&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Double Quote Expansion</title><link>/linux/shell/shell-expansion/</link><pubDate>Fri, 22 May 2026 00:00:00 +0000</pubDate><guid>/linux/shell/shell-expansion/</guid><description>&lt;h1 id="double-quote-expansion"&gt;Double Quote Expansion&lt;a class="anchor" href="#double-quote-expansion"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Characters that still undergo shell expansion inside double quotes (&lt;code&gt;&amp;quot; &amp;quot;&lt;/code&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;$&lt;/code&gt;&lt;/strong&gt; (Variable/Command expansion)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;`&lt;/code&gt;&lt;/strong&gt; (Command substitution)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;\&lt;/code&gt;&lt;/strong&gt; (Escape character)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;!&lt;/code&gt;&lt;/strong&gt; (History expansion)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Use single quotes (&lt;code&gt;' '&lt;/code&gt;) to suppress all expansion.&lt;/p&gt;</description></item></channel></rss>