You are on page 1of 71

|  

Crafted by the CSUA at Berkeley


http://csua.berkeley.edu
Presented 8/29/2002
ðedistribution
‡ The authors (nor anyone else) provides no
warranty or claim of accuracy of this
document. Use at your own risk.

‡ You may use this document in whole or part


according to the terms of the GPL. See
http://www.gnu.org/copyleft/gpl.html for
details.
Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
|hat is it and where do you get it?

‡ An operating system used on everything


from servers to embedded systems.

‡ To you, probably a prompt:


~> › ›

‡ You get a temporary account when you take


a CS class. Get a (more) permanent account
from the VCF or CSUA. Vr buy a Mac.
'f you know only one thing,
know how to ðTFM.

~>man ? 
‡ gives you help on that command.

~>apropos  
‡ tells you all man pages that contain  .
ow to get help.

‡ Come to the CSUA office, 343 Soda.


‡   is next door the CSUA.
‡ Go to the VCF in the ML eller Lounge
when someone is holding staff hours.
‡ Post your question to a newsgroup (like
your class newsgroup).

‡ it the man pages/web first !


Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
Files and Directories:
aming something gives you power over it.
Absolute Addressing
Addressing relative to your home dir.
Addressing relative to your current dir.
File system commands

‡ pwd - report your current directory


‡ cd ¬›  
- change your current directory
‡ ls ¬?› 
-list contents of directory
‡ cp ¬ 
¬ 
- copy
‡ mv ¬ 
¬ 
 move (or rename)
‡ rm ¬
-delete a file
‡ mkdir ¬ ?›  
-make a directory
‡ rmdir ¬?› 
-remove an empty directory
getting recursive

‡ remove a directory and its contents:


rm -r ¬?› 


‡ copy a directory and its contents:


cp -r ¬?› 

File permissions.
‡ There are 3 kinds of people in the world: you (user),
your friends (group) and everyone else (other).

‡ Each sort of person may or may not be able to read,


write, or execute a file.

sls -l .forward
-rw-r--r-- 1 darin csua 23 Jan 23 2002 .forward

sls -l .cshrc.local
-rwxr-xr-- 1 darin csua 2988 May 19 00:48 .cshrc.local*
executing
‡ ³executing´ a file means running it as a
program.

‡ ³executing´ a directory means setting your


current directory to it using cd.
Changing File Permissions

‡ make a file readable to your friends:


chmod g+r ¬

‡ change who owns a file:


chown ¬
¬

‡ change to which group the file belongs:


chgrp ¬  
¬

touch
‡ look at the full listing again:
sls -l .forward
-rw-r--r-- 1 darin csua 23 Jan 23 2002 .forward

‡ Each file has a date stamp of when it was modified.


‡ Use touch to set the timestamp to the current clock.

touch <filenames

‡ Touch creates the file if it didn¶t exist beforehand.


‡ You can only touch a file to which you can write.
Symbolic Links
‡ use ln -s <old files <second names to create a
symbolic link to a file.

sls -l .forward*
-rw-r--r-- 1 darin csua .forward
lrwxr-xr-x 1 darin csua .forward.link@ -s .forward

‡ The first ³l´ tells you that it¶s a symbolic link.


‡ Symbolic links can be used as if it were its target.
Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
what¶s a shell?

‡ The shell is the program that


runs when you log in. 't prints
the prompt and reads what you
type, invokes programs, etc.

‡ your window to the Unix world.

‡ use ³chsh ¬ 


to change your shell
File Globbing
‡ some commands can work on many files at once:
~> rm file1 file2 file27

‡ Use * to match any number of unknown characters


~> rm file*

‡ Use ? to match one unknown character.


~> rm file?
(un)aliasing
‡ create shortcuts for yourself
~>alias ll ³ls -la´

‡ Use alias with no arguments to discover


current aliases
~>alias
rm rm -i
ll ls -la

‡ Type ³unalias rm´ to remove alias.


shell variables, echo

(tcsh) ~>setenv BVB ³joe´

(tcsh) ~>printenv BVB


joe

(tcsh) ~>echo $BVB


joe
PAT: a very important shell variable
secho $PATH
/home/d/da/darin/bin:/opt/local/bin:/opt/local/bin/pbmutil
s:/usr/bin:/usr/sbin:/opt/SUNWspro/bin:/usr/ccs/bin:/op
t/local/X11/bin:/usr/dt/bin:/usr/openwin/bin:/opt/local
/gnu/bin:/opt/local/games/bin:/usr/ucb:./

‡ 'f a program (like ls) is in one directory found in


your path, then typing it (~sls <enters) will execute
it.

‡ Vtherwise you can type the full absolute address to


execute a program (~s/usr/bin/ls <enters)
finding things in your PAT.

‡ Type ³which ¬? >´ to find the location


of the program which would be run when you
type ¬? 

‡ 'f you don¶t remember if it was chgrp or


chgroup, type ³ch<control-d>´ to get a list of
commands that starts with ch.

‡ when all else fails, use ³find´ to find a file.


~sfind <start dirs -name ´*.docµ
Vther useful pre-defined shell variables

‡ VST what computer you¶re logged into


‡ PAGEð program used display man pages
‡ P|D current directory
‡ GðVUP what group you¶re in
‡ USEð your login
Shell scripts.

‡ 'f you have a bunch of commands you¶d like to


automate, you can put them on separate lines of a
file. Then type ³source <
to run the script.

‡ 'f the first line of your script looks like


´ <program names
then you can make the script executable. |hen it
executes, it uses ¬ 
to interpret the
contents of the script.
Login scripts
‡ Most people have a script that executes
when they log in. 't is commonly used to
set up one¶s PAT and aliases.

‡ Ask someone to help you start your own


login script.
screen is your friend

