Quick Reference

This page collects commands we have (or will) discuss throughout the course. Click on a command for more details on its operation and some examples of common or useful operations. We encourage students to contribute to this page through the advanced homework on git and open source contributions.



alias is a command to create shortcut to commands and applications in the terminal.

$ alias l="ls"
$ l
Documents  Downloads  Music     Public     Videos
Desktop    Pictures   Templates


cat is a command that concatenates files and prints the concatenated files to the standard output.

$ echo "This is an:" > beginning.txt
$ echo "example" > end.txt
$ cat beginning.txt end.txt
This is an:


cd is used to change directory. Unlike most commands, cd is not a separate program, it is a shell built-in. cd is a useful tool to navigate up and down the hierarchy of the file systems on your machine, and move into a given directory.

$ cd ~
$ cd /home


Changes the permissions of a file or directory. Stands for change file mode bits

$ ls -go --time-style=+
total 40
-rw-r--r-- 1 37465  index.html
$ chmod 666 index.html
$ ls -go --time-style=+
total 40
-rw-rw-rw- 1 74981  index.html


chown/chgrp changes the user that owns the file or the group that owns the file.

$ ls -l file
-rw-r--r--  1 ppannuto  ... file
$ sudo chown root file
$ ls -l file
-rw-r--r--  1 root      ... file


cp is used to copy files or directories.

$ cp source destination
$ cp file1.txt file2.txt
$ cp -b file1.txt file2.txt
$ cp -v file1.txt file2.txt
$ cp * ~/Desktop


This command can get you the system time in terminal.

$ date
Thu Mar 24 15:09:46 EDT 2016


df (abbreviation for disk free) is used to display the amount of availbale disk space for file systems on which the invoking user has appropriate read access.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            982M     0  982M   0% /dev
tmpfs           201M   22M  179M  11% /run
/dev/sda1        48G  4.9G   41G  11% /
...(Some more info)

dot (.)

A full stop can be synonymous for source in a shell, can reference a relative directory path, or indicate a hidden file.


The du (disk usage) command shows you the sizes of directory trees including all of their contents and sizes of individual files. This makes it usefull for taking down particular directories that are hogging disk space.

$ mkdir test
$ yes > test/bigfile.txt
$ du -h
51M    ./test
51M    .


echo is used to output whatever it is given into stdout. Often useful see the value of environment variables.

$ echo "Hello World!"
Hello World!
$ echo $USER
<your username>


expand a command that convert tabs to spaces.

$ expand [OPTION] [FILE]

gcc flags

gcc is a compiler command that has the ability to execute options or ‘Flags’ when compiling. These flags can be grouped and executed via the command line:

-o places output in a filename of your choice. If you do not use the -o flag the output file will have the name and extention: ‘a.out’.

-g turns on debugging information.

-Werror makes all warnings into errors.

-Wall enables all the warnings.

-O enables optimization.

NOTE: See below for details.

$ gcc test.c -o test
$ gcc -g test.c
$ gcc -Werror -Wall -O test.c


gzip reduces the size of the name files by compressing a file. It will only attempt to compress regular files. Compressed files can be restored to their original form using gzip -d or gunzip or zcat.

$ gzip archivefile.txt


hash is used to maintain a hash table of full pathnames of recently executed programs. A full search of the directories in PATH is performed only if the command is not found in the hash table.

$ hash
  hits	command
   4	/bin/nano
   3	/usr/local/bin/bundle
   1	/usr/bin/pip
   3	/usr/bin/git
   2	/usr/bin/factor
   5	/usr/bin/sudo
  11	/bin/ls
   1	/usr/bin/figlet
   3	/usr/bin/python

head prints the first 10 lines of a file to the standard output. If more than one file is specified, head will print the filename first and then print the first ten lines of the file. Since a good programmer will always put comments at the beginning of a file, printing the first few lines of a file can help us identify what is in the file.

$ head [options] ... [file] ...


history is used to list command history. By default, history will print the last 500 commands typed into the terminal.

