25.10.2014 Views

Introduction to Bio-Linux

Introduction to Bio-Linux

Introduction to Bio-Linux

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Introduction</strong> <strong>to</strong> <strong>Bio</strong>-<strong>Linux</strong><br />

Logging in and exploring the desk<strong>to</strong>p<br />

You can log in<strong>to</strong> your <strong>Bio</strong>-<strong>Linux</strong> machine locally or remotely. Today you are logging on<strong>to</strong> a machine locally,<br />

which means that the moni<strong>to</strong>r you are looking at is attached directly <strong>to</strong> the machine running the system. You may<br />

also hear this referred <strong>to</strong> as logging in at the console.<br />

Log in using the username and password you have been given.<br />

The view you now see is referred <strong>to</strong> as the desk<strong>to</strong>p.<br />

Exercise<br />

Take some time <strong>to</strong> explore the desk<strong>to</strong>p. Look at what options are available under the menus, what clicking the<br />

icons on the desk<strong>to</strong>p does, etc. Also try using the right and middle mouse but<strong>to</strong>ns when the mouse pointer is over<br />

a blank area of the desk<strong>to</strong>p and explore the menus presented <strong>to</strong> you.<br />

At the right hand side of the <strong>to</strong>olbar on the bot<strong>to</strong>m of the screen are 4 “virtual desk<strong>to</strong>ps”. These effectively give<br />

you 4 times the working space of your moni<strong>to</strong>r. Try going <strong>to</strong> a different virtual desk<strong>to</strong>p and starting up some<br />

windows/applications there.<br />

Click on the icon for your “home” at the <strong>to</strong>p left of the screen. The file manager that appears is a graphical<br />

representation of your files, similar <strong>to</strong> what you might see on a Mac or PC. Leave this window open for the next<br />

part of the practical.<br />

How <strong>Linux</strong> and Unix files are organized<br />

Your <strong>Bio</strong>-<strong>Linux</strong> machine can be thought of as a huge file folder, inside of which are many other file folders, and<br />

inside these are more nested file folders, and so on. As in the real world, file folders can hold other file folders, or<br />

documents/files.<br />

Terminology alert: In <strong>Linux</strong> /Unix systems, documents are usually referred <strong>to</strong> as files, and file folders are referred<br />

<strong>to</strong> as direc<strong>to</strong>ries.<br />

The graphical representation of your account can be a good initial way <strong>to</strong> visualise what folders and documents<br />

you have, and <strong>to</strong> move around in your account. However, as you grow more comfortable with <strong>Linux</strong>, you may<br />

begin <strong>to</strong> find it slow and unnecessary. It is a good way <strong>to</strong> learn about the overall filesystem of the machine<br />

though!<br />

Your account is one direc<strong>to</strong>ry (file folder) within your <strong>Bio</strong>-<strong>Linux</strong> system. In it you can create other direc<strong>to</strong>ries,<br />

s<strong>to</strong>re data, run programs, etc.<br />

Just like with a regular filing cabinet, if you threw all your documents in without any ordering or organisation, it<br />

would rapidly become difficult <strong>to</strong> find things. The same thing will happen <strong>to</strong> your account if you choose <strong>to</strong> keep<br />

all your documents in your home direc<strong>to</strong>ry instead of creating subdirec<strong>to</strong>ries and s<strong>to</strong>ring associated data <strong>to</strong>gether<br />

within them.<br />

If you look at the graphical representation of your home direc<strong>to</strong>ry – you should see the following next <strong>to</strong> the word<br />

location:<br />

1


home/user1<br />

The name of the base file folder, the one within which everything else is, is “/”, usually referred <strong>to</strong> as the “root<br />

direc<strong>to</strong>ry”.<br />

/home<br />

/home/user<br />

home is a file folder located within the root direc<strong>to</strong>ry<br />

user is a file folder within the direc<strong>to</strong>ry home which is within the root direc<strong>to</strong>ry<br />

All the direc<strong>to</strong>ry names are separated with a forward slash – so the direc<strong>to</strong>ry user1 is located within the direc<strong>to</strong>ry<br />

home, which is within /.<br />

The real power on <strong>Linux</strong>/Unix systems is the command line. You usually access the command line from within<br />

terminals.<br />

You can open a terminal by:<br />

• clicking on the icon on the <strong>to</strong>p <strong>to</strong>ol bar<br />

