2.18. Configuring the Look-and-Feel

In this section, we are going to finish setting up your scientific computing environment with a couple final items.

2.18.1. Video for this section

Video for the section is here

Note that once you start the video, a Table-of-Contents icon appears on the bottom right control bar (between the Volume and Fullscreen icons), allowing your to jump to sections in the video.

2.19. Shared Folders

Your scientific computing environment runs in its own world–a VirtualBox VM (Virtual Machine). While this system shares many things with your host computer at the hardare level, it doesn’t have access to your Windows or Mac files.

One of the nice features of installing the VBox Guest Additions is that you can set up shared folders between you VM and your Host OS. That way, you can use your computer as you normally would, say, read an email from your lab partner with an attached data file from the experiment you did together, save it to your Desktop, and then access that file in the VM and unleash your scientific unix tools on it.

The following instructions will show you how to set up a shared folders linking your “Desktop” and “My Documents” folders to your unix environment.

  • Start the VirtualBox program, but Don’t Start your Fedora Scientific VM.

Before you start your VM, highlight it, and click Settings, then click Shared Folders at the bottom of the left side menu.

In the dialog box that appears, you should see a small blue folder and green plus on the right side; Click the +/Folder.

../_images/sharedfolders1m.jpg

A dialog appears called “Add Share”. Click the dropdown arrow at the right side of the “Folder Path:” textbox. Click the “Other” folder icon.

../_images/sharedfolders2.jpg

In the box that pops up, “Desktop” should be at the top (browse to find it, if Desktop is not at the top of this list). Highlight “Desktop” to choose it, then click “OK” at the bottom of the dialog box.

../_images/sharedfolders3.jpg

This will fill in the fields of the “Add Share” dialog box. Be sure that you check the Auto-mount check box, and click “OK”.

You should see the “Path” to your Desktop folder (C:/Users/jhetrick/Desktop for me), Yes for Auto-mount, and Full under Access.

../_images/sharefolders4m.jpg

Repeat the above process exactly, but instead of choosing “Desktop”, this time choose “my Documents”.

../_images/sharedfolders5.jpg

Remember to check “Auto-mount”. At the end, the Shared Folders dialog window should look like this:

../_images/sharedfolders6.jpg

While you still have the Settings dialog window open, click General on the left menu, then click the Advanced tab.

On this tab, find Shared Clipboard, and choose Bidirectional from the dropdown list.

../_images/shareclipboard1m.jpg

Do the same with Drag and Drop; choose Bidirectional.

../_images/shareclipboard2.jpg

This will allow you to use the Edit->Copy/Paste feature on each application window to copy/paste material from your Host system to your Linux system.

Now click OK until you are are back to the main VirtualBox program window.


  • Start your Fedora Scientific VM, and login normally.

2.20. Terminal/Shell Startup Configuration: the .bashrc file

Click the Terminal icon you added to the Panel in the last section. It’s the little black “TV set” term on the right of the Panel (the “Task Bar”) which should be at the top of your screen.

We met the Terminal in the previous section. When you start it up, it opens a text-based window (i.e. not a button and menu GUI application; google “GUI” if you don’t know what it means).

The Terminal is ancient. It comes from time before we could talk with computers, before you could touch the screen to make your choice, before we carried computers in our pockets, even before you you could point at things on the screen with a mouse.

The Terminal comes from the Time of the Mainframe, when the computer was an enormous Machine housed in a large room which was modified to handle the huge power consumption and wiring. On every user’s desk was a Terminal, a little TV and a keyboard. The Terminal allowed users to sent text to the Machine, and receive text back, which was displayed on the screen of the little TV. We still have such Machines, now called supercomputers.

../_images/terminal1.jpg

The Terminal is just the TV. The program that runs in the Terminal is called “The Shell”. There are many different unix shells; please read http://en.wikipedia.org/wiki/Unix_shell .

In this course we will be using the Bash shell. The shell is a program that reads the text you enter at the prompt, and interprests the commands, and carries them out. In the last section, we met the shell, the prompt, and a couple of commands (among them: ls, pwd, cd, and su).