$ history
  498  third_most_recent_command
  499  second_most_recent_command
  500  most_recent_command
  501  history


id: id is used to get information about a user’s UID (user ID), the groups a user belongs to, groups associated with the user, and security context of the current user. The default id command shows the user and groups names and numeric ID’s. Use id with options to find more useful information.

$ id -G username
203 403 94 32 93


join is used to combine two files based on matching content in each file.

$ cat a.txt
1 h
2 t
3 e
4 a
$ cat b.txt
1 i
2 o
3 h
4 h
$ join a.txt b.txt
1 h i
2 t o
3 e h
4 a h


kill is used to send signal to a process or to kill a process. We typically use kill PID, where you know the PID of the process. By default kill generates SIGTERM, to safely end a process.

$ kill 7243


ln is used to create a link (symbolic or hard) to a file on disk. Default creates hard links.

$ ln file1.txt file2.txt
$ ln -s file1.txt file2.txt


locate finds the locations of directories and files on Linux as well as other Unix-like OS.

$ locate hello.cpp


ls is used to list the contents of a directory. By default, ls will simply print file names.

$ ls
directory file


man allows users to format/display the user “manual” that is built into Linux. This manual holds a catalogue of commands and other aspects of the Linux OS.

$ man [command]
$ man ls
$ man strcmp


mkdir is used to create directories (if they do not already exist) on a file system.

The general format is

$ mkdir [options] directories


The more command displays the file called name in the screen. The RETURN key displays the next line of the file. The spacebar displays the next screen of the file.

The syntax is:

$ more [options] [files]


mv is used to move a source file or directory into a destination directory. It is also commonly used to rename files.

$ mv source desination


nl is a command that numbers the lines of files and prints the result to the standard output.

$ echo "This is an:" > beginning.txt
$ echo "example" > end.txt
$ nl beginning.txt end.txt
   1	This is an:
   2	example


passwd is a command that is used to change the password of system users.

$ passwd
Changing password for user [current user]
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully


pwd stands for print working directory. pwd outputs the full pathname of the current work directory.

$ pwd

pwd can also be used to store the full path to the current directory.



rm is used to delete one or multiple files from your current directory. Be careful when using because this does not move the item to trash, it permanetly deletes it.

$ rm file1.txt file2.txt


rmdir is used to remove empty directories.

The format is

$ rmdir [options] directories


rsync is file copying tool. It can be used locally or to and from a host. It is most commonly used to copy only the changes made to a file.

$ rsync dir1/file dir2/


seqprints a sequence of numbers to standard ouput.

$ seq [options]... [*FIRST* [*STEP*]] *LAST*... 


sleep is a Unix command used to suspend program execution for a specified period of time. The default unit is seconds, but minutes, hours, or days may also be specified.

$ sleep 10


sort is used to sort a file or input.

$ cat letters.txt
$ sort letters.txt


su (substitute user) is a command to change a login session’s owner without the owner having to first log out of the session. (as specified in the su Command). In other words, it is called the switch user command

Note: It is most commonly employed to change the ownership from an ordinary user to the administrative user. Therefore it is often refered as the superuser command.

$sudo su root


sudo (super user do) is a command that allows a permitted user to execute a command as a superuser or another user (as specified in the sudoers file). In other words, it runs the command with elevated privileges.

Note: The root user has permission to do anything on your system; acting as root can be dangerous! That is why it’s best practice to only use sudo when you need it, and to double check the command before running.

$ sudo apt-get install wbritish


Tail displays the last part(s) of a file

$ tail input.txt
$ tail -f -n 15 input.txt


tar is a command that is used to store and extract files from a tape or disk archive. The tar command which stands for tape archive simply archives a collection of files into one single file usually refered to as the tarball.

$ tar -cf tarball.tar file1 file2


top displays information on your Linux system, running processes, and system resources, including the CPU, RAM, swap usage, and total number of tasks being run:

$ top