• right-clicking on the desk<strong>to</strong>p and choosing the menu option “New terminal”<br />

• or by going <strong>to</strong> the Utilities option under the Programs drop down menu, and choosing Terminal<br />

You can also start new terminals by typing their name on the command line. There are in fact a number of<br />

different types of terminals – each type has its own idiosyncrasies. The terminals brought up by clicking on the<br />

terminal icon are called “gnome-terminals”. You can start one from the command line by typing:<br />

gnome-terminal &<br />

The & allows you <strong>to</strong> keep working in the original window by starting up the process, (in this case, a gnometerminal),<br />

and putting that process in the “background”. If you want <strong>to</strong> know more about this, please ask a<br />

demonstra<strong>to</strong>r.<br />

Listing files in a direc<strong>to</strong>ry<br />

Use the ls command <strong>to</strong> list files in a direc<strong>to</strong>ry<br />

By default, the command will list the filenames of the files in your current working direc<strong>to</strong>ry. At the moment, this<br />

is your home direc<strong>to</strong>ry.<br />

If you add a –l after the ls command, it alters the behaviour of the command – it will now list the files in your<br />

current direc<strong>to</strong>ry, but with details about them including who owns them, what the size is, what kind of file it is,<br />

etc.<br />

There are many options that modify what information is returned by ls. To find out about them, you can refer <strong>to</strong><br />

the manual pages for this command by typing:<br />

man ls<br />

By giving the name (or full path) of a direc<strong>to</strong>ry you wish <strong>to</strong> list the contents of, you can find out what is in<br />

direc<strong>to</strong>ries other than the one you are running your command from.<br />

ls /usr/local/bin<br />

ls –lR /usr/software<br />

2


You can also use regular expressions <strong>to</strong> limit the files you wish <strong>to</strong> list.<br />

* means any character<br />

? means a single character<br />

[ ] can be used <strong>to</strong> designate a group of characters<br />

Exercise<br />

List the files in your current direc<strong>to</strong>ry. Compare this <strong>to</strong> what you see in the file manager.<br />

List the files in your current direc<strong>to</strong>ry with full details.<br />

List all the files in the direc<strong>to</strong>ry intro_pract. Click on the icon for the intro_pract direc<strong>to</strong>ry in the file<br />

manager and compare the output of the ls command <strong>to</strong> what you see.<br />

List all the files in the direc<strong>to</strong>ry intro_pract. that start with the letters tes<br />

ls intro_pract/tes*<br />

List all the files in your direc<strong>to</strong>ry that start with tes, and end in 1.embl, 2.embl or 3.embl<br />

ls intro_pract/tes*[1-3].embl<br />

Changing the look of the terminal<br />

If you don’t like the colour scheme of the terminal you are working in, you can change it using the Preferences<br />

option under the Settings menu on the terminal.<br />

Exercise<br />

Go <strong>to</strong> the Preferences option under the Settings menu on the terminal. Choose the panel Colours, and then<br />

choose the colour scheme you want. Please note that the option “black on white” actually produces black on grey.<br />

To get black print on a white background, choose Cus<strong>to</strong>m Colours and choose the colours you want.<br />

After this, any new terminal you open will inherit your new colour scheme.<br />

Pressing the right hand mouse but<strong>to</strong>n can bring up menus of options for the terminal you are working in.<br />

You can close terminals by typing exit on the command line or choosing Exit under the File menu.<br />

There is also a menu under the tiny icon <strong>to</strong> the left of the word Terminal at the <strong>to</strong>p of your terminal window. Try<br />

out some of the options. Try choosing the option Sticky under Toggle. This makes that terminal appear in every<br />

virtual desk<strong>to</strong>p, instead of just one desk<strong>to</strong>p. Note: please use the exit options mentioned above <strong>to</strong> close your<br />

terminal, rather than the Close option in this menu.<br />

3


File naming conventions<br />

a.) Certain characters should not be used in filenames in <strong>Linux</strong>/Unix.<br />

If you stick with letters, numbers, hyphens, underscores and full s<strong>to</strong>ps, you will be fine.<br />

b.) <strong>Linux</strong>/Unix cannot deal with spaces in filenames!<br />

Make sure your filenames do not contain them.<br />

Filenames with spaces in them are a common problem when transferring files <strong>to</strong> <strong>Linux</strong>/Unix from a computer<br />

running Windows, or Mac operating systems.<br />