The Prompt is the small line of text that looks like this:

[jhetrick@localhost ~]$

This is the shell telling you that it’s waiting for you to type a command and hit ENTER. In fact, we’ll change this rather generic prompt soon. For now, we have a few commands to issue in order to complete the customizations, before we study the shell in more detail.

When you first start the Terminal, which then starts the Shell, it looks for a special, hidden file, named .bashrc. This is a simple text file where you place configuration commands that will customize the behavior of the shell for you, as well as extend its functionality. For example, most people put aliases (shorthand names) for common commands.

I have prepared a simple .bashrc file for you with a few configuration lines. Once you feel proficient at unix, you can edit and change this file to your liking. Searching the web, you can find many (complex!) examples of .bashrc files that people use and have shared.

To use my .bashrc file, you must first get it.


We first have to get this file onto your VM. So, of course, we’ll just download it, but not through a browser.

I’m assuming you have have your VM up and running, and you are logged in. If not, do so.


Now, let’s see an example of how powerful the shell is.

Open a Terminal and at the prompt, copy/paste (or type) the following text (exactly):

curl -O dirac.physics.pacific.edu/phys/jhetrick/www/PHYS27/.bashrc

Note

If you set up Bidirectional Clipboard Sharing (above), you should be able to simply cut and paste the link above into the Firefox browser textbox.

Here we are using the program curl (Command line URL), which when you hit ENTER, goes out into the internet and grabs the URL you asked for. It is insanely powerful. The -O switch (more about switches later) lets you configure curl’s behavior at the command line. If you want you can tell curl to get a webpage , and then read that webpage for URLs, get those, and then read those...etc. Yeah, that’s pretty powerful.

If things worked, curl should have responded with something like this:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100  1716  100  1716    0     0  83958      0 --:--:-- --:--:-- --:--:-- 86052

In particular you should see the Total Downloaded Size as 1716 bytes (second number).


Click the [X] button on the Terminal window to close it. Then, click the Terminal icon on the panel to open a new Terminal.

Now when the shell starts, it reads and executes the .bashrc file, and you should see a little message and a new prompt, like this:

Initializing from ~/.bashrc
     >- path
     >- prompt
     >- aliases
User jhetrick - Welcome to the Machine
sci[~]>

Now we are ready to to do some science!


2.21. Examine .bashrc

First, let’s look at the file you just grabbed. To do this, we’ll use less, a file pager/viewer. We’ll learn more about this and other commands in the next chapter, but for now, just type

less .bashrc

at the prompt in your shell window, then ENTER (from now on, if I say “type something at the prompt”, you will know that you follow that with ENTER, right?).

This will display the contents of the file .bashrc, which should look like the following.

To “page through” the file, go forward to the next page of text by hitting the SPACE bar. To go back and view the previous page, hit the b key.

#
# .bashrc initialization file
#
# This file created by Dr. J. Hetrick
# for PHYS 27/193 Introduction to
# Scientific Computing
#
# v. 4.0 Nov 2014

# Source global definitions
if [ -f /etc/bashrc ]; then
   . /etc/bashrc
fi


echo "Initializing from ~/.bashrc"

# --- setup PATH to executables
# if you want to add a directory to the
# PATH you add it at the end, with a :

export PATH=".:$PATH:$HOME/bin"

# -----------------------------
echo "     >- path"


# --- setup BASH SHELL --------
# You can set the prompt to something useful by
# setting the variable PS1.
# \h means "Hostname" (the name of your computer
# \w means "working directory"

# This prompt has your hostname in it, useful
# when you are on different machines and want to
# know which one you are working on. However I've
# "commented it out" of this file by putting #
# in front of it.
#PS1="\h[\w]>"

# We can use this prompt for our Scientific VM
# It will have the working directory inside the []
# and I like a > for a prompt.

PS1="sci[\w]>"

# -----------------------------
echo "     >- prompt"


# --- Put aliases here -------

alias l='ls -F'
alias la='ls -aF'
alias ll='ls -lF'
alias lla='ls -alF'
alias lsd='ls -lF | grep "^d"' # only directories
alias m=less
# this function lists the 20 most recently changed files
function lt() { ls -lFt "$@" | head -20 ;}

