Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "''Unix is user friendly -- It's just picky about who it's friends are...'' -- Unknown, seen in.sigs around the world."— Presentation transcript:

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

2 Basics of the Unix/Linux Environment Shells and Your Unix Environment

3 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

4 Common Shells sh bash ksh csh tcsh Bourne Shell Bourne Again Shell TENEX C shell C Shell Korn Shell

5 sh Bourne shell the original Unix shell Pro: Flexible and powerful scripting shell Con: Not interactive or particularly user friendly

6 csh C shell designed for the BSD Unix system syntax closely follows C programming Pro: 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

7 ksh Korn shell derived from the Bourne shell so has a shared syntax job control taken from the C shell

8 bash Bourne-Again shell Combines the “best” of sh, ksh, and csh Default shell on Linux and Mac OSX operating systems Pro: Flexible and powerful scripting language with all the interactive features of csh plus command completion This shell is great for complicated GMT scripts

9 tcsh TENEX C shell Default shell of the CERI unix environment Pro: 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

10 What is my shell? env $SHELL will echo your current login shell to the screen to switch your shell in a single terminal window, simply type the name of the preferred shell the command line also usually indicates which shell family you are using $ -- bash, sh, or ksh > or % -- csh, tcsh

11 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 % history 1139 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 % !1139 ls | more | tail -n5 >> directory.list

12 The Unix Environment Mitch 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

13 What are your environment variables? env: prints the current environment variables to the screen

14 HOME & SHELL HOME: 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

15 PATH PATH: 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/bi n:/usr/sbin:/ceri/local/sbin:/gaia/home/stbisrat/bin:/usr/local/bin:/opt/Stu dio/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/bi n/sparc-sun-solaris2.8:/gaia/smeagol/local/bin The : is used to separate each full path name When 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

16 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.

17 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!

18 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!

19 To force your least squares executable in the current (working) directory to run %./ls To force the unix ls command to run %/bin/ls

20 MANPATH MANPATH: 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/G MT4.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

21 HOST & REMOTEHOST HOST: the name of the machine you are currently logged into REMOTEHOST: the name of the machine you are sitting in front of, if different % echo $HOST $REMOTEHOST enigma sailfish2.ceri.memphis.edu

22 SSH Related Variables SSH_CLIENT: the IP (internet protocol) address of the HOST machine SSH_CONNECTION: the IP address of the HOST machine and the REMOTEHOST machine % echo $SSH_CLIENT $SSH_CONNECTION 141.225.156.223 52372 22 141.225.156.223 52372 141.225.157.75 22

23 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.

24 set set: sets csh shell variables A 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

25 setenv setenv: 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

26 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

27 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

28 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)

29 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

30 PATH=/usr/local/sod-2.2.2/bin:$ANTELOPE/bin:$PATH export PATH. bashrc

31 some warnings If 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!

32 Aliases alias: creates a pseudonym or nickname for a common command or series of commands Anything you find yourself typing repeatedly can be set to an alias Anything you find yourself frequently mis-typing can be set to an alias unalias: unset the alias alias and unalias can be run within a terminal window for short-term usage or set in your configuration files for long-term usage

33 Aliases examples alias 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

34 Source source: executes configuration files If 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


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

Similar presentations


Ads by Google