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

Online manual page

mkdir <name>

Create a new directory

mkdir(1)

rmdir <name>

Remove an empty directory

rmdir(1)

tree

Display directory structure as a tree

tree(1)

tree -L <n> <path>

Display tree to depth n

Working with files

Command

Description

Online manual page

touch <file>

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

touch(1)

cp <src> <dest>

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

cp(1)

cp -a <src> <dest>

Copy a directory recursively, preserving permissions

mv <src> <dest>

Rename a file or directory

mv(1)

mv <src>/file <dest>/file

Move a file without renaming it

rm <file>

Remove a file

rm(1)

rm -r <dir>

Remove a non-empty directory and all its contents

cat <file>

Print the contents of <file> to the screen

cat(1)

less <file>

View file contents one page at a time

less(1)

head -n 20 <file>

Print the first 20 lines of a file (default with no flag is 10)

head(1)

tail -n 20 <file>

Print the last 20 lines of a file (default with no flag is 10)

tail(1)

Users, groups, and permissions

Command

Description

Online manual page

chmod <mode> <file>

Change file permissions (symbolic or numeric notation)

chmod(1)

chown <user>:<group> <file>

Change file owner and group

chown(1)

umask

Show or set the default permissions mask

umask(2)

sudo <command>

Run a command with administrator privileges

sudo(8)

Searching

Command

Description

Online manual page

grep <pattern> <file>

Search for lines matching a pattern in a file

grep(1)

grep <name> /etc/passwd

Look up a user account

grep <name> /etc/group

Look up group membership

find <path> -name <pattern>

Search for files matching a name pattern

find(1)

which <command>

Show the full path to an executable command

which(1)

file <name>

Determine the type of a file

file(1)

Getting help

Command

Description

Online manual page

man <command>

Open the manual page for a command

man man

Open the manual page for man itself

man(1)

man -k <keyword>

Search man page descriptions for a keyword

<command> --help

Print a brief help summary for a command