# ----------------------------
echo "     >- aliases"


# ----------------------------
# comment this out if too cheezy for you :)
# by putting a # at the front. Notice it
# echos the value of the USER environment variable

echo "User $USER - Welcome to the Machine"

First, every line that begins with a hash (#) is a comment. It will not be read as a command, but rather is there solely for the reader.

After the top comment block describing the file, there is an if statement:

if [ -f /etc/bashrc ]; then
   . /etc/bashrc
fi

This command effectively says “if there is a system bashrc (``/etc/bashrc``) file, read and execute its commands first”.

Next comes some comments about the PATH, and this command:

export PATH=".:$PATH:$HOME/bin"

This command adds the current folder (.) and a bin subfolder to the PATH–a colon (:) separated list of folders in which the shell should look for executable programs.

Next, we change the prompt to something friendlier. The default prompt is: [user@localhost ~]$.

I prefer the following:

sci[~]>

What this does is let you know that you are currently logged into your Scientific environment (which we’re going to call sci). Since I often login to other machines around the world via the terminal (and start a shell on that machine), I always put the same .bashrc file on the remote machine, except that I change the name in the prompt to the name or location of that machine, like dirac[~]> or hawaii[~]>.

Additionally, this prompt shows that you are currently working in your Home directory (or folder), which has a nickname: ~ (the tilde).*Folders* (where files are stored) in Unix are called Directories. I will use the two terms interchangably, and you will get used to it. Just remember:

Note

Directory = Folder

If you cd to another directory, such as your Pictures directory (do this now, by typing cd Pictures), you should see that the prompt changes to

sci[Pictures]>

Did it? To move back to your Home directory, all you have to do is type cd (+ ENTER), and your prompt should return to

sci[~]>

In this little exercise, in addition to learning how to move around a little, you’ve learned that the tilde–in the context of directories–is a shorthand name for Your Home (or Default) Directory.

Note

~ = your Home (default) directory


After setting the prompt (by defining the variable PS1=”sci[w]>”), the .bashrc file contains alias definitions.

alias l='ls -F'
alias la='ls -aF'
alias ll='ls -lF;
...

These are short hand names for common commands. As you already learned the ls command lists the contents of a directory. You can change it’s behavior by adding switches, various letters prepended by a minus sign (like -F, -alqF, -O, etc.).

For example, at your prompt, type ls.

Now type a single l (ell). It should show roughly the same thing, except that in the latter case, you typed the alias for ls -F. The -F switch tells ls to “format” the output, by adding a trailing slash to directories, so that it is easier to distinguish them from simple files.

Now type ll (ell ell). This version gives much more detail: permissions, owner, group, size, date, etc. This is called a “long listing” and hence the alias ll.

Similarly, la will show ALL files, including hidden ones that start with a dot. Try it: type

la

2.22. Fixing the Shared Folders

When you booted your VM, the Shared Folders we created at the beginning of this document were “mounted (attached to the file system) in a special system directory, /media to be specific, and they were created by the root user. We have a couple things to do to make life easier.

First, in your Terminal, type

cd /media

then

ll (ell ell) to do a long listing the contents of above directory.

You should see

sci[/media]>ll
total 56
drwxrwx---. 1 root vboxsf  8192 Nov 10 10:19 sf_Desktop/
drwxrwx---. 1 root vboxsf 49152 Nov 10 16:18 sf_Documents/

This tells us that there are two directories: sf_Desktop/ and sf_Documents/. I like to use the trailing / to help you get used to that meaning these are directories, not files.

the first part of each line for these directories shows the type of object (file, directory, or other) and the permissions.

drwxrwx---

means that this thing is a directory (d), and that the Owner (denoted by the first rwx) has read, write, and execute privledges. The second rwx says that the Group has r,w,x, privledges. This means that, like the Owner of the object, anyone in the file/directory’s Group can read, write (i.e. modify), or execute (in the case of a program) that file. For Directories, x permission means that that group or person can cd into the Directory.

We then see that the Owner is root, and the Group for the file is the vboxsf Group.

drwxrwx---. 1 root vboxsf  8192 Nov 10 10:19 sf_Desktop/

Try to cd into the sf_Desktop directory. Do:

cd sf_Desktop

You should get an error telling you that you don’t have the correct permission to do so.

sci[/media]>cd sf_Desktop
bash: cd: sf_Desktop: Permission denied

Ouch!


One solution:

You could simply become the root user everytime you want to cd into this directory. You would first do su (change to superuser account), issue the root password, then as root, cd sf_Desktop, but this is way cumbersome.


A better solution:

It’s far easier just to add you to the vboxsf Group. Then you would have the correct privledges to cd into sf_Desktop.

However, only root has high enough privledges to edit your Group affiliations on the Machine. So, to make this change, you do have to become root. But just this once.


The best solution: Do this:

In some previous exercises, you became root by typing the su command, and giving the root password. This basically stops your shell program (the one that started with you as the user when you clicked the Terminal icon), and starts a new shell in the same Terminal, but this time logged in as root. You get a prompt like this: [root@localhost /media]#, and you have complete control of the machine.

There is a better way to do administrative activities which require root access, by using the sudo (super user do) command. The difference is that with the root shell (and a prompt [root...]#) anything you type will be carried out as the root user.

Using sudo, you are only able to issue one command at a time. When we set up your user account, we checked “Make this user an Administrator” (didn’t we...??).

Type the following, substituting your username for YOURUSERNAME (my YOURUSERNAME = jhetrick, so I would type sudo usermod -aG vboxsf jhetrick):

sudo usermod -aG vboxsf YOURUSERNAME

The sudo command will first ask to be sure that you are you: it will ask for YOUR password (not the root password). This is so that, while you were out in the kitchen grabbing another beer, your evil roomate does not come in, and seeing that you have an open Terminal and Shell running, issue a sudo command to erase your hard drive (it could happen).

This command then adds you to the Group vboxsf, but the change doesn’t take effect until you login again

Instead of shutting down your whole VM machine and rebooting, you only need to Logout, then Login again.

../_images/sfdir3.jpg

Go ahead and Logout/Login. Then open a Terminal.


In your fresh Terminal window, cd to the /media directory

cd /media

List the contents of the directory with an l.

Now try to cd into the sf_Desktop directory.

Do a listing there by typing l

Do you see the things on your Desktop in that list? Here’s mine.

../_images/sfdir5.jpg

While you have your Terminal running, type a lone cd (no target directory after it) to get back to your Home directory.

Here we want to make two “Symbolic Links” to the Shared Folders we made. Then you won’t have to cd to the /media directory every time. There will be shortcuts in your Home directory. To make these, type the following commands in the terminal, in your Home directory.

ln -s /media/sf_Desktop winDesktop

ln -s /media/sf_Documents winDocs

(if you are on a Mac, you can use “macDesktop” and “macDocs”)

These lines start with ln (lowercase L N, for link), and the command makes shortcuts called winDesktop and winDocs. Do an l to list the contents of your Home directory. Do you see these links? How are they designated so you can tell them from normal files?

Do cd winDesktop

Then l

Do you see your Windows (or Mac) Desktop contents?

../_images/sfdir7.jpg

2.23. Fonts and Colors

Finally, I like to play with the font and color a little. This customization is completely up to you.

To change the font that the Terminal uses, go to the very top of the window and click “Settings”, then click “Edit Current Profile”.

../_images/terminalConfig2m.jpg

You can change almost everything about the Terminal, and I recommend staying away from everything but font and color.

../_images/terminalConfigm.jpg

Click the “Appearance” tab and play around with the options. You can always click “Cancel” to go back to what it was before. If you move the “Edit Profile” window to the side, you can see the effect of your choices on the Terminal. Personally, I like a bold, 11 point, Monospace font, in a stark White-on-Black color scheme. But my eyes are old and need the print to pop.


You are now ready to start using your scientific computing environment.

2.24. Homework

Homework 2 is here