basics of the unix/linux environment

Post on 22-Feb-2016

61 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Basics of the Unix/Linux Environment. File Permissions and Text Editing. Dealing with file names with special characters. - PowerPoint PPT Presentation

TRANSCRIPT

Basics of the Unix/Linux

EnvironmentFile Permissions and Text Editing

Dealing with file names with special characters

Say I have a file named “!”. (this is probably because I used >! at some time while in bash, but this syntax is for tcsh not bash, so I redirected my output to a file called !)

%ls !!%rm !remove !? Y

What about a file named “-”?

Make a file named “-” with touch command(use man to see what the touch command does)

%touch -%ls- f2.dat HW

Try to remove it.%rm - usage: rm [-fiRr] file ...

What is the problem? (you tell me.)

We have to let the shell know that the “-” is NOT a switch.

Use the “-” switch all by itself.%rm - -rm: remove - (yes/no)? yalpaca.ceri.memphis.edu193:>

Remember that filenames can have any character but the “/” (used to define the path), so sooner or later you are going to get a file name that will be hard or dangerous to reference.

You will have to be especially careful/creative if you get a file named “*” as%rm *

is disastrous(and the more privileges you have and the higher up you are in the directory structure, the more disastrous it is.)

OwnershipUser

the person who created or is in charge of the file/directory (u)

Groupa group of users that can be associated with the

file/directory (g)

Othersany user not part of the User or Group designation (o)

PermissionsRead

ability to read the file/directory (r)

Writeability to write or overwrite the file/directory (w)

Executeability to execute or run the file and view directories (x) if a directory is not executable, you cannot cd into it or see

what is in it at all.

Viewing ownership & permissions

ls -l: lists long format

% ls -aFl *pl bin | head -n 10

-rw-r--r-- 1 hdeshon user 42 Aug 20 13:47 helloworld.pl standard permissions

-rwxr-xr-x 1 hdeshon user 1276 Aug 7 2007 res2sacfiles.pl* preferred executable permissions

bin: used to store executable scripts and programs for global access

total 40722drwxr-xr-x 3 hdeshon user 3584 Aug 1 13:50 ./ standard directory

permissionsdrwxr-xr-x 41 hdeshon user 2048 Aug 21 10:07 ../-rwxr-xr-x 1 hdeshon user 13508 Aug 1 13:50 addcglags*-rwxr-xr-x 1 hdeshon user 1155 Aug 1 13:50 addnoise*-rwxr-xr-x 1 hdeshon user 49152 Aug 1 13:50 ah2asc*

Changing owners and groups

If you create a file, you are the owner/user.

Mitch and Bob have the system set up to automatically set group to ‘user’, or all users of the CERI unix system.

Default for CERI files are rw-r--r-- otherwise known numerically as 644

Changing Permissionschmod: change file or directory permissions

%chmod ugo+x helloworld.pl%ls –lF helloworld.pl

-rwxr-xr-x 1 hdeshon user 42 Aug 20 13:47 helloworld.pl*

%chmod go-rx helloworld.pl%ls –lF helloworld.pl

-rwx------ 1 hdeshon user 42 Aug 20 13:47 helloworld.pl*

–R flag allows you to set all files to the same permissions within a directory and all subdirectories

Changing Permissionsyou can also use numbers to change ownership

644 represents u+rw; g0=r755 represents u+rwx; go=rx #I use this one a

lot

%chmod 775 helloworld.pl%ls –lF helloworld.pl

-rwxr-xr-x 1 hdeshon user 42 Aug 20 13:47 helloworld.pl*

Text Editing OptionsMouse-driven options

nedit: this GUI text editor allows interactive mouse or keyboard driven text manipulation; colored text and auto-recognition of various standard scripting and programming languages is helpful for debugging scripts and code; appears to be a student favorite at CERI and is available on the Unix system

emacs: a less sleek looking GUI text editor allows interactive mouse or keyboard driven text manipulation; it is very powerful and is an old favorite of computer programmers

Text Editing OptionsKeyboard-driven options

vim: this non-GUI text editor relies primarily on keyboard driven text manipulation; steep learning curve but very powerful; colored text and auto-recognition of various standard scripting and programming languages is helpful for debugging scripts and code; my personal favorite

pico: a pared down non-GUI text editor very similar to the email program pine. If you don’t know what pine is, use nedit instead.

OK, nedit or vimnedit is available on the CERI unix machines because

Bob and Mitch have installed it nedit has a shallow learning curve

vim is available standard on all unix and unix-like systems

vim is harder to learn

*note to OSX users, nedit can be downloaded and installed on OSX. Xcode is a similar but more powerful editor for code development.

NEditto start it up

%nedit & an & placed at the end of a command line opens the program in the background so that you can continue to use the terminal window.

This is what it looks like

vimto start it up

%vim [name-of-file]

Two modesnormal/command modeinsert/input mode

Typing takes place in insert mode and the editing power comes to the fore in normal mode

Use esc to toggle out of insert mode

moving the cursoresc

0$ ^

$ -- go to end of line (eol)0 -- go to beginning of line (bol)^ -- go to first character at bol

^f -- scroll screen forward ^b -- scroll screen backwards

type esc to enter normal mode

^

^control key

^f

^b

to enter insert modeesc

s

I,i

A,a

i -- inserta -- appends -- substitute

A -- append at end of lineI -- insert at beginning of line

type esc to exit insert mode

deleting textesc type esc to enter normal

mode

dd

x -- delete character behind cursorX -- delete character in front of cursor

dw -- delete worddd -- delete lineXdd -- delete next X lines

X,x

dw

copy, paste, undo and redo

esc type esc to enter normal mode

p

yy -- copy the line (yank)yw -- copy the word (yank)p -- paste the line or word after the cursor

u -- undo change

U -- undo all changes to the line^R -- redo change. -- repeat last command

U,uyyyw ^R

^

^control key

control key .

search and replaceesc type esc to enter normal

mode

/

/[word(s)] -- search for the next instance of the word or words n -- go to next instance of word or words:s/[old]/[new] -- substitute old with new string; cursor is on old string:g/[old]/s/[old]/[new]/g -- globally find old, substitute all old with new

n

:s/ return:g/ :

saving and exiting vim

ZZ

:w:q

:w [filename] -- write to file:w! [filename] -- overwrite file:wq -- write and quit

:q --- quit:q! --- quit without savingZZ -- write and quit

esc type esc to enter normal mode

:

shift shift

return

other useful features:![unix command] -- allows you to run standard unix commands

without exiting vim; very useful with GMT

Example :!ls *.SAC list all sac files in the current directory

:set hlsearch -- will highlight all instances of a string when using /[word] to search

>aB -- indent the block/loop defined by {} when cursor is located within the block in question

:sp -- split the screen

^WW -- use to move from one split screen to the next; useful when writing subroutines within the same

file

: set number or :set nonumber -- turn line numbers on/off

:X -- jump to line number X example :1 go to first line of file

top related