If you end up with filenames with spaces in them, you will need <strong>to</strong> enclose the entire filename in quotation marks<br />

so that <strong>Linux</strong>/Unix understands that the space is part of the name.<br />

Alternatively, you can “escape” the space using a backslash. For example, if I have a file called<br />

my document<br />

<strong>Linux</strong>/Unix will see this as two filenames, “my” and “document”.<br />

But you could write either of the following <strong>to</strong> make it understand you mean a single file:<br />

“my document”<br />

my\ document<br />

We advise that you change the name of such files <strong>to</strong> remove the space. A common practice is <strong>to</strong> replace the space<br />

with an underscore. E.g.<br />

mv “my document” my_document<br />

Keeping points a and b in mind, the files in your account can be named whatever you like.<br />

If you have a lot of files with names including spaces in your account on your <strong>Bio</strong>-<strong>Linux</strong> machine (or which you<br />

will be moving in<strong>to</strong> your account), then please get in <strong>to</strong>uch with us – we may be able <strong>to</strong> help you au<strong>to</strong>mate the<br />

renaming of these files.<br />

Having said this, please note that there are common naming conventions in place that you should try <strong>to</strong> follow.<br />

More is said on this in the bioinformatics practical.<br />

4


Basic commands<br />

It is possible for users <strong>to</strong> achieve a great deal with only a small number of commands.<br />

Ana<strong>to</strong>my of a Command<br />

<strong>Linux</strong>/Unix commands usually take the form:<br />

command<br />

parameters arguments<br />

what I want <strong>to</strong> do how I want <strong>to</strong> do it on what do I want <strong>to</strong> do it<br />

You have already seen a command with this structure when you used ls with the parameter l and the argument of<br />

a file or direc<strong>to</strong>ry name.<br />

ls -l intro_pract<br />

Some commands may not need parameters or arguments, or will use defaults if nothing is specified, but most will<br />

have options available <strong>to</strong> you if you choose <strong>to</strong> use them.<br />

For example, just typing ls will list the contents of the current direc<strong>to</strong>ry.<br />

If a command is executed without any problems, it will usually not report anything back <strong>to</strong> you, (unless reporting<br />

<strong>to</strong> you was the purpose of the command!). If the command does not execute properly, you will often see an error<br />

message returned. Whether or not the error is meaningful <strong>to</strong> you depends on what your level of experience with<br />

<strong>Linux</strong>/Unix is and how user-friendly the errors generated by that command were designed <strong>to</strong> be.<br />

<strong>Linux</strong>/Unix shorthand and shortcuts<br />

At first understanding example <strong>Linux</strong>/Unix commands can seem daunting. This is often due <strong>to</strong> shorthand that can<br />

be employed when using commands. However, the common shorthand characters are very useful.<br />

The following incomplete list covers the symbols you will see most often <strong>to</strong>day and describes their meanings as<br />

you will most likely encounter them in this course.<br />

Warning: some symbols have different meanings depending where they are used,<br />

A short incomplete list includes:<br />

* matches any character appearing 0 or more times, also known as a wildcard<br />

