You are on page 1of 3

Key Function

Linux quick reference card Displays previous command in


command history (6.3)
Conventions
Optional command arguments are enclosed in square Displays next command
brackets [ ]. Multiple arguments are separated by * denotes a bash control-key sequence (6).
spaces unless otherwise stated. Command options
can sometimes be combined - see sect. 1 for
information on how to get details for specific 4 The File System
commands. Emphasised words are place holders for
real filenames etc. Section symbols () denote
4.1 Files
references to other sections in this card.
4.1.1 Filenames
Filenames may be chosen from any combination of
1 Help alphanumeric characters plus "-", " " and "." (other
characters such as control characters or spaces may be
Online help is available via the manual commands used but need to be "escaped" using the "\" character).
man and apropos Name of hidden file start with a dot.
In all commands, files may be referenced by their full
man command lists information on command path names or by a relative path name e.g. /
man -k keyword lists all commands referring to home/cs1/filename is a full path name (starts with a
keyword forward slash) but filename and ../mydir/filename are
apropos name search through the documentation, for relative path names (6.2).
exact matches or any item that somewhere contains
name
2 Work session 4.1.2 File management commands
2.1 Logging in cat [-n] f1 [ f2 ..] -- concatenates and lists entire files
[-n with line nos.]
In the SGI Laboratory. Type username:bioinfo
in the Login: text-box and your password in the more filename -- lists file a page at a time (within
Password: box. more, type ? for help, space bar for the next page, q to
On bioinfo server via ssh from unix station and via quit). (8).
putty from windows
ls -- lists files in current directory
2.2 Changing your password ls [ opts ] name -- lists file or directory name
The command passwd prompts for old/new Options: -F lists files appending "/" if a directory and
passwords. "*" if executable, -l gives information on size, owner,
permissions and modification time, -R recursively
2.3 Logging out lists directory, -a lists all files starting with ".".
logout or CTRL + D (3.1, 6.4)
login [username] -- logout and login user username mv f1 f2 -- renames f1 as f2
mv f1 [ .. fn] d1 -- moves f1 [ .. fn ] into directory
3 Keyboard d1 Renaming files to be the same as existing files is
prohibited if the noclobber variable is set (6.4).
3.1 Control Keys cp f1 f2 -- copies f1 to f2
cp [ -r ] f1 .. fn d1 -- [ recursively ] copies f1 ..fn into
The following control keys may be used to edit the directory d1
command line and to affect the behavior of running
programs. rm fname -- remove fname
Key Function rm -r dname -- recursively remove dname (4.2)
CTRL + A Moves to start of line*
4.2 Directories
CTRL + C Interrupts many programs Directories can be listed, renamed and copied just like
CTRL + D End-of-file character (logout) ordinary files (4.1.2)
CTRL + E Moves to end of line* mkdir dname -- makes a new directory dname rmdir
CTRL + R Search for previous commands * dname -- removes directory dname only if
it is empty (to remove non-empty directories (4.1.2))
CTRL + Z Suspends foreground job (6.2)
TAB Completes filenames, commands* cd -- return to your home directory
cd dname -- change directory to dname
pwd -- echoes your current working directory * matches an arbitrary number ( >= 0)of
characters
4.3 File permissions
Each file (and directory) has nine bits specifying its [...] matches any single character
access permission. Access can be given for a user to e.g. [an] matches a or n [a-z] matches any
read, write, or execute a file (or any combination of lowercase letter
these). Permissions can be specified for the owner of
a file, the members of a file's group and for everyone 6.2.2 Filename abbreviations
else. (ls -l provides this information). The chmod
command is used to change these file modes. . current working directory
.. parent of current working directory,
chmod [class(es)] op perm(s)[,...] file(s) where ~ your home directory,
classes are u, g, o, a (user(owner), group, others, all), ~user user home directory of user
op(erations) are =, -, + (set permission, remove
access, give access) and perm(issions) are r,w,x 6.2.3 Redirecting Input and Output
(read, write, execute).
In numeric mode r=4, w=2, x=1 cmd > fname redirects output from cmd
e.g. chmod u=rwx,g=rw,o-rwx f1 into fname (replacing fname if it
chmod 750 f1 (numeric mode) exists)
cmd >> fname redirects output from cmd
and appends it to fname (created
5 Processes if it doesn't exist)
cmd < fname uses fname as input for cmd
ps -x list all processes belonging to you

kill -9 pid kill process number pid (pid obtained 6.2.4 Pipelines
from ps -x)
The output stream from one command may be piped
w list all users on the machine into the input stream for another using the "|" symbol.
For example ls | wc counts the files in the current
whoami owner of this shell directory.

6.2.5 Jobs
6 bash
6.1 Commands jobs lists all background jobs command &
runs command in background
alias astring = cstring abbreviate command
cstring to be astring bg [n] place last CTRL + Z stop the foreground job bg places
[ nth ]suspended job in background the stopped job in the background
exec command replace shell with command
% [n] brings the current [nth] background
fg [n] bring last [ nth ] suspended job into job to foreground
foreground
history list command history (6.3) Also (6.1).

login, logout (2) 6.3 History mechanism


var = value set variable var [ to value val ] Special characters:
!! -- entire last line
export var export value assignment !n -- command line n in history
globally (6.4) ! -- final word on last line, e.g. ls !
source fname run commands in fname !* -- all of last line except for first word
!?pat? -- most recent line containing pat
umask ddd sets file permission creation
mask (4.3). All of the above can be modified with the following
suffixes:
6.2 Special Characters
6.2.1 Filename substitution :n-m -- words n to m on line e.g. !!:2-3
:p -- list command without executing, e.g.?foo?:p
You can abbreviate filenames using wild card
characters.
? matches any single character
6.4 Bash variables 10 Command summary
Command Description
Modified using var = value (6.1). The string var
returns the value contained by variable var. | pipeline (6.2.4)

PATH contains the list of directories to <,>,>> redirecting I/O (6.2.3)


search for issued commands
HOME your home directory (6.4)
!, !! recall commands (6.3)

% bring job to foreground (6.2.5)


TERM contains terminal information
acroread previewer for PDF files
7 Miscellaneous filters alias abbreviate command (6.1)
Most of the following commands may be used as bg put job in background (6.1)
filters i.e. they can take their input from the standard
input (and thus be part of a pipe (6.2.4)). See the cat list file (4.1.2)
manual pages for details.
cd change directory (4.2)
grep pattern file(s) -- types out the lines containing chmod change file permission (4.3)
pattern in the file(s). (egrep is a faster,
similar command allowing extended regular cp file copy (4.1.2)
expression matching).
diff list file differences (8)
grep -v pattern file(s) -- types out the lines not
containing pattern in the file(s) du disk usage (4.4)

export update environment var (6.1)


head [n] file(s) -- types out the top n lines of file(s)
fg bring job to foreground (6.1)
tail [n] file(s) -- types out the last n lines of file(s)
grep string searching (7)
diff file1 file2 -- lists the differences between the
two files. One of the filenames may be
gunzip uncompress a file (9)
replaced by a hyphen to specify standard input. gzip compress a file (9)

sort [-n] [-r] file -- sort file in [numeric] ascending jobs list jobs (6.2.5)
[descending] order.
kill kill processes (5)
wc file(s) -- counts characters, words and lines in logout finish work session (2)
text files
ls list file names (4.1.2)
8 Generic Startup Files
man online help (1)
These files are used to setup the environments of mkdir make directory (4.2)
certain programs.
more list file pagewise (4.1.2)
.history Shell history saved from last session
mv ename (move) file (4.1.2)
9 Compression passwd change password (2)
The GNU compression utilities reduce the disk space ps list processes (5)
used by a file, allowing the full contents to be
recovered later. rmdir remove directory (4.2)

rm rm remove (delete) file (4.1.2)


gzip file Replaces file with file.gz, a set set update variable (6.1)
compressed version of the file
source execute shell commands (6.1)
gunzip file.gz Uncompresses the file to recover
the original contents w, who w, who who is logged in (5)

zip -r file.zip file(s) Creates archive file.zip with


zip compress a file (9)
compressed version of files

You might also like