Bash Cheatsheet

Free Bash cheatsheet. Searchable reference for common Bash commands โ€” file operations, text processing, pipes, processes, and scripting basics.

Frequently asked questions

What is the difference between > and >> for redirection?

> redirects output to a file, overwriting whatever was there. >> redirects output to a file, appending to the end instead of overwriting it.

What does 2>&1 mean?

In Bash, file descriptor 1 is standard output (stdout) and 2 is standard error (stderr). 2>&1 redirects stderr into wherever stdout is currently pointing, so both end up combined in the same place โ€” commonly used as command > file 2>&1 to capture everything a command prints into one file.

What is a pipe, and how is it different from redirection?

A pipe (|) connects one command's output directly to another command's input, letting you chain tools together (e.g. cat file | grep error | wc -l). Redirection (>, <) connects a command's input or output to a file instead of another command.

How do I run a command in the background?

Add & to the end of a command to run it in the background and get your terminal prompt back immediately. Use jobs to see background jobs in the current session, or nohup command & if you need it to keep running after you close the terminal.