Free tools Windows power users keep installed

One-click scans. No signup required.

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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Three small Linux commands can solve everyday terminal problems without a script: shuf randomizes lines or picks a sample, timeout puts a time limit on a command, and tee saves output while letting it continue through a pipeline. These examples describe GNU Coreutils behavior; availability and details can vary with your distribution, installed package, and version.

1. Use shuf to mix lines or pick a sample

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

shuf -n 3 names.txt

This prints three randomly selected lines from names.txt. It is handy for a casual choice or a quick sample from a list. GNU Coreutils 9.11 also accepts explicit values with -e and can generate a range with -i:

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.
shuf -i 1-10

To choose five values from a short list while allowing repeats, use replacement mode, -r:

shuf -r -n 5 -e red blue green

Without -r, the output is a permutation of the supplied values, so a value will not appear more times than it appears in the input. These are ordinary randomization conveniences, not a basis for security decisions or a cryptographic lottery. See the GNU Coreutils 9.11 shuf documentation.

2. Use timeout to bound a command’s run time

Put a duration before a command to have GNU timeout signal it when that interval expires:

timeout 10s some-command

GNU Coreutils 9.10 uses TERM by default. A timeout normally returns status 124; scripts can use that status to distinguish a timeout from many other outcomes. The command’s actual stopping time can depend on system conditions and how it responds to the signal, so this is not a guarantee of instantaneous cleanup.

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

GNU timeout also supports alternate signals, a kill-after interval, and --preserve-status. In foreground mode it does not time out children of the managed process. Consider the process tree and signal-handling behavior when using it to contain work that may launch other processes. See the GNU Coreutils 9.10 timeout documentation.

3. Use tee to save output as it flows

tee copies standard input both to standard output and to one or more files. This lets you watch a command’s output while saving it:

make 2>&1 | tee build.log

Here, 2>&1 sends standard error to the same place as standard output before the pipe, so both streams reach tee. The output remains visible in the terminal and is written to build.log. By default, an existing file with that name is overwritten. Add -a to append instead:

make 2>&1 | tee -a build.log

One scripting detail: in some shells, a pipeline’s reported status reflects only its last command, which can hide a failure from the command before tee. In Bash, enable pipefail when you want the pipeline to report an earlier failure:

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

That behavior belongs to the shell’s pipeline status rules, 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

Remember the job, not just the spelling

  • shuf: shuffle input lines or take a limited random sample.
  • timeout: give a command a time limit and signal it when the limit expires.
  • tee: save a stream to a file while forwarding it onward or to the terminal.

For short command examples to keep nearby, tldr-pages offers community-maintained practical summaries alongside fuller references such as 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.