Welcome to Unix

Crafted by the CSUA at Berkeley http://csua.berkeley.edu Presented 8/29/2002

Redistribution
‡ 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.

Outline
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

Get a (more) permanent account from the OCF or CSUA.What is it and where do you get it? ‡ An operating system used on everything from servers to embedded systems. . probably a prompt: ~> type stuff here ‡ You get a temporary account when you take a CS class. Or buy a Mac. ‡ To you.

~>man command ‡ gives you help on that command. . ~>apropos keyword ‡ tells you all man pages that contain keyword.If you know only one thing. know how to RTFM.

‡ Go to the OCF in the MLK Heller Lounge when someone is holding staff hours. ‡ Come to the CSUA office. ‡ Post your question to a newsgroup (like your class newsgroup). ‡ HKN is next door the CSUA. 343 Soda. ‡ Hit the man pages/web first ! .How to get help.

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

.Files and Directories: Naming something gives you power over it.

Absolute Addressing .

Addressing relative to your home dir. .

Addressing relative to your current dir. .

copy mv <old file> <new file> .report your current directory cd <to where> .File system commands ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ pwd .change your current directory ls <directory> -list contents of directory cp <old file> <new file> .move (or rename) rm <file> -delete a file mkdir <new directory name> -make a directory rmdir <directory> -remove an empty directory .

getting recursive ‡ remove a directory and its contents: rm -r <directory> ‡ copy a directory and its contents: cp -r <directory> .

File permissions.local* . or execute a file.1 darin >ls -l . write.forward csua 2988 May 19 00:48 .1 darin csua 23 Jan 23 2002 .local -rwxr-xr-. your friends (group) and everyone else (other).cshrc.forward -rw-r--r-. ‡ There are 3 kinds of people in the world: you (user). ‡ Each sort of person may or may not be able to read.cshrc. >ls -l .

‡ ³executing´ a directory means setting your current directory to it using cd.executing ‡ ³executing´ a file means running it as a program. .

Changing File Permissions ‡ make a file readable to your friends: chmod g+r <filename> ‡ change who owns a file: chown <user> <filename> ‡ change to which group the file belongs: chgrp <group> <filename> .

‡ You can only touch a file to which you can write.touch ‡ look at the full listing again: >ls -l .forward ‡ Each file has a date stamp of when it was modified. .forward -rw-r--r-. touch <filename> ‡ Touch creates the file if it didn¶t exist beforehand. ‡ Use touch to set the timestamp to the current clock.1 darin csua 23 Jan 23 2002 .

forward* -rw-r--r-.Symbolic Links ‡ use ln -s <old file> <second symbolic link to a file. ‡ Symbolic links can be used as if it were its target.1 darin lrwxr-xr-x 1 darin csua csua .forward ‡ The first ³l´ tells you that it¶s a symbolic link.forward .forward.link@ -> . name> to create a >ls -l . .

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

‡ your window to the Unix world. ‡ use ³chsh <new shell>´ to change your shell . It prints the prompt and reads what you type. etc.what¶s a shell? ‡ The shell is the program that runs when you log in. invokes programs.

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 BOB ³joe´ (tcsh) ~>printenv BOB joe (tcsh) ~>echo $BOB joe .

then typing it (~>ls <enter>) will execute it.PATH: a very important shell variable >echo $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:. ‡ Otherwise you can type the full absolute address to execute a program (~>/usr/bin/ls <enter>) ./ ‡ If a program (like ls) is in one directory found in your path.

‡ Type ³which <command>´ to find the location of the program which would be run when you type <command>. type ³ch<control-d>´ to get a list of commands that starts with ch. use ³find´ to find a file. ‡ If you don¶t remember if it was chgrp or chgroup. ~>find <start dir> -name ´*.finding things in your PATH.docµ . ‡ when all else fails.

Other useful pre-defined shell variables ‡ ‡ ‡ ‡ ‡ HOST PAGER PWD GROUP USER what computer you¶re logged into program used display man pages current directory what group you¶re in your login .

‡ If the first line of your script looks like #!<program name> then you can make the script executable. When it executes. it uses <program name> to interpret the contents of the script. Then type ³source <file>´ to run the script. . ‡ If you have a bunch of commands you¶d like to automate. you can put them on separate lines of a file.Shell scripts.

. It is commonly used to set up one¶s PATH and aliases. ‡ Ask someone to help you start your own login script.Login scripts ‡ Most people have a script that executes when they log in.

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. .

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

