Lecture 2 Unix Basics Corpus Linguistics Fall 2004 © Kevin Cohen.

Post on 11-Jan-2016

213 views 0 download

transcript

Lecture 2Unix Basics

Corpus LinguisticsFall 2004

© Kevin Cohen

Last time

• ssh –l my_name babel.colorado.edu

(connect with babel)• pwd (where am I?)• ls (what’s here?)• cd (I want to go somewhere else)• mkdir

Switches: Unix adverbs

• options that you specify• ls –l: long listings• ls –a: show hidden files, too• ls –t: sort by time• ls –lat: show all files, in long

format, sorted by time

Switches

Arguments: objects

• No argument allowed:– pwd

• Argument required:– mkdir

[kev@compbio kev]$ mkdirmkdir: too few argumentsTry `mkdir --help' for more information.[kev@compbio kev]$

Arguments

• Argument(s) optional:– cd (no arg—what happens?)– cd .. (arg is ..—what happens?)

Arguments

• Argument(s) optional:– cd (no arg—what happens?)– cd .. (arg is ..—what happens?)– ls (no arg—what happens?)– ls .cshrc (arg is .cshrc)

Arguments

• Argument(s) optional:– cd (no arg—what happens?)– cd .. (arg is ..—what happens?)– ls (no arg—what happens?)– ls .cshrc (arg is .cshrc)babel>ls .cshrc

.cshrc

babel>ls i_like_my_dog

i_like_my_dog not found

File named .cshrc exists

File named i_like_my_dog doesn’t exist

Wildcards

• Underspecified objects• Syntax: combine with any amount

of the name of an argument• Examples:• ls ling*• ls linguistics*• ls *linguistics

Wildcards

• Underspecified objects• Syntax: combine with any amount

of the name of an argument• Examples:• ls ling*• ls linguistics*• ls *linguistics

Semantics: “allow zero or more of any character(s) here”

Show me:

ling

linguist

linguistics

babel>pwd /home/kev/demo_wildcardsbabel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>ls ling

ling

babel>ls ling*

ling

linguistic_anthropology

linguistic_phonetics

linguistics

linguistics_and_the_law

linguists

babel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>ls linguist*

babel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>ls linguist*

linguistic_anthropology

linguistic_phonetics

linguistics

linguistics_and_the_law

linguists

babel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>ls *linguistics

babel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>ls *linguistics

linguistics

psycholinguistics

sociolinguistics

babel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>ls *ics

babel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>ls *ics

linguistic_phonetics

linguistics

phonetics

psycholinguistics

sociolinguistics

babel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>ls *and*

babel>lslinglinguistic_anthropologylinguistic_phoneticslinguisticslinguistics_and_the_lawlinguistsmorphologyphoneticspsycholinguisticssociolinguistics

babel>ls *and*

linguistics_and_the_law

Switches + Arguments

• You can combine them. – Switches come first.

• ls –lt li*• “List everything that starts with li

followed by zero or more of any other character…

• …show me the “long” version…• …and arrange them by “time.”

Two ways of specifying location

• Relative: walk out the door. Take stairs to first floor. Exit building from east. Take 36 to I-70. Get off at Vasquez exit. Merge onto Colorado. Turn left onto 23rd. Turn right onto Krameria. Go to next block. Go to house on southwest corner.

Two ways of specifying location

• Relative: walk out the door. Take stairs to first floor. Exit building from east. Take 36 to I-70. Get off at Vasquez exit. Merge onto Colorado. Turn left onto 23rd. Turn right onto Krameria. Go to next block. Go to house on southwest corner.

• Absolute: Go to 2089 Krameria St., Denver, CO.

I’m in /home/kev, and I want to see the contents of /home• Using relative

path:

ls ..

• Using absolute path:

ls /home

I’m in /home/kev, and I want to see the contents of

/home/jurafsky• Using relative

path:

ls ../jurafsky

• Using absolute path:

ls /home/jurafsky

/

bin home etc usr

otherfolks

jurafskykev

More things you can do with files

• View their contents• Copy• Rename/move them • Delete them• Count contents• Compare their contents

Please open a terminal and ssh to

babel

Viewing file contents

• The whole thing at once• The whole thing, a bit at a time• Just part of it

Viewing file contents

• The whole thing at once• cat filename• Example:• cd• ls -a• cat .cshrc

Viewing file contents

• The whole thing, a bit at a time• more filename• Example:• ls /corpora/celex/english• more /corpora/celex/english/README

Viewing file contents

• Just some of it (just the beginning)• head filename• head –number_of_lines filename• Example:• head /corpora/celex/english/README• head –20 /corpora/celex/english/README

Viewing file contents

• Just some of it (just the end)• tail filename• tail –number_of_lines filename• Example:• head /corpora/celex/english/README• head –20 /corpora/celex/english/README

Copying: cp

• A ditransitive verb• cp original_file new_file• Example:• cd• cp .cshrc .cshrc_bak

Caution: no guardrails

• touch junk• cat junk• cp .cshrc junk • cat junk

Moving/renaming: mv

• A ditransitive verb• mv original_file new_file• Example 1:• cd• ls• mv .cshrc.bak .cshrc_bak01

Moving/renaming: mv

• A ditransitive verb• mv original_file new_file• Example 1:• cd• ls• mv .cshrc.bak .cshrc_bak01

Renames the file

Moving/renaming: mv

• A ditransitive verb• mv original_file new_file• Example 2:• cd ling5200• ls• mv ../junk .

Moving/renaming: mv

• A ditransitive verb• mv original_file new_file• Example 2:• cd ling5200• ls• mv ../junk .

Moves the file from parent

to current directory

Moving/renaming: mv

• A ditransitive verb• mv original_file new_file• Example 3:• cd ling5200• ls• mv ../junk mango

Moving/renaming: mv

• A ditransitive verb• mv original_file new_file• Example 3:• cd ling5200• ls• mv ../junk mango

Moves from parent to current directory

and changes name

man pages

• Unix’s help facility• Syntax: man command_name• E.g.: man cp

To see more, hit the spacebar

Comparing files: diff

• A ditransitive verb• diff one_file another_file• Example 3:• cd ling5200• diff ../junk mango• touch junk• diff junk mango

man pages

• Name• Synopsis of syntax• Description• Options

man pages

Remember you said you’d like cp to ask you before it blew

away your file?

• Consult the man page for cp• Make a back-up copy of your .cshrc file

(cp .cshrc .cshrc.bk01)• Open it in a text editor (emacs .cshrc)• Create an alias for cp• Ctrl-XS Ctrl-X Ctrl-C• Tell Unix about your new alias

(source .cshrc)

Interlude

HW1

1. Well?

HW1 #1

“He has all of the primary facts that he needs, in the form of a corpus of approximately one zillion running words, and he sees his job as that of deriving secondary facts from his primary facts. At the moment he is busy determining the relative frequencies of the eleven parts of speech as the first word of a sentence versus the second word of a sentence.”

--Fillmore

HW1 #1

He sits in a deep soft armchair, with his eyes closed and his hands clasped behind his head. Once in a while he opens his eyes, sits up abruptly shouting, ‘Wow, what a neat fact!’, grabs his pencil, and writes something down…having come still no closer to knowing what language is really like.”

--Fillmore

HW1 #1

• Why should I think anything you tell me is true?

• Why should I think anything you tell me is interesting?

HW1 #1

“They [take] this to be science, very genuinely and very sadly.”

--Postal

HW1 #1

• Rationalism as theory, yes—method, no (Sampson)

• “I don’t think there can be any corpora, however large, that contain information about all of the areas of English lexicon and grammar that I want to explore…[but] every corpus I have had the chance to examine, however small, has taught me facts I couldn’t imagine finding out any other way.” (Fillmore)

HW1

5. ssh

Some important Unix concepts

• Redirection• Security/permissions• Environment

Piping and redirection

• Piping: sending the output of one command to another command as its input

cat .cshrc | wc

Use the output of

that…

…as the input for this

Piping and redirection

• ls –l /corpora2• ls –l /corpora2 | head• ls –l /corpora2 | head -5

Piping and redirection

• Redirection: sending output someplace other than to your screen

ls –l /corpora2 > corpora2_contents

Put the output of

this command

…into this file

Piping and redirection

• If the file doesn’t already exist…• If the file does already exist…• >>• cat .cshrc > junk• ls –lt /corpora2 >> junk

No space!

LINGUIST-L

Position Description:

Primary responsibility is the creation and maintenance of linguistic test data. This involves analyzing a set of sentences and generating the expected linguistic analysis based on the specification. Other responsibilities include evaluating linguistic coverage, reporting accuracy, generating linguistic bugs, and tracking regression of the products and technology.

Security

• passwd: change your password– no real words– mix case (E.g. M!nkeY, not m!nkey)– mix letters, other symbols (@rm3n!an)– change frequently– nothing obvious (chomsky, phonology,

birthday, cat’s name)– DON’T email them

Security

You

Security

You

...Z

Y

X

Security

students

...

staff

Permissions

File Directory

r •view•copy

list contents

w •change•delete

•create•delete

x execute cd into

Security

• Permissions

“-” means file

“d” means directory

you

(user)

Security

• Permissions

“-” means file

“d” means directory

Security

• Permissions

“-” means file

“d” means directory

you

(user)

group

Security

• Permissions

“-” means file

“d” means directory

you

(user)

group

others (world)

Changing permissions

• Easy way: chmod who+/-what filename

• Who:– u: user (you)– g: group– o: other (world)

Changing permissions

• Easy way: chmod who+/-what filename• Who:

– u: user (you)– g: group– o: other (world)

• What:– r: read– w: write– x: execute

Changing permissions

• Easy way: chmod who+/-what filename• Who:

– u: user (you)– g: group– o: other (world)

• What:– r: read– w: write– x: execute

chmod u+x helloWorld.pl

Changing permissions

• Easy way: chmod who+/-what filename• Who:

– u: user (you)– g: group– o: other (world)

• What:– r: read– w: write– x: execute

chmod u+x helloWorld.pl

chmod go-w helloWorld.pl

Changing permissions

• Medium: chmod u=rwx,g=r,o=r hello.pl• Who:

– u: user (you)– g: group– o: other (world)

• What:– r: read– w: write– x: execute

chmod u+x helloWorld.pl

chmod go-w helloWorld.pl

Changing permissions

• Hard: chmod 744 helloWorld.pl• Who:

– First digit: user (you)– Second digit: group– Third digit: other (world)

• What:– 4: read– 2: write– 1: execute– 0: nothing

chmod u+x helloWorld.pl

chmod go-w helloWorld.pl

Environment

• uname• echo $SHELL• echo $PATH• setenv• setenv DUMMY_VARIABLE melgibsonsux• echo $DUMMY_VARIABLE