unix is user friendly -- it's just picky about who it's friends are...'' --...

34
''Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Upload: dudley

Post on 25-Feb-2016

37 views

Category:

Documents


0 download

DESCRIPTION

''Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world. Basics of the Unix/Linux Environment. Shells and Your Unix Environment. What is a shell?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

''Unix is user friendly --It's just picky about who it's friends are...''-- Unknown, seen in .sigs around the world

Page 2: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Basics of the Unix/Linux

EnvironmentShells and Your Unix Environment

Page 3: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

What is a shell?Traditional user interface with the unix

operating system…it interprets your typing

A scripting program that controls the syntax at the command line interface

Just as there are many flavors of unix and unix-like systems, there are many types of shells

Page 4: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Common Shells

BourneShell

Bourne Again Shell

TENEXC shell

C ShellKornShell

Page 5: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

shBourne shellthe original Unix shellPro: Flexible and powerful scripting shellCon: Not interactive or particularly user friendly

Page 6: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

cshC shelldesigned for the BSD Unix systemsyntax closely follows C programmingPro: easy for C programmers to learn and comes

with many interactive features such as file completion and aliases

Con: not as flexible or powerful a scripting language

Page 7: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

kshKorn shellderived from the Bourne shell so has a shared

syntaxjob control taken from the C shell

Page 8: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

bashBourne-Again shellCombines the “best” of sh, ksh, and cshDefault shell on Linux and Mac OSX operating

systemsPro: Flexible and powerful scripting language

with all the interactive features of csh plus command completion

This shell is great for complicated GMT scripts

Page 9: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

tcshTENEX C shellDefault shell of the CERI unix environmentPro: User friendly on the command line & it is

what your CERI account environment is set up to use

Con: It is not as suitable for long and involved scripts

It is perfectly good for most daily geophysics work on the command line & most faculty here use it on a daily basis so there are many experts around

Page 10: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

What is my shell?env $SHELL will echo your current login shell to

the screento switch your shell in a single terminal window,

simply type the name of the preferred shellthe command line also usually indicates which

shell family you are using$ -- bash, sh, or ksh> or % -- csh, tcsh

Page 11: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Useful features of tcsh & bash

file completion: you can key the tab button to complete the name of a long file

history: list the previous commands entered during the active session

% history1139 11:19 ls | more | tail -n5 >> directory.list

up and down arrow keys: allow you to move up and down through previous commands

right and left arrow keys: allow you to edit command lines without starting from scratch

!XXX: reruns the command labeled XXX in the history list% !1139ls | more | tail -n5 >> directory.list

Page 12: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

The Unix EnvironmentMitch has set up the basic CERI environment so

that everyone can access the standard geophysics packages available on the Sun system

But what does this mean?your environment is composed of a number of

environment variables which provide important information to the operating system

since you generally want the computer to behave the same way everyday, these environment variables are setup in configuration files accessed at login

Page 13: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

What are your environment variables?

env: prints the current environment variables to the screen

Page 14: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

HOME & SHELLHOME: this environment variable controls what

other unix commands consider your base or home directory

this is how “%cd “ knows which directory to go to% echo $HOME/gaia/home/hdeshon

SHELL: this variable stores your default shell% echo $SHELL/usr/bin/tcsh

*these environment variables should not be changed by the user

Page 15: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

PATHPATH: tells the shell where to find applications and/or

executable files%echo $PATH

/gaia/smeagol/local/passcal.2006/bin:/gaia/smeagol/local/gmt/GMT4.2.1/bin:/opt/local/bin:/opt/local/sbin:/opt/csw/bin:/opt/csw/sbin:/ceri/local/bin:/usr/sbin:/ceri/local/sbin:/gaia/home/stbisrat/bin:/usr/local/bin:/opt/Studio/SUNWspro/bin:/opt/Studio/SUNWspro/prod/bin:/opt/sfw/bin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/bin:/usr/ucb:/usr/ccs/bin:/usr/local/teTeX/bin/sparc-sun-solaris2.8:/gaia/smeagol/local/bin

The : is used to separate each full path nameWhen a command is called from the command line,

the shell will search through this list of paths, in order, until it finds the first instance

Page 16: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

How does PATH work?If you are working a program to do least squares

analysis and decide to call it “ls,” what will happen when you enter the command “ls”?

It depends on your PATH variable.When the shell goes looking through your path for

an executable file named “ls”, it will run the first one it finds.

Page 17: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

If the directory containing your least squares program (executable file), “ls”, is in your path

Before

the directory containing the Unix list command, “ls”, it will run your program and you will not be

able (at least simply) to get a listing of your directory!

Page 18: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

If the directory containing your least squares program, “ls”, is in your path

AFTER

the directory containing the Unix list command, “ls”, it will run the Unix ls command and you will