Your Options ‡ Abstinence (switch majors. do not use network) ‡ protection (also known as encryption) . unplug your computer) ‡ monogamy (use only one computer.

ftp. ‡ telnet. ‡ from library machines you can use the java ssh client from a web browser. . rlogin ‡ all your data (including your password) is transmitted plain text over the network.What not to use.

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 file> user@machine:<path> ‡ copy remote to local scp user@machine:<path> <source file> .

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

the program mail ‡ ³mail´: useful for sending: >mail darin@csua Subject: hello Cc: hi there this is a message . .

‡ pine .most modern/complex.other console based options ‡ elm .more complete. but doesn¶t handle attachments very well. the ³standard´ ‡ mutt .quick and simple. . easy to use.

eudora. but leaves mail how it is on the server. ‡ ALWAYS use SSL (encryption). ‡ POP takes the messages off the server to your local computer. Works well if you wish to use console based email. outlook. . and others can get at your mail using POP or IMAP.accessing mail remotely ‡ netscape. ‡ IMAP only reads headers.

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

In command mode each letter is a command. hjkl  nqop . ‡ Has two modes: command and insert.vi ‡ is an editor available on all decent Unix systems. In insert mode you can type normally. ‡ Press escape to get into command mode. Developed at Berkeley.

‡ all possible commands displayed at bottom of screen. (control-somethings) ‡ no real surprises .the pine composer ‡ the simplest visual editor available on most Unix systems.pico .

designed by and for lisp programmers.emacs ‡ Always has one major mode running. potentially several minor modes. ‡ stands for editing macros . .

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

which is usually your screen ± standard input.STD* ‡ All terminal programs have: ± standard output. which is also the screen . which is usually your keyboard ± standard error.

redirect output to a file with > ‡ If you type who at the prompt. you will get a list of who is logged into the system. . a file named f will be created and the standard output of who will be placed in that file instead of to your screen. ‡ If you type who >f.

‡ Use who >>f to append to f rather than overwriting it. . who >f will overwrite the file f.> vers >> ‡ By default.

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

Outline
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 printer in 330 is called ³lw330´.printers have stupid names ‡ The printers downstairs are named ³lw274´.

ps .how to print a .ps file ‡ syntax: lp -D<printer> <filename> ‡ example: lp -Dlw330 myfile.

ps .pdf file ‡ convert it to .how to print a .pdf output.ps first!!! ‡ use the pdf2ps utility program. pdf2ps input.

ps first!!! ‡ The program a2ps (anything to .how to print other file types ‡ Convert them to . .ps) works most of the time.

‡ syntax: lpq -P<printer_name> ‡ example: lpq -Plw330 .How to check the printer¶s queue.

. Type ³cancel´.How to cancel your print job.

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

‡ example: big_program > output & ‡ big_program will not have input! . use ³&´.To start a process in the background.

use <control-z>. type ³fg´ ‡ To put the program you just suspended in the background. ‡ To return to the program you just suspended.managing jobs ‡ To suspend the currently active program. type ³bg´ .

To see a list of your programs running. >ps PID TTY 866 pts/1 872 pts/1 TIME CMD 00:00:00 tcsh 00:00:00 ps . type ³ps´.

use kill to end a process >ps PID 866 874 875 TTY pts/1 pts/1 pts/1 TIME 00:00:00 00:00:00 00:00:00 CMD tcsh cat ps >kill 874 [1] Terminated cat .

use kill -9 <PID> .kill -9 ‡ If kill <PID> doesn¶t end your process.

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

‡ There is no ³saving to the clipboard´ step as in Microsoft¶s Windows or MacOS. ‡ Hit the middle mouse button in another window.cutting and pasting ‡ Highlight some text in any window. . ‡ The highlighted text appears.

‡ <control-leftclick> in xterm ‡ edit -->preferences --> fonts in netscape. .Changing your fonts.

Changing your window manager.xsession gets run when you log into X windows. . the last line sets which window manager you are going to use. ‡ Your ~/. ‡ You probably want someone to set up your X configuration for you the first time.

‡ You need to get a program called a program called an ³Xserver´. ‡ You must allow X-forwarding through your ssh client. .Using X windows at home on a MS-Windows machine. Exceed works well and is free for academic use. Putty is good for this.

Sign up to vote on this title
UsefulNot useful