Command-line cheat sheet¶
This page lists the most common commands in the Ubuntu command line.
For full details on any command, run man <command> in your terminal.
CLI basics¶
More detailed explanation of the commands in this section can be found in our Welcome to the terminal tutorial.
Working with the filesystem¶
Working with files¶
Command |
Description |
Online manual page |
|---|---|---|
|
Create a new (empty) file, or update the timestamp of an existing file |
|
|
Copy a file from a source ( |
|
|
Copy a directory recursively, preserving permissions |
|
|
Rename a file or directory |
|
|
Move a file without renaming it |
|
|
Remove a file |
|
|
Remove a non-empty directory and all its contents |
|
|
Print the contents of |
|
|
View file contents one page at a time |
|
|
Print the first 20 lines of a file (default with no flag is 10) |
|
|
Print the last 20 lines of a file (default with no flag is 10) |
|
|
Count the number of lines in a file |
Users, groups, and permissions¶
Command |
Description |
Online manual page |
|---|---|---|
|
Change file permissions (symbolic or numeric notation) |
|
|
Change file owner and group |
|
|
Show or set the default permissions mask |
|
|
Run a command with administrator privileges |
Searching¶
Command |
Description |
Online manual page |
|---|---|---|
|
Search for lines matching a pattern in a file |
|
|
Look up a user account |
|
|
Look up group membership |
|
|
Search for files matching a name pattern |
|
|
Show the full path to an executable command |
|
|
Determine the type of a file |
CLI in depth¶
More detailed explanation of the commands and operators in this section can be found in our The command line in depth tutorial.
Redirecting input and output¶
Command |
Description |
|---|---|
|
Redirect stdout (1) to a file (overwrites existing content) |
|
Append stdout (1) to the end of |
|
Pass a file’s contents as stdin (0) to a command ( |
|
Discard stdout (1) entirely |
|
Redirect stderr (2) to a file |
|
Redirect both stdout (1) and stderr (2) to a file |
|
Here-document: feed multi-line text as stdin, ended by a line containing |
Pipes and command chaining¶
Command |
Description |
|---|---|
|
Pipe stdout (1) of |
|
Run commands in sequence regardless of exit status |
|
Run |
|
Run |
|
Run a command in the background |
|
Group commands and redirect their combined output |
|
Run commands in a subshell (side effects don’t affect the current shell) |
|
Continue a long command on the next line |
Variables and environment¶
Command |
Description |
Online manual page |
|---|---|---|
|
List all environment variables |
|
|
Print the value of variable |
See note below this table |
|
Set a shell variable (available in current shell only) |
|
|
Set a variable and export it to child processes |
|
|
Remove a variable |
|
|
Print the exit status of the last command ( |
|
|
Print the PID of the current shell |
Note
If you are using the bash, dash or zsh shell, echo is a builtin command documented under the shell manual page. For example, the bash builtin shell section. If your shell doesn’t have an echo builtin command, use the echo(1) manual page instead.
Shell expansion¶
Command |
Description |
|---|---|
|
Expands to the home directory ( |
|
Variable expansion: replaced by the value of |
|
Command substitution: replaced by the output of |
|
Arithmetic expansion: evaluates integer arithmetic, e.g. |
|
Brace expansion: generates separate words, e.g. |
|
Range expansion: generates a sequence, e.g. |
|
Glob: matches any sequence of characters in a filename |
|
Glob: matches any single character in a filename |
|
Glob: matches any one of the listed characters in a filename |
Getting help¶
Command |
Description |
Online manual page |
|---|---|---|
|
Open the manual page for a command |
|
|
Open the manual page for |
|
|
Search man page descriptions for a keyword |
|
|
Print a brief help summary for a command |