ls mydir/* list all the files under the direc<strong>to</strong>ry mydir<br />

ls cat* list all files starting with the letters cat<br />

5


ls cat*hat<br />

list all files starting with the letters cat and ending in hat<br />

? matches a single character<br />

ls cat??hat list all files starting with the letters cat followed by any 2 letters, and then hat<br />

. “the direc<strong>to</strong>ry I am currently in”<br />

.. the direc<strong>to</strong>ry one level above<br />

~ my home direc<strong>to</strong>ry<br />

~username<br />

the home direc<strong>to</strong>ry of the user username<br />

Changing direc<strong>to</strong>ries<br />

The command used <strong>to</strong> change direc<strong>to</strong>ries is cd<br />

If you think of your direc<strong>to</strong>ry structure, (i.e. this set of nested file folders you are in), as tree structure, then the<br />

simplest direc<strong>to</strong>ry change you can do is move in<strong>to</strong> a direc<strong>to</strong>ry directly above or below the one your are in.<br />

To change <strong>to</strong> a direc<strong>to</strong>ry one below you are in, just use the cd command followed by the subdirec<strong>to</strong>ry name:<br />

cd subdir_name<br />

To change direc<strong>to</strong>ry <strong>to</strong> the one above the one your are in, use the Unix shorthand for “the direc<strong>to</strong>ry above” ..<br />

cd ..<br />

If you need <strong>to</strong> change direc<strong>to</strong>ries <strong>to</strong> one far away on the system, you could explicitly state the full path:<br />

cd /usr/local/bin<br />

If you wish <strong>to</strong> return <strong>to</strong> your home direc<strong>to</strong>ry at any time, just type cd by itself.<br />

cd<br />

To switch between direc<strong>to</strong>ries, you can use the cd – command. This returns you <strong>to</strong> the last direc<strong>to</strong>ry you were<br />

working in before this one.<br />

If you get lost and want <strong>to</strong> confirm where in the direc<strong>to</strong>ry structure you are, use the pwd command (push working<br />

direc<strong>to</strong>ry). This will return the full path of the direc<strong>to</strong>ry you are currently in.<br />

Note also that by default in <strong>Bio</strong>-<strong>Linux</strong>, you see the name of the current direc<strong>to</strong>ry you are working in as part of<br />

your prompt. This is <strong>to</strong> help you remember where you are in your account.<br />

Exercise<br />

Change direc<strong>to</strong>ry from your home direc<strong>to</strong>ry <strong>to</strong> the direc<strong>to</strong>ry intro_pract.<br />

cd intro_pract<br />

Type pwd <strong>to</strong> see the full path <strong>to</strong> where you are.<br />

6


Making a direc<strong>to</strong>ry<br />

To make a new file folder, you use the command mkdir (make direc<strong>to</strong>ry). E.g.<br />

mkdir newdir<br />

would create a new direc<strong>to</strong>ry called newdir.<br />

Exercise<br />

Move <strong>to</strong> your home direc<strong>to</strong>ry (recall the cd command).<br />

Make a new direc<strong>to</strong>ry called testdir.<br />

mkdir testdir<br />

Hit the refresh but<strong>to</strong>n of the file manager of your account <strong>to</strong> update it.<br />

Move in<strong>to</strong> the new direc<strong>to</strong>ry testdir (using the command line)<br />

Move back in<strong>to</strong> the intro_pract direc<strong>to</strong>ry – try <strong>to</strong> do this with a single command.<br />

Using text edi<strong>to</strong>rs<br />

There are a number of different text edi<strong>to</strong>rs available on <strong>Bio</strong>-<strong>Linux</strong>. Note that what we are referring <strong>to</strong> here is not<br />

a word processor, (e.g. MS Word); text edi<strong>to</strong>rs only deal in text.<br />

The text edi<strong>to</strong>rs available range in ease of use from simple <strong>to</strong> complex, and each has its pros and cons. In this<br />

practical we will briefly look at two edi<strong>to</strong>rs, pico and nedit.<br />

Pico<br />

Pros:<br />

• very easy – e.g. command options are visible at the bot<strong>to</strong>m of the window<br />

• can be used when logged in without graphical support<br />

• fast <strong>to</strong> start up and use<br />

Cons:<br />

• by default it is set <strong>to</strong> put returns in<strong>to</strong> lines <strong>to</strong>o long for the screen (i.e. using pico for system administration<br />

is dangerous!)<br />

• is not completely intuitive for people who are used <strong>to</strong> word processors<br />

7


Nedit<br />

Pros:<br />

very easy<br />

quite intuitive<br />

colouring schemes are available for programming syntax<br />

Cons: it is an X program (i.e. graphical), and can’t be run from a text-only environment<br />

it is (slightly) slower <strong>to</strong> start up than non-graphical edi<strong>to</strong>rs<br />

Exercise<br />

Editing a file with pico<br />

In a terminal, type pico.<br />

Write some information in<strong>to</strong> this file. Try the options listed at the bot<strong>to</strong>m of the screen. the ^ means the Control<br />

key (Ctrl). So, for example, <strong>to</strong> check the spelling, use Ctrl-t. The command Ctrl-o saves the file and allows you <strong>to</strong><br />

continue working on it, and Ctrl-x saves the file and exits pico.<br />

When you are done, save your file and exit.<br />

Editing a file with nedit<br />

Type nedit &<br />

Type some text in<strong>to</strong> the window.<br />

Look under the menus for the kinds of options available <strong>to</strong> you.<br />

Under the Shell menu, try the options wc (word count) and number lines.<br />

Save your file under a different name than the one you used for the file you created with pico and exit nedit.<br />

Reading text files<br />

There are many commands available for reading text files on <strong>Linux</strong>/Unix. Among the most common are cat,<br />

more, and less.<br />

cat streams the entire contents of a file <strong>to</strong> your terminal. It is not generally a good command <strong>to</strong> use <strong>to</strong> read files<br />

except ones with very little text. cat is a very useful command for concatenating files though! (More on this<br />

function later.)<br />

more and less are commands that show the contents of a file one page at a time. less has more functionality than<br />

more.<br />

With both more and less, you can use the space bar <strong>to</strong> scroll down the page, and typing the letter q causes the<br />

program <strong>to</strong> quit – returning you <strong>to</strong> your command line prompt.<br />

In addition, once you are reading a document with more or less, typing a forward slash / will start a prompt at the<br />

bot<strong>to</strong>m of the page, and you can then type in text that is searched for below the point in the document you were at.<br />

Typing in a ? also searches for a text string you enter, but it searches in the document above the point you were at.<br />

Hitting the n key during a search looks for the next instance of that text in the file.<br />

8


With less (but not more), you can use the arrow keys <strong>to</strong> scroll up and down the page, and the b key <strong>to</strong> move back<br />

up the document if you wish <strong>to</strong>.<br />

Exercise<br />

Read the file hsy14678.embl using the commands cat, more and less.<br />

cat hsy14768.embl<br />

more hsy14768.embl<br />

less hsy14768.embl<br />

Use the spacebar <strong>to</strong> scroll down<br />

Press q <strong>to</strong> quit.<br />

Use the spacebar <strong>to</strong> scroll down, b <strong>to</strong> go up a page, and the up and<br />

down arrow keys <strong>to</strong> move up and down the file line by line.<br />

Press the / key and search for the letters sequen in the file.<br />

Press the ? key and search for the letters gene in the file.<br />

Press the n key <strong>to</strong> search for other instances of gene in the file.<br />

There are many command line options available for each of the above commands, as well as functionality we do<br />

not cover here. To read more about them, consult the manual pages:<br />

man cat<br />

man more<br />

man less<br />

Copying and pasting text<br />

To select text for copying, press the left mouse but<strong>to</strong>n <strong>to</strong> highlight the text.<br />

To paste, you have the window you wish <strong>to</strong> paste <strong>to</strong> selected, (usually meaning it is the <strong>to</strong>p window on view), and<br />

press the middle mouse but<strong>to</strong>n once – if you have a two but<strong>to</strong>n mouse, press both but<strong>to</strong>ns simultaneously <strong>to</strong><br />

emulate the middle mouse but<strong>to</strong>n.<br />

Exercise<br />

Open two terminals. In one, use the command less <strong>to</strong> open one of the files you created in the previous exercise.<br />

Open up another terminal and start pico.<br />

Copy and paste text from the first terminal in<strong>to</strong> the window running pico.<br />

Save your file (if you want <strong>to</strong>), and exit pico.<br />

9


Command his<strong>to</strong>ry and filename completion<br />

(aka. how <strong>to</strong> cut down on typing!)<br />

Using your his<strong>to</strong>ry<br />

A his<strong>to</strong>ry of the commands you have used is s<strong>to</strong>red as you work. You can access this list and use it <strong>to</strong> see previous<br />

commands, and <strong>to</strong> re-run previous commands.<br />

If you use the up arrow key when you are at the prompt in your terminal, you can see previous commands you<br />

have run. This is particularly useful if you have mistyped something and want <strong>to</strong> edit the command without<br />

writing the whole command out again.<br />

You can view past commands using the command his<strong>to</strong>ry.<br />

To re-run a command listed by the his<strong>to</strong>ry command, you can just type the command number, preceded by an<br />

exclamation mark. E.g.<br />

!268<br />

By default, if you type the command his<strong>to</strong>ry, you will see the last 15 commands. To see more, just put the<br />

number of previous commands you wish <strong>to</strong> see after a hyphen. For example, <strong>to</strong> see the last 30 commands, type:<br />

his<strong>to</strong>ry -30<br />

Using filename completion<br />

If you type in a command with a filename, and instead of completing the filename, you press the tab key part way<br />

through, the system will try <strong>to</strong> complete the filename for you. If the part of the filename you have written is<br />

unambiguous, i.e. there is only one filename that would fit that pattern, the rest of the filename will be filled in for<br />

you. If the pattern is ambiguous, all the filenames that match it will be presented <strong>to</strong> you. You can then choose <strong>to</strong><br />

type out the full name of the file, continue typing until the pattern is not ambiguous and press tab again, or,<br />

instead, if you press tab twice, you will see that the system will cycle through all the filenames that fit your<br />

pattern – you can just keep hitting tab until you get <strong>to</strong> the correct filename.<br />

Exercise<br />

Type<br />

ls hsy<br />

and hit the tab key.<br />

Type<br />

ls test<br />

and hit the tab key. Hit the tab key again. Cycle through the filename options given <strong>to</strong> you.<br />

Type<br />

his<strong>to</strong>ry<br />

Run one of your previous commands using ! followed by the number of the command.<br />

10


Piping commands – how <strong>to</strong> make the output of one command be the input<br />

for the next<br />

There are many instances when you will want <strong>to</strong> use the output of one command as the input for the next<br />

command. For example: what if you wanted <strong>to</strong> see the last 200 commands you ran? This would scroll of<br />

the screen before you could read it. However, if you could take the output from the his<strong>to</strong>ry command<br />

and run it through a command like less, you could view the list page by page.<br />

To do this, you need <strong>to</strong> use the pipe symbol |<br />

This is usually found in the bot<strong>to</strong>m left of your keyboard, although on some keyboards, it may be<br />

elsewhere. The picture on the keyboard may be a straight line up and down, or it may look like two<br />

lines, one on <strong>to</strong>p of the other.<br />

To call up the last 200 commands run, and run them through the less command, you would type:<br />

his<strong>to</strong>ry -200 | less<br />

Finding patterns with grep<br />

An important function in <strong>Linux</strong>/Unix is grep. If you provide grep with a bit of text, it will search for that<br />

text in a file and return any lines that contain that text. By default, grep is case sensitive.<br />

Exercise<br />

Search the file hsy14768.embl for the term DE.<br />

grep DE hsy14768.embl<br />

If you give grep the –i parameter, what happens?<br />

grep –i DE hsy14768.embl<br />

If you want <strong>to</strong> specify that you only want <strong>to</strong> see lines that begin with the letters DE, then you can preface<br />

them with ^:<br />

grep ^DE hsy14768.embl<br />

If you only want <strong>to</strong> see lines that end in UK, you can specify this by using the $ symbol at the end of the<br />

text:<br />

grep UK$ hsy14768.embl<br />

11


Note: While grep is a very useful utility, if you want <strong>to</strong> search biological sequences for patterns, there<br />

are sophisticated programs designed especially for this, and we advise against using grep in all but the<br />

most trivial cases.<br />

Clearing your terminal of text<br />

Your terminal windows can fill up with lots of text, and it can become difficult <strong>to</strong> see the information<br />

you want because of all the clutter.<br />

You can clear the terminal window of all previous text by typing<br />

clear<br />

The result is a prompt in a nice clean window.<br />

Copying files<br />

To copy files, the basic command is cp. At minimum, you must also specify the name of the file(s) <strong>to</strong> be copied,<br />

and the destination location.<br />

cp firstfile dest_location<br />

cp file1 file2 file3 location<br />

cp direc<strong>to</strong>ry/* location<br />

copies all files in the direc<strong>to</strong>ry <strong>to</strong> location<br />

To move whole direc<strong>to</strong>ries, with all the subfiles and subdirec<strong>to</strong>ries, use the –R option, (meaning recursive).<br />

cp –R mydir location<br />

The <strong>Linux</strong>/Unix shorthand for “this direc<strong>to</strong>ry right here” (a dot . )comes in very handy when copying:<br />

cp –R mydir .<br />

Copy all files/direc<strong>to</strong>ries under mydir <strong>to</strong> this direc<strong>to</strong>ry here<br />

Make sure you leave a space between the direc<strong>to</strong>ry name and the shorthand dot.<br />

Also useful is the shorthand for someone’s home account. e.g. instead of having <strong>to</strong> know and type the location of<br />

their account, you can use ~username In the case of your own account, you need only use ~<br />

cp ~user2/somefile . copy the file somefile from user2’s home direc<strong>to</strong>ry here. Note that user2 would have<br />

<strong>to</strong> have given you permission <strong>to</strong> do this!<br />

cp ~/somedir/somefile .<br />

copy the file somefile from within my account/somedir <strong>to</strong> here.<br />

Exercise<br />

Copy all the files that start with the letters tes and end in .embl in<strong>to</strong> the direc<strong>to</strong>ry testdir that you made earlier.<br />

12


There are many different ways <strong>to</strong> accomplish the above. If you have problems, or would like <strong>to</strong> know if you have<br />

done it in the most efficient way, then please ask a demonstra<strong>to</strong>r.<br />

Removing files and direc<strong>to</strong>ries<br />

To remove a file or files, use the rm command followed by the name of the file(s) you wish <strong>to</strong> delete.<br />

rm file1<br />

rm file2 file3 file4<br />

rm cat*<br />

remove all files starting with the letters cat<br />

Note<br />

On <strong>Bio</strong>-<strong>Linux</strong> the command rm has been aliased <strong>to</strong> rm –i.<br />

This means the system will ask you if you really mean <strong>to</strong> delete the file you have just asked <strong>to</strong> delete, and you<br />

must answer yes if you do. Other <strong>Linux</strong>/Unix systems may not be so polite, and unlike Windows systems, the files<br />

you delete are not s<strong>to</strong>red in a trash can for you <strong>to</strong> retrieve – they’re gone! (Unless the file has been there for some<br />

time and you are making proper backups….which you should be!)<br />

If you have a lot of files <strong>to</strong> delete, confirming each one can be tedious. You can escape this safety feature by using<br />

a backslash in front of the rm command.<br />

\rm files<br />

To remove an empty direc<strong>to</strong>ry, you can use the rmdir command:<br />

rmdir thisdir<br />

If that direc<strong>to</strong>ry contains any files, you will not able <strong>to</strong> delete the direc<strong>to</strong>ry using rmdir until you have deleted all<br />

the files within it.<br />

To delete a direc<strong>to</strong>ry and all the files in it, use the rm command with the options -rf<br />

rm –rf fulldir<br />

You may be prompted <strong>to</strong> confirm that you wish <strong>to</strong> delete each file.<br />

If this is <strong>to</strong>o tedious, and you are certain that you want <strong>to</strong> delete all the files in that direc<strong>to</strong>ry as well as the<br />

direc<strong>to</strong>ry itself, remember that you can “escape” this safety feature using the backslash:<br />

Exercise<br />

\rm –rf fulldir<br />

Delete one of the files you created earlier with pico or nedit.<br />

Delete the entire testdir direc<strong>to</strong>ry.<br />

13


Changing permissions on files and direc<strong>to</strong>ries<br />

The command <strong>to</strong> change permissions is chmod. You have <strong>to</strong> specify who you are modifying the permissions of,<br />

what the new permissions are, and what file or direc<strong>to</strong>ry <strong>to</strong> act on.<br />

The format of the chmod command is:<br />

who can take the value(s):<br />

chmod who ± permissions filename<br />

u<br />

g<br />

o<br />

a<br />

means user and refers <strong>to</strong> the owner of the file<br />

means group, and refers <strong>to</strong> the group the file belongs <strong>to</strong><br />

means others, everyone on your systems apart from those above<br />

means all three, i.e. user, group and others<br />

Permissions can be:<br />

r<br />

w<br />

x<br />

means read permission<br />

means write permission<br />

means execute permission<br />

So, for example, <strong>to</strong> give read permission <strong>to</strong> someone in the same group for a file called<br />

“filename” in ~/intro_pract.<br />

chmod g+r ~<br />

gives permission <strong>to</strong> people in my group <strong>to</strong> read my home direc<strong>to</strong>ry<br />

chmod g+rx ~/intro_pract give permission <strong>to</strong> people in the group <strong>to</strong> list files in the intro_pract direc<strong>to</strong>ry<br />

chmod g+r ~/intro_pract/myfile give permission <strong>to</strong> people in the group <strong>to</strong> read the file<br />

myfile (assuming they already have permission <strong>to</strong> “see” in<strong>to</strong> the intro_pract direc<strong>to</strong>ry).<br />

A very basic way <strong>to</strong> s<strong>to</strong>p a process<br />

Sometimes a command or program goes on <strong>to</strong>o long, or is obviously doing something you did not plan. If it is not<br />

a situation where there is an obvious way (e.g. a menu option) <strong>to</strong> s<strong>to</strong>p the program running, try using Control-c.<br />

i.e. the Control key and c-key at the same time.<br />

Logging out of a session<br />

To logout, you can choose the option logout under the System menu.<br />

Please do this at the end of the day – but not now.<br />

14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!