true a command that returns the logical value of truth, which is 0.

#!/usr/bin/env bash
# The value of $? is the exit status code of the last program/command to run
$ true
$ echo $?
$ false 
$ echo $?


uniq is used to filter consecutive repeated lines from a file or input. The first line of each consecutive group of repeated lines is retained. Repeated lines that are not consecutive are treated as unique instances and will not be filtered.

$ cat numbers.txt
$ uniq numbers.txt


This command shows the current time followed by your computer’s uptime.

$ uptime
3:03 up 1 day, 6 hrs, 2 users, load averages: 1.38 1.43 1.42


Print the number of bytes, words, and lines in files

$ cat a.txt 
I love EECS 398.
What a great class. 

$ wc [filename] 
$ wc a.txt
3 9 44 a.txt


whereis is used to locate source/binary and manuals sections for specified files. The supplied names are first stripped of leading pathname components and any (single) trailing extension of the form .ext.

$ whereis [options] filename


which is used to show the full path for each of the executables that you give it. Since command-line commands are also executables, which is usually used to find full paths to shell commands. By default, which will only give the first full path found for the given executable.

$  which ls


who is a command that shows which users are currently logged on the machine.

$ who
alice    pts/0        2016-03-19 20:52 (:0)
bob      pts/1        2016-03-18 09:00 (:0)
mallory  pts/4        2016-03-19 22:48 (


whoami is used to print the current userid. Permissions for commands will be run with the level of permissions of userid.

$ whoami






apropos allows you to quickly figure which commands lead to the actions you want to perform

$ apropos "list directory"
dir (1) - list directory contents
ls (1) - list directory contents
ntfsls (8) - list directory contents on an NTFS filesystem
vdir (1) - list directory contents


curl is used to transfer data from one server to another using a supported protocol such as HTTP or HTTPS

$ curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.


dd is a utility that can be used to convert and copy files in a number of ways. This can be used for backing up/restoring entire hard drives or partions, converting data formats, converting the case of a file, and more.

Warning: dd is often referred to by many as 'disk destroyer' or 'data deleter' due to its potential to erase large chunks of data when used improperly. If you plan on testing any of these commands exercise extreme caution to avoid losing any significant data.
$ dd if=[inputFile] of=[outputFile] [options]
0+1 records in
0+1 records out
6 bytes copied, 0.000101046 s, 59.4 kB/s


diff is a tool used to compare files line by line.

$ diff [option]... [file1] [file2] 


factor is used to list all prime factors of each integer number.

$ factor [NUMBER]...


ffmpeg is a command line tool that is used for converting and editing audio and video files.

$ ffmpeg -i sample.avi sample.mp4


file is used to find out the type of a file

$ file file.md
file.md: ASCII text


find is used to find items matching certain specified criteria in a given directory tree.

$ find ~/ -name "foo" -print


Git is a version control system that can be used for collaboration


grep is used to search files for the occurrence os string of characters matching a string (egrep can support called regular expressions often abbreviated as regex).

$ grep string file
matches because it has string in it


ifconfig is used to configure a network interface or display information about all active or inactive connections.

Warning: While ifconfig is still used, it is recommended to use iproute2 (Linux) or iproute2mac [See reference on 'ip']. ip is a much more powerful tool that can do everything ifconfig can do, and lots more.


ip is a powerful networking tool that when simply used will display information on kernel-resident interfaces. Much like ifconfig, it can turn devices on/off and set IP and MAC addresses. ip also wraps popular commands like netstat, ndp, arp, and route into its functionality.

# Close the first ethernet connection 
$ ip link set dev eth0 down


less is used to display contents of a file, as well as allow navigation. Its name is derived from being the opposite of more.

$ less file.txt

These are the contents of "file.txt".

The output will actually take up the entire screen, and you can navigate using Vim-like commands.


Simply put, this command can compile code into an executable without having to type a super long compilation sequence. We can use the make utility to automate many tasks in the development process, including compilation and regression testing.

$ make main
c++     main.cpp   -o main
$ ./main


nslookup, which stands for “name server lookup”, is used to query internet name servers interactively. By default, nslookup tranlsates a domain name to an IP address, or vice versa.

nslookup www.google.com


TODO: Claim the issue for this command and add documentation for this command by submitting a pull request.

*short* example of command usage and output


ping is used to test a connection to a network. You can use ping to check if your local machine can connect to a network or if a particular device is reachable from your machine. A ping may fail to reach a device if either device is blocked by a firewall.

$ ping
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=255 time=1.518 ms


ps provides a snapshot of current processes

#Shows four items of information for each process currently under the current user and from this terminal
#PID: Process ID
#TTY: Terminal Type (name of console that user logged into)
#TIME: System time used on process
#CMD: Name of command that launched process
  PID TTY          TIME CMD
 1612 pts/17   00:00:00 bash
25671 pts/17   00:00:07 gedit
26195 pts/17   00:00:00 ps


Rev reverses the lines of a file. This utility will copy the files specified in the command to standard output while reversing the order of each of the characters in every line. If no files are specified, it will use standard input and read in lines.

The general format is:

$ rev [file...]


scp is used to make a secure copy of files or directories to and from a remote host. Similar to “cp” except either the source or destination should be a remote host. scp uses secure shell protocol (ssh) to tranfer the file to or from the server.

$ scp source user@host:destination
$ scp user@host:source destination


sed is used to make replacements in text files using regular expressions. It searches for regex matches and executes the provided replacement at all instances.

$ sed <options> string file


sftp is short for SSH File Transfer Protocol, also known as Secure File Transfer Protocol, enables secure file transfer capabilities between networked hosts. Unlike the scp, sftp additionally provides remote file system management functionality, allowing applications to resume interrupted file transfers, list the contents of remote directories, and delete remote files.

Useful Options / Examples

We can establish an SSH connection and then open up an SFTP session using that connection by issuing the following command:

$ sftp username@remote_hostname_or_IP


sshfs is used to mount a remote ssh server to a local mountpoint to allow the secure transfer of files or directories to and from a remote host. Similar to “scp” except instead of having to manually transfer the files from the command line, files can be simply “mv” or “cp” into a folder. sshfs uses the secure shell protocol (ssh) to transfer the file to or from the server and the “FUSE” libraries to produce the mountpoint.

$ sshfs mnt_pnt user@host:dest_folder


TODO: Claim the issue for this command and add documentation for this command by submitting a pull request.

*short* example of command usage and output


tac concatenates each file or command line input to standard output in reverse (hence tac = cat in reverse).

$ tac filename


tcpdump is a tool that allows you to view a dump of traffic on a network. By default, tcpdump will let you view the dump on your local network. You can use packet analyzing tools like Wireshark to analyze tcpdumps and pcap files.

$ tcpdump 


telnet is used to communicate with another host using the TELNET protocol.

$ telnet


time prints out the total time elapsed, the time used by system overhead and the time used to execute the utility.


tmux is a terminal multiplexer. It allows the user to access separate terminal sessions inside a single terminal window. tmux is especially useful in remote access.

$ tmux


touch is used to create new, empty files or update the timestamp of an existing file.

$ touch newFile.txt


tr is used to translate the characters given as input into new characters based on flags and strings given as input.

$ tr 'is' 'at'


units gives conversion rates from one scale to another.

$ units [-f unitsfile] [-q] [-v] [from-unit to-unit]...


wget is a tool for downloading files using HTTP, HTTPS, or FTP using the command line.

$ wget https://c4cs.github.io/hw/c4cs-wk9-advanced.pdf


xclip can put the output of a command into the X-clipborad if we pipe the command into xclip.

ls -la | xclip

xclip can also directly copy the content of the following file:

xclip SomeOtherFile.txt

xclip -o can print the stuff in X-clipboard.

xclip -o > output.txt

If you’re on a Mac the equivalent command is pbcopy.