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.

Basics

alias

alias instructs the shell to replace one string with another when executing commands.

$ alias rm='rm -i'
$ rm sample.txt
rm: remove regular empty file 'sample.txt'? Y
$ 

bg

bg resumes a stopped job in the background, so the terminal remains usable.

$ gedit file.txt
^Z
$ bg 'gedit file.txt'
$ jobs
[1]+ Running    gedit file.txt
$

cat

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:
example

cd

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

chmod

chmod (change mode) is the command to change permissions to system objects (files and directories).

$ chmod u+x filename

chown/chgrp

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

cp

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

date

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

df

df displays the amount of disk space available on the file system containing each file name argument.

$ df [OPTIONS] [FOLDER]

dot (.)

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

du

du, or disk usage, reports the sizes of directories, including of all of their contents and the sizes of individual files, and the sizes of each directory in the directory tree.

$ du [options] [directories and/or files]

echo

echo is used to display a message on the screen and write the given message to standard output with a newline at the end. echo is implemented as built-in command in many command shells like bash, ksh, csh.

$ echo "Hello World"
Hello World
$ echo Hello World
Hello World

expand

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

fg

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

gcc flags

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

gzip

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

hash

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

history

history is used to display the most recently used commands.

$ history [options]

id

id is a command that prints out the effective and real user and group ids.

The syntax for the command is:

id [option(s)]

jobs

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

join

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

kill

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

less

less is a tool to view a text file one screen at a time. You can navigate through the file with j or RETURN, and backwards with k

$ less hello.txt
# displays hello.txt
q # to quit

ln

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

locate

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

ls

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

$ ls
directory file

man

man provides manual pages for terminal commands

$ man git
# displays git man page
q # to quit

mkdir

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

The general format is

$ mkdir [options] directories

more

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

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

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

passwd

passwd is used to change the password of a user account

$ passwd [OPTION] [USER]

printf

printf is used to format and output data.

$ printf format [argument]
$ printf "%f\n" 7
7.000000
$ printf "%d\n " 0xF
15

pwd

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

$ pwd
/home/bo/Desktop

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

x=$(pwd)

rm

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

rmdir is used to remove empty directories.

The format is

$ rmdir [options] directories

rsync

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

seq

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

sleep

The sleep command makes your script, terminal, or anything else that is bash executable go to sleep for however long you specify

$ sleep 5s

sort

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

su

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

sudo

sudo allows a user to execute a command as a different user (with the default being the root user). sudo is useful when commands need to be performed with elevated privileges, such as installing system updates.

$    sudo apt-get update

tail

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

tar

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

top

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

true

true a statement that logically evaluates to true. It is often used to check whether statements evaluated succesfully or not. It is the logical inverse of ‘false’, also a unix command.

$ true
$ rm -rf directory || true

uniq

uniq, often used with sort, allows a user to report, or filter, repeated lines that are adjacent in a file.

$ sort in.txt | uniq 
line1
line2
line3

uptime

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

wc

wc prints newline, word, and byte counts for each FILE.

$ wc tecmint.txt
12  16 112 tecmint.txt

whereis

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

which

which returns the first matching command(s) in $PATH

$ which echo
/bin/echo

who

Displays list of all users currently logged on

$ who
Username console  Oct 12 08:20
Username ttys000  Oct 20 09:35

whoami

whoami prints the username of the current user when invoked

$ whoami
mmdarden

Tutorials

Shells

Scripting

Tools

apropos

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

asciinema

asciinema is a tool that allows you to record a terminal session with out having to use screen capture. It also allows for easy copy-pasting!

$ sudo apt-get install asciinema #install
$ asciinema rec #start session
$ your_commands_here
$ exit #exit session

cmp

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

curl

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

dc

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

dd

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

diff

diff is used to check for the differences between two files line by line. This is very useful for checking a programs output against a file containing its expected output.

$ printf "this\ndifference\n" > first.txt
$ printf "this\nsimilarity\n" > second.txt
$ diff first.txt second.txt
2c2
< difference
---
> similarity

factor

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

ffmpeg

ffmpeg is a multimedia framework used to record, convert, and stream audio and video.

# Convert between filetypes
$ ffmpeg -i input.mp4 output.avi

file

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

find

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

git

git is a version control tool allowing for easy collaboration on projects.

$ git clone https://github.com/c4cs/c4cs.github.io.git
$ cd c4cs.github.io
$ echo "Modified File" >> README.md
$ git add README.md
$ git commit -m "Added to README.md"
$ git push origin master

grep

grep is a program for searching text files for lines that match regular exprssions. It can be used for all sorts of pattern-matching and text-based query analysis.

$ grep -i crab animals.txt
Crab
Crab-Eating Macaque
Hermit Crab
Horseshoe Crab
King Crab

ifconfig

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

ip

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

make

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

nslookup

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

objdump

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

ping

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

ps

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

rev

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

scp

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

sed

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

sftp

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

sshfs

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

stat

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

tac

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

tcpdump

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

telnet

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

time

time outputs the runtime of a program that is given as an argument.

$ time cd

real 	0m0.008s
user 	0m0.008s
sys 	0m0.000s

tmux

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

touch

touch Creates a new empty file and can also change timestamps on existing files. Useful for creating empty files quickly.

$ touch main.cpp

tr

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

units

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

wget

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

xclip

TODO: Add documentation for this command by submitting a pull request.

*short* example of command usage and output

Editors

Toys

Ubuntu

Os_x