The majority of computers used in the computer science department run on a kernel called Linux. Unlike traditional operating systems such as Windows, Linux is built on a Unix core. Why should this matter to me?  Being a CS student and not knowing Unix would be like a doctor not knowing anything about the heart. It may not be your specialty, but it is still important.
Unix is inherently modular and as such allows programs to be easily ported, compiled and run. as such a multitude of command-driven programs have been written which will run on any UNIX-like operating system. Mac and Linux are prime examples of UNIX-like operating systems and as such many of the same commands can be used on both systems. These vary greatly from the basic DOS Shell included in MS Windows based OS’s.
A large part of UNIX system’s popularity is the terminal interface used to execute commands. Buckle up, as you will be using the terminal extensively during your university career. Who knows, it may end up being your favourite program!

 

University Computer Systems

Linux is segmented into many sub-classes. These sub-classes are called distributions. Distributions are split upon many different features however a good set of features to split distributions (or distro’s) upon is package management. In the Linux world, there are two main forms of package management. One stems from the Red Hat Distro and uses packages called .rpm’s, the other stems from the Debian distribution and uses .deb packages. The Linux systems in University is called CentOS (CentOS Linux release 6.0 (Final)) and is binary compatible with Red Hat Linux, hence it uses packages in the .rpm format.

 

Choosing your own Linux distribution

It is likely that as a CS student you will have a need to run a Unix OS on your own machine. If you are a Mac user, great, you’re already sorted. If you are coming from the Windows world, I would recommend you choose a Linux distribution and install it locally on your Laptop. This has got a lot easier over the years and is now at a stage that most people’s grandmothers could probably manage an installation. I recommend a guide here which will select an appropriate distro for your needs. As the university systems use .rpm management and CentOS, for 100% compatibility you should go for CentOS however in practise it really doesn’t matter which distro you choose. I am currently running Linux Mint/Mac and I must say, I’ve never had an issue with either (Mac isn’t even based on Linux). Linux Mint is a nice easy drop in Linux system which offers a windows like environment while also offering all the UNIX goodies.

In your Linux travels you may also come across different installation methods with the Ubuntu based distro’s . These will be native install or wubi. I will spend a little time explaining the differences between them.

A native install creates a dual boot configuration. This configuration partitions your Windows Hard drive and creates a Linux Partition and a swap partition. This is the Vanilla install and offers the most speed. At boot time it will give you a menu choice of windows or linux. This is supported by all Linux distro’s. Although better for speed and experience, it also comes with the drawback of being harder to reverse back to a windows only install.

A Wubi install is less persistent. What this install does is it creates a file on your windows computer which is a disk image for Linux. you can boot in and out the same way you would a native install however it is much easier to remove. Wubi can be removed in the same way as any windows program, allowing easy unistallation. Wubi is much better for newcomers to linux as it brings less of a chance to mess up your computer. Wubi will however run slower on your computer due to how it is installed.

 

Terminal

The terminal program is the main underpinning of any UNIX operating system. Here you are able to issue commands to instruct the OS to carry out certain actions. I will detail some of the most basic commands you may use day to day as a CS student.

cd
./
ls
mv
mkdir
cp
rm
!!
chmod
find
grep
man
cd

“cd” changes directory. e.g to move to the ugrads directory at /home/ugrads:

cd /home/ugrads

To go to the home directory use this shortcut:

cd ~/
./

“./” means current directory

“../” means parent directory

Therefore to execure a file called main in the current directory:

./main
ls

The “ls” command is one of the most common commands used. It lists the contents of a directory. Usage is below.

ls

To get a more detailed listing of a directory including permissions, file owners, size and date’s use:

ls -l

You can also add a -h to give a more human readable view of filesizes

ls -lh

You can also show hidden files by adding -a

ls -lah
mv

“mv” is the move command. Much like cut and paste, “mv” will move a file or folder from location1 to location2. It can be used to rename files.

mv location1 location2
mkdir

To create a a directory under the current directory called “java”

mkdir java

To create intermediate directories as required add a -p. e.g:

 mkdir -p ~/java/2012/09/26/src