not be able (at least simply) to run your program!

Page 19: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

To force your least squares executable in the current (working) directory to run

%./ls

To force the unix ls command to run

%/bin/ls

Page 20: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

MANPATHMANPATH: tells the shell where to find the manual

pages read using the man command

%echo $MANPATH

/gaia/smeagol/local/passcal.2006/man:/gaia:smeagol/local/gmt/GMT4.2.1/man:/opt/local/man:/ceri/local/man:/usr/dt/man:/usr/man:/usr/openwin/share/man:/usr/local/man:/opt/SUNWspro/man:/opt/sfw/man:/usr/local/teTeX/man:/gaia/smeagol/local/man:/opt/csw/man

If you do a man on a command and the shell can’t find a manual page (and you are sure the man page exists), this environment variable may not be set correctly

Page 21: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

HOST & REMOTEHOSTHOST: the name of the machine you are

currently logged intoREMOTEHOST: the name of the machine you

are sitting in front of, if different

% echo $HOST $REMOTEHOSTenigma sailfish2.ceri.memphis.edu

Page 22: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

SSH Related VariablesSSH_CLIENT: the IP (internet protocol) address of

the HOST machineSSH_CONNECTION: the IP address of the HOST

machine and the REMOTEHOST machine

% echo $SSH_CLIENT $SSH_CONNECTION141.225.156.223 52372 22 141.225.156.223 52372 141.225.157.75 22

Page 23: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Modifying your current shell environment

If you mess up modifying the environment in your current window – you may “break” your current window (shell).

This is generally not a problem on the sun, mac, etc.

The environment is local to that window/shell.

Just close it and open another window.

Page 24: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

set

set: sets csh shell variablesA typical tcsh set command is

%set history=100 This would save the last 100 commands on the history

list.

The bash equivalent is simply%history=100

Page 25: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

setenvsetenv: the csh command to change

environment settings.

% setenv PATH {$PATH}:/gaia/home/hdeshon/scripts this adds the directory ‘~/scripts’ to the end of the

environment variable PATH within the active window

The bash equivalent is simply%PATH=$PATH:/gaia/home/hdeshon/scripts

Page 26: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

setenv can be run on the command line, from within a local configuration file (.cshrc or .login), or in a shell script.

When run without specifying an environment variable, it will print all environment variables to the screen

Page 27: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Making your own environment variables

• Anytime you want a global definition of something, you can create your own global environment variable

%setenv LATESTRTVEL rtvel4_9305_5bv19

Page 28: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Modifying your default environment

It will get old changing everything to the way you want it each time you log in/open a new window/start a new shell. And this being Unix, there is a (easy) way to set up your own personal environment.

The setup of your personal environment (personal changes/preferences for how you want the shell to work for you) is stored in shell configuration files, aka dot files

.cshrc or .bashrc

There is also a file .login, but it is not likely you will have to change it (it get’s used when you log in, not each time you start a shell)

Page 29: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

setenv PATH ${PATH}:/gaia/home/hdeshon/scripts

setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/gaia/home/hdeshon/fftw-2.1.5/lib

setenv PRINTER 3876_grad

set filec #explicitly turns on file completion

set noclobber #turns on no clobber, which keeps redirect > from #overwriting files unless the ! is specified

set history=500 #keep the last 500 commands in the history list

alias l 'ls -F'

.cshrc

Page 30: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

PATH=/usr/local/sod-2.2.2/bin:$ANTELOPE/bin:$PATH

export PATH

.bashrc

Page 31: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

some warningsIf you need to modify your environment

configuration file (.cshrc, .bashrc), do so with care

Always leave two terminal windows open (prior to making any changes) in case you mess your file up so completely and break your active window, you have another window open to delete the offending file

Always backup the file you before modifying it!

Page 32: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Aliasesalias: creates a pseudonym or nickname for a

common command or series of commandsAnything you find yourself typing repeatedly can

be set to an aliasAnything you find yourself frequently mis-typing

can be set to an alias

unalias: unset the aliasalias and unalias can be run within a terminal

window for short-term usage or set in your configuration files for long-term usage

Page 33: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Aliases examplesalias settitlebar 'echo -n "^[]2;$CWD^G"'

alias cwdcmd 'set PROMPT="[${USER}@`hostname`] $CWD% "'

alias cd 'chdir \!* && cwdcmd && settitlebar’

alias howmuch 'du -sk .’

alias h 'history’

alias m more

alias mroe more

alias l 'ls -F'

alias c clear

alias src source

Page 34: Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in .sigs around the world

Sourcesource: executes configuration filesIf you change your configuration file, you will need to

execute the changes in all open terminal windows for the changes to take effect. They automatically will take effect when new terminal windows are opened.

%nedit ~/.cshrc you’ve used NEdit to make file changes

%source ~/.cshrc