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.

Working with the filesystem

Command

Description

mkdir <name>

Create a new directory

rmdir <name>

Remove an empty directory

tree

Display directory structure as a tree

tree -L <n> <path>

Display tree to depth n

Working with files

Command

Description

touch <file>

Create a new (empty) file, or update the timestamp of an existing file

cp <src> <dest>

Copy a file from a source (src) to a new destination (dest)

cp -a <src> <dest>

Copy a directory recursively, preserving permissions

mv <src> <dest>

Move or rename a file or directory

rm <file>

Remove a file

cat <file>

Print the contents of <file> to the screen

less <file>

View file contents one page at a time

head <file>

Print the first 10 lines of a file

tail <file>

Print the last 10 lines of a file

Users, groups, and permissions

Command

Description

chmod <mode> <file>

Change file permissions (symbolic or numeric notation)

chown <user>:<group> <file>

Change file owner and group

umask

Show or set the default permissions mask

sudo <command>

Run a command with administrator privileges

grep <name> /etc/passwd

Look up a user account

grep <name> /etc/group

Look up group membership

Searching

Command

Description

grep <pattern> <file>

Search for lines matching a pattern in a file

find <path> -name <pattern>

Search for files matching a name pattern

which <command>

Show the full path to an executable command

file <name>

Determine the type of a file

Getting help

Command

Description

man <command>

Open the manual page for a command

man man

Open the manual page for man itself

man -k <keyword>

Search man page descriptions for a keyword

<command> --help

Print a brief help summary for a command