‡ You can use the program ³screen´ to run several


shells from one window.

‡ create a new shell by pressing <ctrl-a> c

‡ switch shells by pressing <ctrl-a> <number>

‡ use ³<ctrl-a> d´ to detach a session and come back


to it later.
Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
Your Vptions
‡ Abstinence
(switch majors, unplug your computer)

‡ monogamy
(use only one computer, do not use network)

‡ protection
(also known as encryption)
|hat not to use.
‡ telnet, ftp, rlogin

‡ all your data (including your password) is


transmitted plain text over the network.

‡ from library machines you can use the java


ssh client from a web browser.
using ssh keys
‡ use ³ssh-keygen´ to generate a
public/private set of keys. You keep the
private key and append the public key to
authorized_keys.

‡ You can now log in using either your


password or the private key file.
using secure copy: scp

‡ copy local to remote


scp <source files user@machine:<paths

‡ copy remote to local


scp user@machine:<paths <source files
Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
the program mail
‡ ³mail´: useful for sending:

smail darin@csua
Subject: hello
Cc:
hi there
this is a message
.
other console based options
‡ elm - quick and simple, easy to use, but
doesn¶t handle attachments very well.

‡ pine - more complete. the ³standard´

‡ mutt - most modern/complex.


accessing mail remotely
‡ netscape, outlook, eudora, and others can
get at your mail using PVP or 'MAP.

‡ PVP takes the messages off the server to


your local computer.

‡ 'MAP only reads headers, but leaves mail


how it is on the server. |orks well if you
wish to use console based email.
‡ AL|AYS use SSL (encryption).
Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
vi
‡ is an editor available on all decent Unix
systems. Developed at Berkeley.

‡ as two modes: command and insert. 'n


insert mode you can type normally.

‡ Press escape to get into command mode. 'n


command mode each letter is a command.

hjkl  
pico - the pine composer
‡ the simplest visual editor available on most
Unix systems.

‡ all possible commands displayed at bottom


of screen. (control-somethings)

‡ no real surprises
emacs
‡ Always has one major mode running,
potentially several minor modes.

‡ stands for editing macros - designed by and


for lisp programmers.
Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
STD*

‡ All terminal programs have:

± standard output, which is usually your screen


± standard input, which is usually your keyboard
± standard error, which is also the screen
redirect output to a file with >

‡ 'f you type who at the prompt, you will get


a list of who is logged into the system.

‡ 'f you type who sf, a file named f will be


created and the standard output of who will
be placed in that file instead of to your
screen.
> vers >>

‡ By default, who sf will overwrite the file f.

‡ Use who ssf to append to f rather than


overwriting it.
redirecting input from a file with <
‡ The program sort will sort its standard
input and then print it on standard out.

‡ To sort the lines of file1 and display:


sort < file1

‡ To sort the lines of file1 and save in file2:


sort < file1 s file2
The output of one program can
be the input to another.

who | sort

‡ The output of who is sorted and shown on


your terminal screen.
grep

‡ grep shows only those lines containing its


search pattern.

‡ To see all lines in a file containing µbob¶:

grep ¶bob· < file1


The cat command
‡ the arguments to cat are concatenated together
and displayed on stdout. To view a file:

cat file1

‡ if no arguments, cat puts on stdout whatever


you type on stdin, so this does the same thing:

cat < file1


Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
printers have stupid names

‡ The printers downstairs are named ³lw274´.

‡ The printer in 330 is called ³lw330´.


how to print a .ps file

‡ syntax:
lp -D<printers <filenames

‡ example:
lp -Dlw330 myfile.ps
how to print a .pdf file

‡ convert it to .ps first!!!

‡ use the pdf2ps utility program.

pdf2ps input.pdf output.ps


how to print other file types

‡ Convert them to .ps first!!!

‡ The program a2ps (anything to .ps) works


most of the time.
ow to check the printer¶s queue.

‡ syntax:
lpq -P<printer_names

‡ example:
lpq -Plw330
ow to cancel your print job.

Type ³cancel´.
Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
To start a process in the
background, use ³&´.

‡ example:

big_program s output &

‡ big_program will not have input!


managing jobs
‡ To suspend the currently active program,
use <control-z>.

‡ To return to the program you just


suspended, type ³fg´

‡ To put the program you just suspended in


the background, type ³bg´
To see a list of your programs
running, type ³ps´.

sps
PID TTY TIME CMD
866 pts/1 00:00:00 tcsh
872 pts/1 00:00:00 ps
use kill to end a process
sps
PID TTY TIME CMD
866 pts/1 00:00:00 tcsh
874 pts/1 00:00:00 cat
875 pts/1 00:00:00 ps

skill 874
[1] Terminated cat
kill -9

‡ 'f kill <PIDs doesn¶t end your


process, use kill -9 <PIDs
Vutline
I. getting help
II. the file system
III. the shell
IV. safe computer sex
V. email options
VI. and lesser editors
VII. input and output redirection
VIII.printing
IX. process management
X. X
cutting and pasting

‡ ighlight some text in any window.

‡ it the middle mouse button in another


window.

‡ The highlighted text appears.

‡ There is no ³saving to the clipboard´ step as


in Microsoft¶s |indows or MacVS.
Changing your fonts.

‡ <control-leftclick> in xterm

¢ edit --spreferences --s fonts


in netscape.
Changing your window manager.

‡ Your ~/.xsession gets run when you


log into X windows, the last line sets which
window manager you are going to use.

‡ You probably want someone to set up your


X configuration for you the first time.
Using X windows at home on a
MS-|indows machine.

‡ You need to get a program called a program


called an ³Xserver´. Exceed works well
and is free for academic use.

‡ You must allow X-forwarding through your


ssh client. Putty is good for this.

You might also like