"two of the most famous products of berkeley are lsd and unix. i don't think that this is...

25
"Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence .” Anonymous

Upload: liliana-gray

Post on 25-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

"Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.”

Anonymous

Page 2: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Basics of the Unix/Linux

EnvironmentCommon Commands

Page 3: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Making directoriesmkdir: make directory

% mkdir bin src Projects Classes

Makes 4 directories: bin, src, Projects, and Classes in the working directory.

Page 4: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Removing Directoriesrmdir: remove directory; only works with empty

directories but is safe% rmdir bin src Projects Classes

Removes the 4 directories bin, src, Projects, and Classes in the working directory -- if they are EMPTY.

Page 5: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Removing files and directories

rm: remove files and directories; a very straightforward and DANGEROUS command

There is no trash can on a unix machine.

CERI accounts are set up so that rm is aliased to rm –i, which means the computer will ask you if you really want to remove the file(s) one at a

time

%which rm

rm: aliased to /bin/rm –i

Page 6: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

%rm file1

remove file1? yes

%

Valid answers.

Yes, yes, Y, y – to accept and erase.

No, no, N, n – to not erase.

<CR> - does not erase.

Something it does not understand – does not erase.

Page 7: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

rm –d: remove directory like rmdir

rm –r: remove directory and all subdirectories and files; implies –d; can be very dangerous… one typo could remove months of files

% rm -r Classes

\rm: You can return to the original definition of rm using the “\”. You will no longer be prompted before a file is removed so don’t make a typo

Page 8: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Looking at filesmore: browse or page through a text file;

opens file quickly and pages down full screen; use space bar to page down

less: same as more but allows forward and backward paging; in OSX, more is aliased to less because less is more with additional features

Page 9: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Looking at files continuedhead -nX: prints the first X number of lines to

the screen; default is 10 lines if -n is not specified

tail -nX: prints the last X number of lines to the screen; default is 10 lines if -n is not specified (mac/linux)

tail -Xf: prints the last X number of lines to the screen; default is 10 lines if -f is not specified (ceri suns)

Page 10: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Manipulating filescat: concatenate files into a single column; it dumps the

entire file contents to the screen unless redirected to a file

o Since it dumps the entire file contents to the screen, we can use it to “print out” or ”type out” a file.

%cat dead.letter

Hello...testing

Another Unix philosophy issue – use of side effects.

We don’t need another command to print or type the contents of a file to the screen as it is a side effect of the

cat command.

Page 11: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Example: make one file out of file1, file2 and file3 and call it alltogether.

%cat file1 file2 file3 > alltogether

or

%cat file1 file2 file3

This command (does not need input redirection, exception to regular rule that input comes from Standard IN) takes files file1, file2, and file3 and puts them into file alltogether or you can skip creating the file alltogether

Page 12: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Creating files using cat - type the command

%cat > name_of_file

Now type in your text. Press the <Return> key to start a new line. When you have finished typing in your text, enter Ctrl-d (Press and hold down the Ctrl key and type a "d"). This stops the cat command and returns you to the system prompt.

%cat > test.fileHello everyone<CR>CNTL-D%more test.file

Hello everyone

Page 13: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

paste: concatenate files with each file a new column; when used on a single file, it dumps the entire file contents to the screen

Page 14: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Piping and RedirectInput and output on the command line are

controlled by the |, >, <, and ! symbols

| : pipe function; sends the output from command on left side as input to the command on the right side

% cd SACdata% ls | head -n51002

1019

1023

1045

1046

Page 15: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Piping and Redirect> : redirect standard output (screen) to a specific file*

% cd SACdata% ls | head -n5 > directory.list% more directory.list1002

1019

1023

1045

1046

* In tcsh, this will not overwrite a pre-existing file with the same name. In bash shell, the > overwrites any pre-existing file with no warning

Page 16: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Piping and Redirect>! : redirect standard output (screen output) to a

specific file and overwrite the file if it already exists *

% ls | head –n5 >! directory.list% more directory.list1002

1019

1023

1045

1046

*This syntax is specific to tcsh, your default CERI shell; in bash this will put the output into a file named !

Page 17: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Piping and Redirect>> : concatenate standard output (screen output) to

the end of a specific file

% ls | head –n2 >! directory.list% ls | tail –n2 >> directory.list% more directory.list1002

1019

tmp

tmp.file

< : redirect file on right as input to command on the left

% head –n1 < suma1.hrdpicks 1 51995 31410273254 30870 958490 297

Page 18: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Copying, moving, or linking files & directoriescp: copy files

cp -r: copy directory and all files & subdirectories within it

% cp file1 Project/SUMATRA/file2

% cp file1 Project/SUMATRA/.

Page 19: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

mv: move files or directories

% mv file1 file2 Project/SUMATRA/.

If you want to change the names when you move them, you have to do them one at a time

% mv file1 ESCI7205/HW/HW1

% mv file2 ESCI7205/HW/HW2

Page 20: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

ln -s: create a symbolic link between two files

% ln –s sourcefile1 Project/SUMATRA/targetfile1

% ln –s sourcefile1 Project/SUMATRA/.

This makes the file show up in the new directory (the target) listing, but the file really only exists in the original place.

Page 21: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

WildcardsWildcards all you to match multiple instances of

characters/numbers in file or directory names

They can be used in combination with almost all unix commands

Wildcards are essential when dealing with large amounts of geophysical data

Page 22: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Wildcards* : represents zero or more characters or numbers

% ls 2/*.BHZ.*2/HIA.BHZ.SAC 2/WMQ.BHZ.SAC

2/filt.HIA.BHZ.SAC 2/filt.WMQ.BHZ.SAC

% ls 2/f*.BHZ.*2/filt.HIA.BHZ.SAC 2/filt.WMQ.BHZ.SAC

? : represents a single character or number

% ls 2/HIA.BH?.*2/HIA.BHE.SAC 2/HIA.BHN.SAC

2/HIA.BHZ.SAC

Page 23: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

Wildcards[] : single placeholder used to specify a range

of characters or numbers rather than all possible characters or numbers

% ls 2/HIA.BH[E,N,Z].*2/HIA.BHE.SAC 2/HIA.BHZ.SAC

2/HIA.BHN.SAC

% ls */HIA*198[0-9]*795/HIA.BHZ.D.1988.041:07.18.30

799/HIA.BHZ.D.1988:14:35:27.00

812/HIA.BHZ.D.1988:03:43:49.00

813/HIA.BHZ.D.1988.362:13.58.59

814/HIA.BHZ.D.1989.041:17.07.43

Page 24: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

CNTL-CUse CNTL-C to quit a job

If you accidently start something that isn’t working, CNTL-C will quit and return you to a blank command line

Page 25: "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

See this link for a list and description of many Unix

commands

http://pcsplace.com/tech-list/ultimate-list-of-linux-and-unix-commands/