Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk2 min

3 Linux Commands You Can Learn in Seconds: shuf, timeout, and tee

Learn how shuf randomizes or samples lines, timeout limits a command's runtime, and tee saves output without stopping it from flowing.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Three small GNU Coreutils commands can make everyday terminal work easier: shuf randomizes lines or picks a sample, timeout limits how long a command runs, and tee saves output while passing it along. Their names and basic forms are easy to remember; just keep in mind that availability and details can vary with your Linux distribution and installed Coreutils version.

Use shuf to randomize lines or pick a sample

shuf outputs a random permutation of input lines. Add -n to limit how many lines it prints:

As an Amazon Associate I earn from qualifying purchases.

shuf -n 3 names.txt

This prints three randomly selected lines from names.txt. It is handy for a quick sample or casual randomized choice—not for a security decision or a high-stakes lottery.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can also provide values directly with -e, or ask for a range of numbers with -i:

shuf -i 1-10
shuf -e red blue green

By default, each supplied value appears at most once in the shuffled output. Add -r to sample with replacement, which means values can repeat:

shuf -r -n 5 -e red blue green

These examples follow the GNU Coreutils 9.11 shuf documentation.

Use timeout to put a limit on a command

When a command might take too long, prefix it with timeout and a duration:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
timeout 10s some-command

GNU Coreutils sends the command a TERM signal when the specified interval expires. A timeout normally returns exit status 124. The actual timing and cleanup depend on system conditions and on what the command starts; this is not a guarantee that every child process will be stopped immediately. GNU documents special behavior in foreground mode: it does not time out children of the managed process.

GNU Coreutils also supports alternate signals, a kill-after interval, and --preserve-status for cases where you need different signal or exit-status behavior. Check the GNU Coreutils 9.10 timeout documentation for the exact options and their effects.

Use tee to watch and save output

tee copies standard input both to standard output and to one or more files. That lets output remain visible in the terminal while a file captures it:

make 2>&1 | tee build.log

Here, 2>&1 sends standard error to standard output before the pipe, so both streams are sent through tee. By default, tee overwrites an existing output file. Use -a when you intend to append instead:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
make 2>&1 | tee -a build.log

In some shells, the pipeline’s exit status may reflect only its last command, masking a failure from the command before tee. For example, Bash supports set -o pipefail to make a pipeline return a failure status if a command in it fails. That behavior belongs to the shell, not to tee. See the GNU Coreutils 9.11 tee documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Where to check availability and syntax

These documented behaviors are for GNU Coreutils; an individual system may have a different implementation, version, or package installed. If a command is missing or an option behaves differently, consult your system’s manual page or installed package documentation rather than assuming every Linux distribution is identical.

For a quick refresher on common command syntax, the community-maintained tldr-pages website offers concise examples alongside fuller manual pages.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.