Unix Basics

Text editors

vi is the most widely available text editor in Unix. You have to learn a few commands, but then it becomes pretty efficient. It can be run from almost any terminal window and does not require an X11 session. Type vi filename at the prompt to get started. Type ESC :q (one key at a time, in order) to quit.

    Useful guide to vi

emacs is a very powerful editor that has great features, such as automatic formatting (tabbing, and useful text colors) for particular document types (e.g.
matlab script, Fortran code, latex file). Type
emacs at the prompt, and read the emacs tutorial for thorough instructions on commands to use.

nano is a basic editor that is probably the easiest text-only editor to use of any (only on linux). 

gedit or kedit – a basic GUI-based editor with an easy mouse-based interface 

To view a file but not edit it, you can use more or less.

cat filename lists the contents of a file on the screen.

 

Useful commands

Killing a job

If an application freezes for some reason, you can kill it from another terminal window. First you will need to see what processes are running, then find the job ID number, then kill the job.

At the prompt, type

ps -ef | grep username

with your username so you can see what processes are being run under your username. You can also just type

ps -ef” but that will show all jobs being run, not just yours.

If you are looking for a specific job, e.g. netscape (one of the first web browsers!), you would type

ps -ef | grep netscape

Which would return:

 katopod 106302 116600  0 12:41:35 pts/12  0:00 grep netscape
 katopod 106465 112940  0 12:36:05 pts/10  0:00 /bin/sh /usr/bin/X11/netscape
 katopod 106757 106465  0 12:36:06 pts/10  0:18 netscape

To kill a job, you will need the job ID number, which is the first number listed by ps.

kill 106465

Then check to see if the job has been killed by running the same command:

ps -ef | grep netscape

If for some reason the job is still there, do a super kill:

kill -9 106465

If someone else’s job is hanging up your system, you will have to ask a system administrator to kill their job for you.

Compiling and viewing a LaTeX file

A couple of ways you can get started: 1) American Meteorological Society LaTeX package, 2) Overleaf.com

This is the old way to do this:

save your document as filename.tex

compile:

% latex filename

convert the dvi file to postscript:
%dvips filename -o

view the postscript file using ghostview:

% gv filename.ps

Check out pdflatex too – it’s a bit easier to work with.

Useful Unix commands

Look at the man pages for all of these commands for more detailed and accurate information!

For basic unix commands, see https://inst.eecs.berkeley.edu/~cs61a/sp19/articles/unix.html

cp -rcopy directories and subdirectories (recursive)
echo “string” >> filt.txtappend string to a file
cat foot.txt | grep “\f” | sortfind lines with ‘f’ in foo.txt and sort
grep “string” *search all files in directory for string
cat foo.txt | grep flowersdisplay line with “flowers” in foo.txt
jobsdisplays jobs running in background
fg job_numberpull job to foreground
bgput job in background
stop job_numbersuspends job
kill job_numberkills job
kill -9 job_numbertotally kills job
compcompares text of two files
diffdisplays differences in files
hostnamedisplay current host
fromlist of messages in mail
scriptstarts a transcript of the terminal session
sttyset terminal options
ttyget terminal name
whatisdescribe command
whereisshows location of command
whichshows location
lesstext browser
moretext browser
spell file.txtspellcheck 
locate file.txtfinds the location of a file (search)
man commandopens man (manual) page for ‘command’, e.g. man pwd
mail user@domain.edu < notes.txtattach notes.txt to email and send