98
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques

Introduction to Basic Unix

Embed Size (px)

DESCRIPTION

Introduction to Basic Unix

Citation preview

Page 1: Introduction to Basic Unix

Lecture 1: Introduction, Basic UNIX

Advanced Programming Techniques

Page 2: Introduction to Basic Unix

Unix Programming Environment1

Objective: To introduce students to the basic features of Unix and the Unix Philosophy (collection of combinable tools and environment that supports their use) Basic commandsFile systemShellFilters (wc, grep, sort, awk)File redirection, Pipes

Page 3: Introduction to Basic Unix

Operating Systems

An Operating System controls (manages) hardware and software.provides support for peripherals such

as keyboard, mouse, screen, disk drives, …

software applications use the OS to communicate with peripherals.

The OS typically manages (starts, stops, pauses, etc) applications.

Page 4: Introduction to Basic Unix

Kernel (OS) Interacts directly with the hardware through device drivers Provides sets of services to programs, insulating these programs from the underlying hardware Manages memory, controls access, maintains file system, handles interrupts, allocates resources of the computer Programs interact with the kernel through system calls

Page 5: Introduction to Basic Unix

Structure of the UNIX system

Applications

Shell

\Kernel (OS)

Hardware

There are many standard applications:

• file system commands

• text editors

• compilers

• text processing

Page 6: Introduction to Basic Unix

Unix and Users

Most flavors of Unix (there are many) provide the same set of applications to support humans (commands and shells).Although these user interface programs are not part of the OS directly, they are standardized enough that learning your way around one flavor of Unix is enough.

Page 7: Introduction to Basic Unix

Flavors of Unix

There are many versions of Unix that are used by lots of people:SysV (from AT&T)BSD (from Berkeley)Solaris (Sun)IRIX (SGI)AIX (IBM)LINUX (free software)

Page 8: Introduction to Basic Unix

Logging In

To log in to a Unix machine you can either:sit at the console (the computer itself)access remotely, via SSH, e.g.

The system prompts you for your username and password.Usernames and passwords are case sensitive!

Page 9: Introduction to Basic Unix

CS Dept. Accounts

See http://www.cs.drexel.edu/~kschmidt/Ref/csLogin.htmlAll CS machines (that you have access to) running Linuxtux machines – the farm you may

connect to from anywheretux.cs.drexel.edu

lab machines – any of the desktops you may sit at in the lab, classrooms

Not administered by Drexel IRT

Page 10: Introduction to Basic Unix

Username

(typically) a sequence of alphanumeric characters of length no more than 8.the primary identifying attribute of your account.(usually) used as an email addressthe name of your home directory is usually related to your username.

Page 11: Introduction to Basic Unix

Passworda password is a secret string that only the user knows (not even the system knows!)When you enter your password the system encrypts it and compares to a stored string.passwords should have at least 6 charactersIt's a good idea to mix case, include numbers and/or special characters (don't use anything that appears in a dictionary!)

Page 12: Introduction to Basic Unix

User's Home Directory

