Quick Reference

Console tips

Readline tab completion

Readline history up/down arrows

Control-c to send SIGINT

Control-d to send EOT/EOF

Paths

/

The root directory (top of the hierarchical filesystem).

~

Your own home directory, which is space set aside for your personal files.

.

A special child listed in every directory that refers to itself. That is, path/. is the same as path, and just . refers to the working directory.

..

A special child listed in every directory that refers to its parent. That is, path/child/.. is the same as path, and just .. refers to the directory above the working directory.

Absolute path

A path that starts with a /, such as /usr/local/bin, starts from the root directory.

Relative path

A path that doesn’t start with /, such as input.txt or source/main.c, starts from the working directory.

Working with files and directories

mkdir path

Make a new directory named path.

rmdir path

Remove a directory named path, but only if it is empty.

rm path

Remove a regular file named path. There is no trash; the deleted file cannot be easily recovered.

rm -r path

Remove a directory named path, and all of its contents recursively. There is no trash; the deleted files cannot be easily recovered.

rm -f path

Remove path by force, i.e. do not complain if the file is read-only or already doesn’t exist. There is even less protection than a normal rm.

mv source dest

Move/rename source to dest. The source can be a directory or a file, it doesn’t matter.

cp source dest

Make a copy of regular file source named dest.

cp -r source dest

Make a copy of directory source named dest, copying all of its contents over recursively.

For cp and mv, if dest is a directory that already exists, the source will be copied or moved into that directory without changing its name, i.e. it is as though you had specified dest/source.

Synchronizing files with a server

rsync -a path user@server:

Copy path (recursively if path is a directory) into user’s home directory on server.

rsync -a user@server:path .

Copy path on server into the local working directory. If path is relative, start from user’s home directory.

Following a git repository

git clone url

Get your own copy of the repository from the given url, creating a new directory named after the repository to hold its contents.

git pull

Run within your clone of a repository, to download and incorporate any updates from the original.

Working with programs

running bare command to find in PATH

running with absolute path

running with relative path e.g. ./

gcc -g -Wall -o program name.c

gcc -c -g -Wall -o name.o name.c

gcc -g -o program objects

make

make target

e.g. clean

Working with archives

tar czf name.tar.gz path

Create a compressed archive of path. The archive will be named name.tar.gz.

tar tzf name.tar.gz

List the contents of the archive name.tar.gz. This is a good way to see what is in an archive without extracting anything.

tar xzf name.tar.gz

Extract the contents of the archive name.tar.gz.

RTFM

man page

Read the specified page of the manual, i.e. man ls to learn more about the options to ls, or man man to learn more about how to read the manual.

man section page

Read the specified page of the manual in a particular section. The sections help disambiguate documentation for things with the same name; for example, man 1 printf shows the page for the shell command named printf, whereas man 3 printf shows the page for the C standard library function named printf.

whatis page

List all of the manual pages named page, with their section numbers and short descriptions. For example, if you try to look up information on the C standard library function printf and are surprised to get the manual page for the shell command named printf, you can run whatis printf to see a list of all the pages with that name and figure out which one you want.

apropos query

Print the manual for pages that are relevant to query, by searching their titles and short descriptions for matching text.

You have attempted of activities on this page