------------------------------------------------------------------------- PHYS210 2009-09-15 LAB SUMMARY Homework directories, Startup Files, Aliases ------------------------------------------------------------------------- 1) THE /phys210 DIRECTORY AND YOUR SUB-DIRECTORY WITHIN IT Login and locate your personal directory within the /phys210 directory % cd /phys210/your-login-name or % cd /phys210/$LOGNAME The latter command will work for everyone. NOTE! In the following, whenever you see something that you are to type that includes $LOGNAME, you can replace $LOGNAME with your login (account) name The instructor will be doing this demo as user 'phys210t' % pwd /phys210/phys210t Get a long listing of the directory % ls -lt drwx------ 2 phys210t ugrad 4096 2009-09-15 11:08 hw1/ drwx------ 2 phys210t ugrad 4096 2009-09-15 11:08 hw2/ drwx------ 2 phys210t ugrad 4096 2009-09-15 11:08 hw3/ drwx------ 2 phys210t ugrad 4096 2009-09-15 11:08 hw4/ drwx------ 2 phys210t ugrad 4096 2009-09-15 11:08 hw5/ drwxr-xr-x 2 phys210t ugrad 4096 2009-09-15 11:08 public_html/ Note the permissions on hw[1-5], NO access except by user (i.e. you). Please keep them that way. Change to the public_html directory, When *you* type pwd following execution of the cd command, you should see /phys210/$LOGNAME/public_html % cd public_html % pwd /phys210/phys210t/public_html Get a directory listing, should be a single file 'index.html' % ls index.html View the contents of the file: in your case you should see the text $LOGNAME % cat index.html phys210t You will be replacing/modifying index.html in Problem 2 of Homework 1. Access /phys210/$LOGNAME/public_html/index.html using a browser. Point the browser to (note the use of the ~ (tilde)) http://laplace.physics.ubc.ca/~$LOGNAME e.g., in my case http://laplace.physics.ubc.ca/~phys210t Again, you should see the text $LOGNAME in the browser window. ------------------------------------------------------------------------- 2) INSTALLING THE DEFAULT 210 BASH STARTUP FILES Change to your home directory % cd Look for the following files .bash_profile .bash_login .profile .bashrc .aliases using % ls .bash_profile % ls .bash_login % ls .profile % ls .bashrc % ls .aliases For any that exist, and unless you're a Linux expert and you know what these files do, and you're happy with their contents, then move them as follows, and as necessary, using one or more of the following mv commands *** % mv -i .bash_profile .bash_profile.O % mv -i .bash_login .bash_login.O % mv -i .profile .profile.O % mv -i .bashrc .bashrc.O % mv -i .aliases .aliases.O In the highly unlikely case that any of the .O files already exist, then back *them* up using, for example % mv -i .bashrc.O .bashrc.OO, and re-execute % mv -i .bashrc .bashrc.O Now copy the PHYS 210 default startup files from the phys210 account to your home directory. Don't confuse phys210's home, referred to as ~phys210 or /home/phys210 with the /phys210 directory discussed in 1. and in which you will do your homework! Again, ensure that you are in your home directory. When *you* type pwd following execution of cd, you should of course see /home2/$LOGNAME % cd % pwd /home2/phys210t Do the copying, AND BE CAUTIOUS; i.e. use the -i option to cp. If cp prompts you to confirm overwrite then you have NOT mv'ed the original file(s) per the above instructions, so go back to *** above and try mv'ing the file(s) again. % cp -i ~phys210/.bashrc . % cp -i ~phys210/.profile . % cp -i ~phys210/.aliases . Now start up a new terminal window and display the aliases that are defined % alias # You should see output like the following alias CP='/bin/cp' alias LN='/bin/ln' alias MV='/bin/mv' alias RM='/bin/rm' alias a='alias' alias cp='cp -i' alias hi='history' alias ln='ln -i' alias ls='ls --color=auto -CF' alias maple='maple32' alias mv='mv -i' alias rm='rm -i' alias xmaple='xmaple32 -cw' Display your path: /home2/$LOGNAME/path should appear in it, as well as '.' (the current directory) which means the shell will always look in the current directory for commands to execute % echo $PATH .:/home2/phys210t/bin:/home/phys210/bin:/etc:/usr/etc:/usr/ucb:/bin:/usr/bin:/usr/local/bin As alternative way to display the value of the PATH environment variable % printenv PATH .:/home2/phys210t/bin:/home/phys210/bin:/etc:/usr/etc:/usr/ucb:/bin:/usr/bin:/usr/local/bin ------------------------------------------------------------------------- 3) DEFINING ALIASES Add a new alias to your ~/.aliases file It's a bit inconvenient to have to type % cd /phys210/$LOGNAME/hw1 to get to your Homework 1 directory, so let's define an alias that will take you there with less typing First, cd to your home directory, and make a back up copy of your ~/.aliases file (making back ups before you start modifying important files is an extremely good habit to develop!) % cd % cp .aliases .aliases.O And verify that you *do* have a back ups, as well as the original % ls .aliases .aliases.O .aliases .aliases.O Now, open ~/.aliases (/home2/$LOGNAME/.aliases) with your text editor of choice, and add the following four lines at the end of the file (if you're having trouble opening /home2/$LOGNAME/.aliases, ask for help!) #----------------------------------------------------------------------- # Define an alias to cd to Homework 1 directory #----------------------------------------------------------------------- alias cdhw1="cd /phys210/$LOGNAME/hw1" Once you have (carefully!) entered these 4 lines, save the file---your editor may prompt you to confirm overwrite of the existing file /home2/$LOGNAME/.aliases, but since you have a back ups, it's safe to do the overwriting. Note that due to the use of double quotes in the alias definition (we'll discuss this in a future lecture), you can use either $LOGNAME literally, or use your actual login (account) name. Now source ~/.aliases to "activate" the new alias ... % source ~/.aliases ... verify that 'cdhw1' *has* been defined as an alias ... % alias cdhw1 alias cdhw1='cd /phys210/phys210/hw1' ... and try it out % cdhw1 % pwd /phys210/phys210t/hw1 ------------------------------------------------------------------------- 4) EXERCISE! Add additional alias definitions to ~/.aliases to change to your 2nd through 5th homework directories, as well as to cd to /phys210/$LOGNAME/public_html. When you're done, be sure to source ~/.aliases, or start a new terminal window, and check that your new definitions have been made and work. IMPORTANT!! DON'T FORGET TO MAKE A BACK UP OF ~/.aliases BEFORE YOU START MODIFYING IT. This may mean overwriting the old back up, but if everything so far has worked as advertised, that should be OK. ------------------------------------------------------------------------- 5) EAGERLY START WORKING ON HOMEWORK 1! In principle, at this point you should be able to complete Problems 1 and 2, although you may have to do a little supplementary study via web resources, using the help facility or other documentation for your text editor of choice etc.