Thursday, 20 October 2011

Working with directories


Once we are in a terminal in a Linux setting, it is no longer a point and click interface for making folders or moving files into folders. In a Windows setting, it has a graphical user interface (GUI) and it is easy to visualize where the folders are and is easy to move folders around. They use the term folder because it comes from putting files into folders.

In a Linux setting, we use the term directory which has exactly the same meaning as folder. In a Linux setting, there is a GUI but terminals are used more often. Furthermore, once we ssh into another machine, we only have a terminal. Therefore, it is useful to know how to make directories and how to move between directories in a terminal.

As mentioned in the previous post, making a directory is fairly simple which is mkdir name (ex. mkdir Project). However, we need to consider where we want to create before making one. A question arises how to get there.

For example, in your machine, you have the following directory structure.

  • /
    • home
      • Jinny
Suppose you are in the root directory and you want to go to the home directory. You can simply do cd home because the home directory is right below the root directory. Now, you are inside the home directory. If you want to make another directory called Guest inside home directory, then you can do the following: mkdir Guest. It will look like

  • /
    • home
      • Jinny
      • Guest
After making the Guest directory, you can get into the Guest directory by using the cd command (cd Guest). You can use cd .. if you want to go back to the parent directory of Guest which is home. The command cd .. brings you back to the parent directory. There is another command cd ../.. at which the first ../ brings you one level up and the second .. brings you another level up. For example, you are inside the Guest directory and you want to go to the root directory. Using cd ../.. will brings you back to the root directory.

There are two types of paths we can consider when moving around: absolute path and relative path. Absolute path always starts from the root to where you want to go and it doesn’t matter where you are currently located. For example, if you are inside the Jinny directory and you want to be in the Guest directory, you can use an absolute path and type cd /home/Guest. One advantage of the absolute paths is you don’t need to know where you are now. From anywhere, the absolute path of the destination is always the same. By the way, if you want to check where you are, you can use the command pwd which shows the path of the working directory.

Contrast to the absolute path, the concept of relative path is where the destination directory is relative to where I am right now. For example, if you are inside the Jinny directory and you want to go to the Guest directory, you can use relative path and type cd ../Guest. The first ../ makes you get out of the Jinny directory and the second Guest makes you go into the Guest directory. One advantage of relative paths is you can type less. However, you need to think about how the destination is related to where I am now.

Thursday, 13 October 2011

How to ssh in Linux and Windows


I am going to talk about how to ssh in Linux and in Windows. ssh is a tool for connecting to another computer (usually called a remote computer). For more information about ssh, go to http://en.wikipedia.org/wiki/Secure_Shell. I am currently using Ubuntu, but I am still a beginner terminal user. Ubuntu is really good for beginners like me because it provides a point and click interface so it is easy to use.

I am currently a research assistant under a business professor. The data I am dealing with is enormous and I need to estimate about 3200 parameters using MCMC. Unfortunately, I only have a laptop with 2 cores and 1 GB of memory. It is not a good idea to run such a huge job on my laptop. I need computing power to run my job! Fortunately, my supervisor has a remote computer which has 8 cores with 16 GB of memory and I can use his computer. That’s how I learnt ssh.

Linux
I am surprised that ssh in Linux is fairly simple. This is how to do it:
1. open the terminal (Ctrl + Alt + t)
2. write “ssh username@address -p port number”
ex) ssh jinny@xxxx.xxx.xx -p 0000
if there is no port, then just ignore the -p part
3. The password may be required.

That’s it. Now you are in the remote computer. It’s that simple!

Windows
For Windows, ssh is not provided so you should download it. You can download “PuTTy” here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

1. open PuTTY and press the run button (then you can see the PuTTY configuration)


2. type the host name in the Host Name section with the port number
3. select the connection type as SSH
4. click open

Now you are in the remote computer.

Once you ssh, you are in the Linux machine, so the following commands are used in a Linux setting.


DescriptionCommand line
change passwordpasswd
listls
create foldermkdir folder name (ex. mkdir Project)
change directorycd directory name  (ex. cd Project)
change to the parent directorycd ..
delete a filerm filename (ex. rm test.r)
delete a folderrm -r filename (ex. rm -r Project)
move filesmv (file you want to move) (to where)
copy filescp (file you want to move) (to where)



I did not write examples for move files and copy files because it requires some knowledge about relative paths and absolute paths. I will write about this concept in the next blog post.

Sunday, 2 October 2011

Welcome to my blog!

Let me introduce myself briefly. My name is Jinny and I am a master student in the department of Statistics and Actuarial Science at Simon Fraser University. I am interested in Bayesian statistics and I want to share my problems, findings and knowledge with you. This blog is somewhat informal in a way that I just want to explore some stuff related to statistics. So, please correct me or comment if you find some mistakes or concerns.

The reason why I am writing this blog is because I want to improve my writing skill and want to keep my works somewhere that I can later easily access. Also, I want to share my problems and findings with people who are interested in the statistical field. It is always good to have some positive or negative feedback.

I have some background in computer science because I took some courses in Python and Java but I should say that I am not good at programming. However, I need to know some basic programming skill for my career. Statistics is highly related to computers recently because computer power is improving. As a result, we can now collect millions of data everyday. In statistics, we use the programming language R and SAS mostly. I heavily use R rather than SAS. I feel SAS is like a black box or canned product and I am not comfortable using it. But don't get me wrong. In some situations, using SAS rather than R saves me time.

I learnt R myself. I did a research assistance project about the average weight of BC pink salmon using MCMC. I built the MCMC code in R and learnt a lot of the structure and syntax of the programming language R. It is a pain in the ass that R does not have a debugger so it is not very clear when there is an error in the program. But again, it is very flexible to write code so you can figure out or rewrite it.

I hope that this blog is a tool for communicating different ideas of the problems that I have!