Mastering Essential Shell Tricks: Pipes, Redirection, and Find Commands
This article explains three crucial shell constructs—pipes, redirection operators, and backslash usage—showing how to combine commands, direct output to files, and pass command results as arguments, with practical examples and a script for archiving recently modified files.
Pipe “|”
Use a pipe to feed the output of one command as the input of another.
Example: grep "hello" file.txt | wc -l This searches for lines containing “hello” in file.txt and counts them; the output of grep becomes the input of wc.
Redirection
Redirect command output to a file instead of the standard screen.
Common symbols: > writes to a file, overwriting it. >> appends to a file, preserving existing content.
Backslash (Escape)
Using a backslash allows the output of a command to be used as an argument for another command.
Command example: find . -mtime -1 -type f -print This finds files modified in the last 24 hours. To archive the found files you can use:
#!/bin/sh
tar -zcvf lastmod.tar.gz `find . -mtime -1 -type f -print`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.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
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.
