Fundamentals 3 min read

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.

Programmer DD
Programmer DD
Programmer DD
Mastering Essential Shell Tricks: Pipes, Redirection, and Find Commands

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`
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ShellUnixScriptingBashfindPipeRedirection
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.