The user’s personal directory. E.g.,All home (users') directories (on tux)

are in /home/home/kschmidt/home/vzaychik

Where all your files go (hopefully organised into subdirectories)Mounted from a file server – available (seemlessly) on *any* department machine you log into

Page 13: Introduction to Basic Unix

Home Directory

Your current directory when you log incd (by itself) takes you homeLocation of many startup and customization files. E.g.:.vimrc .bashrc .bash_profile .forward .pl

an .mozilla/ .elm/ .logout

Page 14: Introduction to Basic Unix

Files and File Names

A file is a basic unit of storage (usually storage on a disk).Every file has a name.Filenames are case-sensitive!Unix file names can contain any characters (although some make it difficult to access the file) except the null character and the slash (/).Unix file names can be long!how long depends on your specific flavor of Unix

Page 15: Introduction to Basic Unix

Directories

A directory is a special kind of file - Unix uses a directory to hold information about other files.We often think of a directory as a container that holds other files (or directories).A directory is the same idea as a folder on Windows.

Page 16: Introduction to Basic Unix

More about File Names

Every file has a name (at least one)Each file in the same directory must have a unique name.Files that are in different directories can have the same name.Files that start with a '.' are, by default, hidden by many utilities

Page 17: Introduction to Basic Unix

The Filesystem (eg)

/

bin etc home/ tmp usr

hollid2 scully bin etc

netprog unix X ls who

Page 18: Introduction to Basic Unix

Unix Filesystem

The filesystem is a hierarchical system of organizing files and directories.

The top level in the hierarchy is called the "root" and holds all files and directories in the filesystem.

The name of the root directory is /

Page 19: Introduction to Basic Unix

Pathnames

The pathname of a file includes the file name and the name of the directory that holds the file, and the name of the directory that holds the directory that holds the file, and the name of the … up to the rootThe pathname of every file in a given filesystem is unique.

Page 20: Introduction to Basic Unix

Pathnames (cont.)

To create a pathname you start at the root (so you start with "/"), then follow the path down the hierarchy (including each directory name) and you end with the filename.In between every directory name you put a "/".

Page 21: Introduction to Basic Unix

Pathname Examples

/

bin/ etc/ home/ tmp/ usr/

Hollid2/ scully/ bin/ local/

netprog unix/ X ls who

/usr/bin/lsSyllabus

/home/hollid2/unix/Syllabus

Page 22: Introduction to Basic Unix

Absolute Pathnames

The pathnames described in the previous slides start at the root.These pathnames are called "absolute pathnames".Special absolute:~kschmidt/ – /home/kschmidt (for

users’ home directories only)~/ – Your home directory (so, relative

to login, $USER)

Page 23: Introduction to Basic Unix

Relative PathnamesPrefixed w/the current directory, $PWDSo, relative to the current working directory$ cd /home/hollid2$ pwd/home/hollid2$ ls unix/Syllabusunix/Syllabus$ ls Xls: X: No such file or directory$ ls /home/scully/X/home/scully/X

Page 24: Introduction to Basic Unix

Special Relative paths…

. – The current directory .. – The parent directory$ pwd

/home/holid2

$ ls ./netprog

./netprog

$ ls ../scully

X

Page 25: Introduction to Basic Unix

Disk vs. FilesystemThe entire hierarchy can actually include many disk drives.some directories can be on other computers

/

bin etc users tmp usr

hollid2 scully

Page 26: Introduction to Basic Unix

Commands – Basic Syntax

Shell expects the first token (for now) to be a command. Subsequent tokens are argumentsArguments that start with a – are called options (generally, Posixly)

ls -o /home/kschmidt /home/kschmidt/Public

– -o provides a long listing– The final 2 tokens are directories

to be listed

Page 27: Introduction to Basic Unix

Commands for Traversing Filesystem

ls – lists contents of a directory-a – all files-l – long listing

pwd – print working (current) directorycd – change directoryw/out argument, takes you home

Page 28: Introduction to Basic Unix

man Pages

To get information about anything that's been properly installed, use man:man lsman catman man

– You can do a keyword search:man -k keyword

Linux boxes also have info pages

Page 29: Introduction to Basic Unix

The ls command

The ls command displays the names of the named filesGive it the name of a directory as a command line argument to list all the (unhidden) files in the directory.By itself, it lists the current working directory

Page 30: Introduction to Basic Unix

Command Line Options

We can modify the output format of the ls program with a command line option.The ls command support a bunch of options: -l long format (include file times, owner and

permissions). Compare to -o -a all (shows hidden* files as well as regular

files) -F include special char to indicate file types. -C place into columns

*hidden files have names that start with "."

Page 31: Introduction to Basic Unix

cd – change directory

The cd command can change the current working directory:cd change directory

The general form is:cd [directoryname]

By itself, returns you to your home directory

Page 32: Introduction to Basic Unix

Viewing files

cat – concatenate, send to stdout. View contents of text filesless, more – paging utilities (hit ‘h’ for help, 'q' to quit)od – octal dump. For viewing raw data in octal, hex, control chars, etc.

Page 33: Introduction to Basic Unix

Copying, removing, linking

rm – remove filerm ~/tmp/download

mv – move (rename) filemv old.file ../otherDir/new.name

cp – copy filecp someDir/file someDir/file.copy

ln – create hard (inode) or soft (symbolic) links to a file

Page 34: Introduction to Basic Unix

Commands for directories

mkdir make directoryrmdir remove directoryDirectories can also be moved or renamed (mv), and copied (cp –r)

Page 35: Introduction to Basic Unix

Commands for Archiving

tar – Tape Archivemakes a large file from many files

gzip, gunzipcompression utility

tar on Linux does gzip compression with the z option:$ tar czf 571back.tgz CS571

$ tar xzf assn1.tgz

Page 36: Introduction to Basic Unix

File attributes

Every file has some attributes:Access Times:

when the file was createdwhen the file was last changedwhen the file was last read

SizeOwners (user and group)PermissionsType – directory, link, regular file, etc.ACLs – access control lists (not today)

Page 37: Introduction to Basic Unix

File Time Attributes

Time Attributes:when the file was last changed ls -lsort by modification time ls -lt

Page 38: Introduction to Basic Unix

File Owners

Each file is owned by a user.You can find out the username of the file's owner with the -l or -o option to ls:

[jjohnson@ws44 winter]$ ls -l

total 24

drwxr-xr-x 7 jjohnson users 80 Jan 3 2005 cs265/

-rw------- 1 jjohnson users 8258 Jan 3 2005 cs265.html

-rw-r--r-- 1 jjohnson users 8261 Jan 3 2005 cs265.html~

Page 39: Introduction to Basic Unix

ls -l

$ ls -l foo

-rw-rw---- 1 hollingd grads 13 Jan 10 23:05 foo

permissionsowner group

size

time

name

Page 40: Introduction to Basic Unix

File Permissions

Each file has a set of permissions that control who can mess with the file.There are three types of permissions:

read abbreviated r write abbreviated w execute abbreviated xThere are 3 sets of permissions:

1. user2. group3. other (the world, everybody else)

Page 41: Introduction to Basic Unix

ls -l and permissions

-rwxrwxrwx User Group Others

Type of file:- – plain filed – directorys – symbolic link(others)

Page 42: Introduction to Basic Unix

rwx

Files:r - allowed to read.w - allowed to writex - allowed to execute

Directories:r - allowed to see the names of the

contentsw - allowed to add and remove files.x - allowed to “enter” the directory

Page 43: Introduction to Basic Unix

Changing Permissions

The chmod command changes the permissions associated with a file or directory.There are a number of forms of chmod, this is the simplest:

chmod mode file

Page 44: Introduction to Basic Unix

chmod – numeric modesConsider permission for each set of users (user, group, other) as a 3-bit # r – 4w – 2x – 1

A permission (mode) for all 3 classes is a 3-digit octal #755 – rwxr-xr-x644 – rw-r—r--700 – rwx------

Page 45: Introduction to Basic Unix

chmod - examples$ chmod 700 CS571$ ls –o Personaldrwx------ 10 kschmidt 4096 Dec 19 2004 CS571/

$ chmod 755 public_html$ chmod 644 public_html/index.html$ ls –ao public_htmldrwxr-xr-x 16 kschmidt 4096 Jan 8 10:15 .drwx--x--x 92 kschmidt 8192 Jan 8 13:36 ..-rw-r--r-- 5 kschmidt 151 Nov 16 19:18 index.html

$ chmod 644 .plan$ ls –o .plan-rw-r--r-- 5 kschmidt 151 Nov 16 19:18 .plan

Page 46: Introduction to Basic Unix

chmod – symbolic modes

Can be used to set, add, or remove permissionsMode has the following form:

[ugoa][+-=][rwx]u – user g – group o – other a – all+ add permission - remove permission

= set permission

Page 47: Introduction to Basic Unix

chmod examples

$ ls -al foo

-rwxrwx--x 1 hollingd grads foo

$ chmod g-wx foo

$ ls -al foo

-rwxr----x 1 hollingd grads foo

$ chmod u-r .

$ ls

ls: .: Permission denied

Page 48: Introduction to Basic Unix

Shell as a user interface

A shell is a command interpreter, an interface between a human (or another program) and the OSruns a program, perhaps the ls

program.allows you to edit a command line.can establish alternative sources of

input and destinations for output for programs.

Is, itself, just another program

Page 49: Introduction to Basic Unix

Bourne-again Shell (bash)

We’ll teach bash in this courseExtension of the Bourne Shell (sh)Contains many of the Korn Shell (ksh) extensionsYou may use the shell of your choice (tcsh, zsh, etc.), but that’s on you.

Page 50: Introduction to Basic Unix

Session StartupOnce you log in, your shell will be started and it will display a prompt.(for our examples, we will use $ as

the prompt. It is not part of the input)

When the shell is started it looks in your home directory for some customization files.You can change the shell prompt,

your PATH, and a bunch of other things by creating customization files.

Page 51: Introduction to Basic Unix

Customization

Each shell supports some customization.User promptWhere to find mailShortcuts

The customization takes place in startup files – files that are read by the shell when it starts up

Page 52: Introduction to Basic Unix

Startup filessh,ksh:

/etc/profile (system defaults) ~/.profile

bash:

~/.bash_profile

~/.bashrc

~/.bash_logout

csh:

~/.cshrc

~/.login

~/.logout

Page 53: Introduction to Basic Unix

Incorrect login

You will receive the “Password:” prompt even if you type an incorrect or nonexistent login name– Can you guess why?Nothing will happen while you type your password. It's fine

Page 54: Introduction to Basic Unix

Entering Commands

The shell prints a prompt and waits for you to type in a command.The first token on the line is taken to be a command (for now). Come in 2 flavors:shell builtin - commands that the shell

interprets directly.External programs (utilities) –

standalone programs on disk (directories in your $PATH are searched, in order)

Page 55: Introduction to Basic Unix

Interpreting a Command - type

When a command is seen, the shell:1. Checks for aliases2. Checks for user-defined functions3. Looks for a builtin4. Checks directories in $PATH for a utility

Use Bash’s type builtin to see what the shell is using:kschmidt@ws60 kschmidt> type echoecho is a shell builtinkschmidt@ws60 kschmidt> type chmodchmod is /bin/chmod

Page 56: Introduction to Basic Unix

Command Options and Arguments

standardized command syntax (applies to most commands):

command option(s) arguments

options modify the way in which a command works, often single letters prefixed with a dash (can be sometimes combined after a single dash

Page 57: Introduction to Basic Unix

Getting helpmanual – original Unix help (flat, single page)$ man bashinfo – 2-d system, emacs-like navigation$ info bashUse the help builtin for help on Bash builtin commandsThe resource frame on the class pageInternet – google, wikipedia

The linux documentation project (http://www.tldp.org/)Safari online Friends, group-mates, and others

Page 58: Introduction to Basic Unix

Some simple commandsdate – print current datewho – print who is currently logged infinger user – more information about userls -ao – lists (long) all files in a directorydu -sh – disk usage summary, human readablequota

Page 59: Introduction to Basic Unix

Logging off

exit builtin (command)Exits the shellIf it is the login (top-level) shell, then

it disconnects you

A shell is just another program that is running. Can recursively invoke shellsPlease don’t just disconnect w/out exiting

Page 60: Introduction to Basic Unix

Standard I/OWhen you enter a command the shell creates a subshell to run the process or script.The shell establishes 3 I/O channels:Standard Input (0) – keyboardStandard Output (1) – screenStandard Error (2) – screen

These streams my be redirected to/from a file, or even another command

Page 61: Introduction to Basic Unix

Programs and Standard I/O

ProgramProgramStandard Input

(STDIN)Standard Output

(STDOUT)

Standard Error(STDERR)

Page 62: Introduction to Basic Unix

Terminating Standard Input

If standard input is your keyboard, you can type stuff in that goes to a program.To signal the end of input press Ctrl-D (^D), the EOF signal, on a line by itself, this closes the input stream.The shell is a program that reads from standard input.What happens when you give the shell ^D? (See the bash set command, ignoreeof)

Page 63: Introduction to Basic Unix

Shell metacharactersSome characters have special meaning to the shell. These are just a few:I/O redirection< > |

wildcards* ? [ ]

others& ; $ ! \ ( ) space tab newline

These must be escaped or quoted to inhibit special behavior

Page 64: Introduction to Basic Unix

Wildcards* – matches 0 or more characters? – matches exactly 1 character[<list>] – matches any single character in <list>

E.g.ls *.cc – list all C++ source files in directory

ls a* – list all files that start w/’a’ls a*.jpeg – list all JPEGs that start w/’a’ls * - (make sure you have a subdirectory, and try it)

Page 65: Introduction to Basic Unix

Wildcards (more examples)

ls file?

- matches file1, file2, but not file nor file22

ls file?.*.DEL

- matches file1.h.DEL, file9.cc.DEL, file3..DEL but not file8.DEL nor file.html.DELThese are not regular expressions!

Page 66: Introduction to Basic Unix

Wildcards - classes[abc] matches any of the enclosed

charactersls T[eE][sS][tT].doc

[a-z] matches any character in a rangels [a-zA-Z]*

[!abc…] matches any character except those listed.

ls [!0-9]*

Page 67: Introduction to Basic Unix

Shell Variables

bash uses shell variables to store informationShell variables are used to affect the behavior of the shell, and many other programsWe can access these variables:set new values for some to customize

the shell.find out the value of some to help

accomplish a task.

Page 68: Introduction to Basic Unix

Setting/Viewing VariablesTo assign (in sh, ksh, bash):VAR=someStringOTHER_VAR=“I have whitespace”Note, no whitespace around the ‘=‘!

To view (dereference) a variable:$ echo $VARsomeString$ echo $OTHER_VARI have whitespace

Page 69: Introduction to Basic Unix

Shell maintains some variables

Some common ones:PATH – list of directories shell searches

for non-shell commandsPS1 – Primary promptUSER – user's login nameHOME – user’s home directoryPWD – current working directory

Page 70: Introduction to Basic Unix

Other Useful OnesSHELL – the login shellTERM – the type of terminal

interfaceHISTFILE – where your command

history is savedEDITOR – holds user's preferred

editorHOSTNAME – machine's hostnameSHELLOPTS – status of various shell

options (see Bash's set built-in)

Page 71: Introduction to Basic Unix

Displaying Shell Variables

Prefix the name of a shell variable with "$".The echo command will do:$ echo $HOME

$ echo $PATH

You can use these variables on any command line:

$ ls -al $HOME

Page 72: Introduction to Basic Unix

Setting Shell Variables

You can change the value of a shell variable with an assignment command (this is a shell builtin command):

HOME=/etc

PATH=/usr/bin:/usr/etc:/sbin

NEWVAR="blah blah blah"

Page 73: Introduction to Basic Unix

set command (shell builtin)

The set command with no args prints out a list of all the shell variables.Some bash optionsnoclobber – won't let re-direct

overwrite an existing fileignoreeof – Shell won't exit on ctrl-Dvi – use vi-style interface (by default,

bash uses emacs-style key bindings)-n – dry-run (just parse, but don't

execute). Handy for debugging scripts

Page 74: Introduction to Basic Unix

Quoting – escape character, \

Use the backslash to inhibit the special meaning of the following character:$ echo $USER

kschmidt

$ echo \$USER

$USER

$ echo a\\b

a\b

Page 75: Introduction to Basic Unix

Quoting – double quotes

Double quotes inhibit all behavior except variable substitution, command substitution, and the escape, \$ echo “$USER is $USER”

kschmidt is kschmidt

$ echo “\$USER is $USER”

$USER is kschmidt

$ echo “I said, \”Wait a moment\””

I said, “Wait a moment”

Page 76: Introduction to Basic Unix

Quoting – single quotes

Single quotes inhibit nearly all special behaviorMay not contain a single quote$ echo ‘I said “Wait!”’

I said “Wait!”

$ echo ‘My name is $USER’

My name is $USER

$ mv rambleOnByLedZeppelin ‘ramble on – led zeppelin’

Page 77: Introduction to Basic Unix

Input Redirection

The shell can read stdin from places other than your keyboard, like, a disk file, or even output from another commandA file (the contents of the file are fed

to a program as if you typed it).A pipe (the output of another program

is fed as input as if you typed it).

Page 78: Introduction to Basic Unix

Output Redirection

The shell can attach things other than your screen to standard output (or stderr).A file (the output of a program is

stored in file).A pipe (the output of a program is fed

as input to another program).

Page 79: Introduction to Basic Unix

Redirecting stdout

Use “>” after a command (and its arguments) to send output to a file:ls > lsoutif lsout previously existed it will be

truncated (gone), unless noclobber is set (see bash)

Page 80: Introduction to Basic Unix

Redirecting stdin

To tell the shell to get standard input from a file, use the “<“ character:

sort < nums– Sort the lines in the file nums ,

sends the result to stdout.

Page 81: Introduction to Basic Unix

You can do both!

sort < nums > sortednums

tr a-z A-Z < letter > rudeletter

Page 82: Introduction to Basic Unix

Appending Output

Use >> to append append output to a file:ls /etc >> foo

ls /usr >> foo

Easy way to concatenate files:cat rest_of_file >> my_file

Page 83: Introduction to Basic Unix

Redirecting stderrstderr is file descriptor 2, so:

gcc buggy.c 2> error.log

grep ‘[Vv]era’ *.html > log 2> errorlog

To send both to the same place (stdout is file descriptor 1):

find . -name 'core*' > core.lis 2>&1

Orfind . -name 'core*' 2> core.lis

Page 84: Introduction to Basic Unix

Pipes – connecting processes

A pipe is a holder for a stream of data.A pipe can be used to hold the output of one program and feed it to the input of another.

prog1prog1 prog2prog2STDOUT STDIN

Page 85: Introduction to Basic Unix

Asking for a pipe

Separate 2 commands with the “|” character.The shell does all the work!

ls -1 | sort

ls -1 | sort > sortedlist

ls -1 | sort | head > top.ten

Page 86: Introduction to Basic Unix

The Unix Philosophy

Stringing small utilities together with pipes and redirection to accomplish non-trivial tasks easilyE.g., find the 3 largest subdirectories:$ du –s * | sort –nr | head -n3120180 Files

22652 Zaychik

9472 tweedledee.tgz

Page 87: Introduction to Basic Unix

filtersPrograms that read some input (but don’t change it), perform a simple transformation on it, and write some output (to stdout)Some common filters…wc – word count (line count, character

count)tr – translategrep, egrep – search files using regular

expressionssort – sorts files by line (lexically or

numerically)cut – select portions of a lineuniq – Removes identical adjacent lineshead, tail – displays first (last) n lines of a

file

Page 88: Introduction to Basic Unix

pipes and combining filters

Connect the output of one command to the input of another command to obtain a composition of filters

who | wc -lls | sort -fls -s | sort -nls -l | sort -nr -k4ls -l | grep ‘^d’

Page 89: Introduction to Basic Unix

Process ControlProcesses are run in a subshell (by default)Subshells inherit exported variablesEach process is has an ID (pid) and a parent (ppid)Use the ps utility to look at some processes:$ ps

PID TTY TIME CMD 350 pts/4 00:00:00 bash22251 pts/4 00:00:00 vim22300 pts/4 00:00:00 ps

Page 90: Introduction to Basic Unix

Process Control (cont.)

Use the –f option for a long listing:$ ps –f

UID PID PPID C STIME TTY TIME CMD

kschmidt 350 349 0 10:06 pts/4 00:00:00 -bash

kschmidt 22251 350 0 17:32 pts/4 00:00:00 vim myHomework

kschmidt 22437 350 0 17:36 pts/4 00:00:00 ps -f

Use the –e option to see more processes (all of them).$ ps –e | grep xmms

29940 pts/0 00:33:47 xmms

Page 91: Introduction to Basic Unix

Killing a process (not usually nice)

The kill command sends a signal to a process (the given pid)By default, sends TERM (terminate), which asks the process to finish, so that it may do clean-upuse -9 to send a KILL (won’t be ignored), but no cleanupMy mp3 player hangs once in while:$ kill -9 29940

Page 92: Introduction to Basic Unix

Job Control

The shell allows you to manage jobsplace jobs in the backgroundmove a job to the foregroundsuspend a jobkill a job

Page 93: Introduction to Basic Unix

Background jobsIf you follow a command line with "&", the shell will run the job in the background.you don't need to wait for the job to

complete, you can type in a new command right away.

you can have a bunch of jobs running at once.

you can do all this within a single terminal (window).

ls -lR > saved_ls &

Page 94: Introduction to Basic Unix

Listing jobs

The command jobs will list all background jobs:

> jobs

[1] Running ls -lR > saved_ls &

>

The shell assigns a number to each job (this one is job number 1).

Page 95: Introduction to Basic Unix

Suspending and Resuming the Foreground Job

You can suspend the foreground job by pressing ^Z (Ctrl-Z). Suspend means the job is stopped, but not dead. The job will show up in the jobs output.

You give fg a job number (as reported by the jobs command) preceeded by a %. Without an argument, fg brings the last job forward

$ jobs[1] Stopped ls -lR > saved_ls &$ fg %1ls -lR > saved_ls

Page 96: Introduction to Basic Unix

Placing a suspended job in the background

If it’s in the foreground, suspend itUse bg, just as you did fg, to let a suspended job continue in the background:$ bg %3

Page 97: Introduction to Basic Unix

Killing a job

Kill may also take a job number or even a job name, introduced by %:$ find . –name core\* -print > corefiles &

$ firefox&

$ jobs

[1]+ Running find . –name …

[2]+ Running firefox

$ kill %2

Page 98: Introduction to Basic Unix

EditorsA text editor is used to create and modify text files.The most commonly used editors in the Unix community:vi (vim on Linux)

$ vimtutor

emac $ emacs Then, hit ctrl-h t (that’s control-h, followed by ‘t’)

You must learn at least one of these editors