Unique and Lesser-Known Bash Script Tricks
Command Line Hacks for Power Users
Some unique and lesser-known Bash tricks that can enhance your scripting and command-line experience.
So open your terminal and type these commands.
(The Bash tricks I shared are specific to the Bash shell, which is commonly used in Unix-like operating systems such as Linux and macOS)
Process Substitution with Named Pipes (<(...)
and >(...)
)
Process substitution allows you to use the output of a command as a temporary file. This is particularly useful when a command requires a filename as an argument.
diff <(sort file1.txt) <(sort file2.txt)
This compares the sorted versions of two files without creating intermediate files.
Using /dev/tcp
and /dev/udp
for Network Communications
Bash can perform TCP and UDP network operations without external utilities.
# Check if a port is open
timeout 1 bash -c "</dev/tcp/google.com/80" && echo "Open" || echo "Closed"
This attempts to open a TCP connection to google.com
on port 80
.
Recursive Globbing with globstar
(**
)