cp

“cp” is the copy command. It copies a file or folder from location1 to location2

cp location1 location2
rm

“rm” is the remove command. Use with caution. Flags to watch out for are -r and -f.

-r = recursive

-f = forcefully

-rf = recursive forcefully

* = everything

therefore:

rm -rf ./* = remove recursively forcefully everything in the current directory

DO NOT USE THIS COMMAND. I include it so you know to steer clear of it.

To remove a file called main.c from the current directory:

rm ./main.c
!!

“!!” means the same as the previous command.

If I type first:

ls

and then decide I wish to add a -l flag I type:

!! -l

This is the same as:

ls -l
chmod

To understand “chmod” you must first understand Linux user permissions. I reccomend Wikipedia.

Linux has 3 types of permission; User, Group and Everyone.

Owner is your permission on a file or directory

Group is the permission assigned to users in the file or directory’s Group

Everyone is the permission that any user on the system has over the file or directory.

Permissions are octal, the values are:

# Permission rwx
7 full 111
6 read and write 110
5 read and execute 101
4 read only 100
3 write and execute 011
2 write only 010
1 execute only 001
0 none 000

 

To give rwx permissions to Owner, Group and Everyone on someFile or folder:

chmod 777 someFile

To only allow the Owner access read and execute access to a file or folder:

chmod 500 someFile

To give the Owner full access and Group read access:

chmod 740 someFile
I recommend you set your home directory to only allow you access:
chmod 700 -R ~/

The -R makes changes recursively

find

The “find” command finds files in the directory structure. To find all files ending in .c (C source files) in the current directory and below:

find ./ -name "*.c"

To find a file you know the name of (e.g. myAwesomeProgram.o):

find ./ -name "myAwesomeProgram.o"

You can use Regular Expressions to find any file using this style syntax.

grep

“grep” makes heavy usage of Regular Expressions to locate files which contain a match to a given pattern. “grep” searches internally in files.

The usage of grep is as such:

grep "regular expression pattern" locationToFiles

If you know a chunk of text inside a file but don’t know which file contains the text, grep is your new best friend. It’s extremely useful for debugging log files.

e.g. I know there is a C source file which imports stdlib.h in my current folder but can’t remember which file. I search for string “# import <stdlib.h>”. I can use grep to find the location of this file.

grep "#include <stdlib.h>" ./*.c
man

The “man” command is probably the most important command of all. “man” gives you the manual pages for other commands. I have given an extremely brief overview of some useful commands and their usage. Each of these commands can be used in extremely complex ways to solve different problems and can be used together by piping input between commands. If you ever need to reference how to use a particular command just type

man <command>

So to open the manual for grep, type:

man grep

Press the q character to return to the terminal.

 

Text Editors

The war of which text editor is best is a long and everlasting battle. Personally I use nano/pico however every programmer has different preferences. The main ones are:

Terminal:

Graphical:

You will need to make a choice of which editor to use, you will find yourself spending a lot of time coding in this environment. For beginners I would recommend Gedit.

 

Tips/Tricks

This is a small section of standard tricks I use to speed up my life as a Computer scientist. I have only added one trick for now as I’m bored of writing guides however in time I’m sure this section will expand.

.bashrc

The “.bashrc” file is a magical file that is run every time your terminal loads. As such it is a great time saver as you can run certain commands every time you login.

The .bashrc file is located at “~/.bashrc”. It is a hidden file (hence having the full stop in front of it’s name). You can add any command you wish to be run at startup. Please note, on the mac the .bashrc file is replaced with the .bash_profile file.

To add a text based welcome message:

echo "echo Welcome" | cat >> ~/.bashrc

To add a custom ascii art welcome message create a text file filled with ascii art called .art located at ~/.art and type:

echo "cat ~/.art" | cat >> ~/.bashrc

To add aliases add an alias line to the end of the .bashrc file. e.g

echo "alias snowy='ssh username@snowy.cs.bris.ac.uk'" | cat >> ~/.bashrc

You can edit this file manually with a text editor like:

nano ~/.bashrc

 

</end>

Mortensson out 🙂