Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

My big idea: Ancient Brain


CA216      CA249      CA318

CA400      CA651      CA668

Introduction to UNIX / Linux (More)

Some Commands to get started

Explore commands and options by typing "man (command)"
e.g. "man ps"


ls                      List files
ls -a                   Show "hidden" files (begin with ".")
ls -l                   Detailed
ls -alR                 Recursive

cat (file)              Type file out in command-line window

more (file)             Type file, pause for each screenful
                        enter for new line, space for next page, q to quit

cp                      Copy files
mv                      Move / Rename files
rm                      Remove files
mkdir                   Make directory
rmdir                   Remove directory

clear                   Clear screen


Detach program (&)

(prog) &                Launch a process detached 
                         from command-line (e.g. windowed)
(prog)                  Command-line frozen until prog exits.

eog file.jpg &		Launch image viewer Eye of GNOME on file

Web browsers

firefox &              Launch Web browser from command-line
firefox "URL" &
google-chrome &

konqueror "URL" & 


sort 		Sort alphabetically (pipe some stream into sort)
sort -n		Sort numerically
sort -r		Reverse sort 

sort by 5th column:
sort -k5
sort +4


grep                    Search for a string in a file or files
grep (string) (file)
grep -i (string) (file)

find                    Find files by name or date
find . -mtime -1        Files modified today

cal                     Calendar

cal 8 1752              Calendar for Aug 1752
cal 9 1752              Calendar for Sept 1752
cal 10 1752             Calendar for Oct 1752

lp (file)               Print
lpr (file)              Print (on some systems)
lp -Pl128 (file)        Print on printer l128 (L128)

lpq                     See print queue
lprm                    Remove job from queue

df -h                   Show space on all disks
df -k                   exact kilobytes

du                      Space used by me

w                       Who is logged in
           (see this when you ssh student.computing.dcu.ie)
(command) ; (command)   Multiple commands on same line


which (prog)            
 what runs if "prog" is typed
 may return nothing if prog is an alias

which ls

type (prog)
 returns path of prog
 or else shows what prog is alias for

type h
type history

whereis (prog)		Where the binary, source, manual pages are for this prog
whereis perl


Command-line HTTP client.

wget -q -O - URL      					  	Download URL, quiet, output to command-line
wget -q -O - URL > file.htm 					Output to file

wget -q -O file.htm  URL  					Output to file

wget -q -O - http://site/file.jpg  > file.jpg 		Output JPEG to file (output JPEG to command-line won't work)

wget -q -O file.jpg  http://site/file.jpg   		Output JPEG to file 

 see more on wget

wget appears in this hacking scene from the movie The Social Network (2010).
Perhaps the most realistic hacking scene in the history of movies.

Absolute and relative paths

Relative path of a file

What file that refers to depends on what directory you are in now.
It looks for index.html in the current directory.
is also relative path. It looks for index.html in the parent of the current directory.

Directory before Command Directory after
/users/gdf cd users/ec2 /users/gdf/users/ec2
/users/gdf cd ../ec2 /users/ec2
/users/gdf cd ec2 /users/gdf/ec2

Absolute path of a file

Gives the full "path" from the root down to the file.
Refers to the same file no matter what directory you are in.

Directory before Command Directory after
/users/gdf cd /users/ec2 /users/ec2

Case sensitivity

Case matters in filenames in UNIX (this is why case often matters on Web).

Question: Is case sensitivity a good thing? Or is it a flaw in UNIX?

Advantages of case sensitivity:

  1. More readable code. You know what to expect.
  2. More variables. num and NUM and Num
  3. Set up conventions, so that NUM probably refers to a compile-time-coded constant, num is a real-time-changing variable, etc.
  4. Quicker/simpler searches on file lists, since can just search for the literal string.
  5. Better to be case-sensitive for passwords. - Larger space to pick from. Harder to guess. Good to be "unforgiving" for security.
Not much return for such huge disadvantages:
  1. Millions of programmer and user hours lost on case not right.
  2. Millions of failed "404 Not Found" website hits because of wrong case in the URL.

Solutions to "404 Not Found" because of case:
  1. Set up program to handle 404. See My "404 Not Found" Handler
  2. Detach website URLs from underlying (case sensitive) file system.
    e.g. Content Management System.

Filenames and Special Characters

Long file names and multiple periods OK.
e.g. product.4652.suppliers.us.html


Avoid these chars

If the command-line is used to address files, it is best to avoid many special characters in filenames.

Avoid these chars in filenames, because they have meaning to the Unix command-line and utilities:

space (separate arguments)
# comment
< redirection
> redirection
` result of a program
| pipe
& detach process
; separate multiple commands on the same line

* wildcard
? wildcard
^ start of line
$ end of line / variable value
[ pattern matching
] pattern matching
\ "quoted" character
/ should be in pathname, not filename
' string delimiter
" string delimiter
! shell history

Stick to these chars

If you're going to use the command-line, best to just use these chars in filenames:


Use these inside filename only, not at start or end:

Feeds      w2mind.org      ancientbrain.com

On the Internet since 1987.