• No results found

Introduction to Bio-Linux

N/A
N/A
Protected

Academic year: 2021

Share "Introduction to Bio-Linux"

Copied!
13
0
0

Loading.... (view fulltext now)

Full text

(1)

Introduction to Bio-Linux

Logging in and exploring the desktop

You can log into your Bio-Linux machine locally or remotely. Today you are logging onto a machine locally, which means that the monitor you are looking at is attached directly to the machine running the system. You may also hear this referred to as logging in at the console.

Log in using the username and password you have been given.

The view you now see is referred to as the desktop.

Exercise

Take some time to explore the desktop. Look at what options are available under the menus, what clicking the icons on the desktop does, etc. Also try using the right and middle mouse buttons when the mouse pointer is over a blank area of the desktop and explore the menus presented to you.

At the right hand side of the toolbar on the bottom of the screen are 4 “virtual desktops”. These effectively give you 4 times the working space of your monitor. Try going to a different virtual desktop and starting up some windows/applications there.

Click on the icon for your “home” at the top left of the screen. This is a graphical representation of your files, similar to what you might see on a Mac or PC. Leave this window open for the next part of the practical.

How Linux and Unix files are organized

Your Bio-Linux machine can be thought of as a huge file folder, inside of which are many other file folders, and inside these are more nested file folders, and so on. As in the real world, file folders can hold other file folders, or files (– for this course, consider these to be the same as documents.)

In Linux /Unix systems, documents are usually referred to as files, and file folders are referred to as directories.

The graphical representation of your account can be a good initial way to visualise what folders and documents you have, and to move around in your account. However, as you grow more comfortable with Linux, you may begin to find it slow and unnecessary. It is a good way to learn about the overall filesystem of the machine though!

Your account is one directory (file folder) somewhere within the overall big file folder, i.e. your Bio-Linux machine. In it you can create other directories, store data, run programs, etc.

Just like with a regular filing cabinet, if you threw all your documents in without any ordering or organisation, it would rapidly become difficult to find things. The same thing will happen to your account if you choose to keep all your documents in your home directory instead of creating subdirectories and storing associated data together within them.

If you look at the graphical representation of your home directory – you should see the following next to the word location:

/home/user1

(2)

The name of the base file folder, the one within which everything else is, is “/”, usually referred to as the “root directory”.

/home home is a file folder located within the root directory

/home/user user is a file folder within the directory home which is within the root directory

All the directory names are separated with a forward slash – so the directory user1 is located within the directory home, which is within /.

A Linux aside:

The root directory of Linux/Unix systems is / . However, Linux systems also have a directory called /root with is a directory called “root” within /

/root is root’s “home” directory. Usually if you someone refers to the root directory, they probably mean just / not /root

The real power on Linux/Unix systems is the command line. You usually access the command line using terminals.

You can open a terminal by:

• clicking on the icon on the top tool bar

• right-clicking on the desktop and choosing the menu option “New terminal”

or by going to the Utilities option under the Programs drop down menu, and choosing Terminal You can also start new terminals by typing their name on the command line.

xterm &

The & allows you to keep working in the original window by starting up the process, (in this case, an xterm), and putting that process in the “background”. If you want to know more about this, please ask a demonstrator.

If you don’t like the colour scheme of the terminal you are working in, you can change it using the Preferences option under the Settings menu on the terminal.

Exercise

Go to the Preferences option under the Settings menu on the terminal. Choose the panel Colours, and then choose the colour scheme you want. Please note that the option “black on white” actually produces black on grey.

To get black print on a white background, choose Custom Colours and choose the colours you want.

After this, any new terminal you open will inherit your new colour scheme.

Pressing the right hand mouse button can bring up menus of options for the terminal you are working in.

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

There is also a menu under the tiny icon to the left of the word Terminal at the top of your terminal window. Try out some of the options. Try choosing the option Sticky under Toggle. This makes that terminal appear in every virtual desktop, instead of just one desktop. Note: please use the exit options mentioned above to close your terminal, rather than the Close option in this menu.

(3)

File naming conventions

a.) Certain characters should not be used in filenames in Linux/Unix.

If you stick with letters, numbers, hyphens, underscores and full stops, you will be fine.

b.) Linux/Unix cannot deal with spaces in filenames!

Make sure your filenames do not contain them.

Filenames with spaces in them are a common problem when transferring files to Linux/Unix from a computers running Windows, or Mac operating systems.

If you end up with filenames with spaces in them, you will need to enclose the entire filename in quotation marks so that Linux/Unix understands that the space is part of the name.

Alternatively, you can “escape” the space using a backslash. For example, if I have a file called my document

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

But you could write either of the following to make it understand you mean a single file:

“my document”

my\ document

We advise that you change the name of such files to remove the space. A common practice is to replace the space with an underscore. E.g.

mv “my document” my_document

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

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

More is said on this in the bioinformatics practical.

(4)

Basic commands

It is possible for users to achieve a great deal with only a small number of commands.

Anatomy of a Command

Linux/Unix commands usually take the form:

E.g. To read a text file and number the lines, I can use the command less, give it the parameter –N and the argument of the filename I wish to read

less –N mytextfile

Some commands may not need parameters or arguments, but most will have options available to you if you choose to use them.

You can find out more about options available to you for any command by using the man command.

man less

If a command is executed without problem, it will usually not report anything back to you, (unless reporting to you was the purpose of the command!). If the command does not execute properly, you will often see an error message returned. Whether or not the error is meaningful to you depends on what your level of experience with Linux/Unix is and how user-friendly the errors generated by that command were designed to be.

command parameters arguments

what I want to do how I want to do it on what do I want to do it

(5)

Linux/Unix shorthand and shortcuts

At first understanding example Unix commands can seem daunting. This is often due to the shorthand employed.

The most common shorthand characters are very useful.

The following incomplete list covers the symbols you will see most often today and describes their meanings as you will most likely encounter them in this course.

Warning: some symbols have different meanings depending where they are used, A short incomplete list includes:

* matches any character appearing 0 or more times, also known as a wildcard ls mydir/* list all the files under the directory mydir

ls cat* list all files starting with the letters cat

ls cat*hat list all files starting with the letters cat and ending in hat

? matches a single character

ls cat??hat list all files starting with the letters cat followed by any 2 letters, and then hat . “the directory I am currently in”

.. the directory one level above

~ my home directory

~username the home directory of the user username

Changing directories

The command used to change directories is cd

If you think of your directory structure, (i.e. this set of nested file folders you are in), as tree structure, then the simplest directory change you can do is move into a directory directly above or below the one your are in.

To change to a directory one below you are in, just use the cd command followed by the subdirectory name:

cd subdir_name

To change directory to the one above the one your are in, use the Unix shorthand for “the directory above” ..

cd ..

If you need to change directories to one far away on the system, you could explicitly state the full path:

cd /usr/local/bin

If you wish to return to your home directory at any time, just type cd by itself.

cd

To switch between directories, you can use the cd – command. This returns you to the last directory you were working in before this one.

(6)

If you get lost and want to confirm where in the directory structure you are, use the pwd command (push working directory). This will return the full path of the directory you are currently in.

Note also that by default in Bio-Linux, you see the name of the current directory you are working in as part of your prompt. This is to help you remember where you are in your account.

Exercise

Change directory from your home directory to the directory intro_pract.

cd intro_pract

Type pwd to see the full path to where you are.

Making a directory

To make a new file folder, you use the command mkdir (make directory). E.g.

mkdir newdir

would create a new directory called newdir.

Exercise

Move to your home directory (recall the cd command).

Make a new directory called testdir.

mkdir testdir

Hit the refresh button on the graphical representation of your account to update it.

Move into the new directory testdir (using the command line)

Move back into the intro_pract directory – try to do this with a single command.

Listing files in a directory

Use the ls command to list files in a directory

By default, the command will list the filenames of the files in your current working directory.

You can specify many options to modify how much information is output by ls. You can also specify the name (or full path) of a directory you wish to list the contents of.

ls /usr/local/bin ls –lR /usr/software

(7)

The meaning of the information returned to you when using the –l option with the ls command will be explained during the course.

You can also use regular expressions to limit the files you wish to list. Recall:

* means any character

? means a single character

[ ] can be used to designate a group of characters

Exercise

List the files in your current directory.

List the files in your current directory with full details.

List all the files in your directory that start with the letters tes ls tes*

List all the files in your directory that start with tes, and end in 1.embl, 2.embl or 3.embl ls tes*[1-3].embl

Using text editors

There are a number of different text editors available on Bio-Linux. Note that what we are referring to here is not a word processor, (e.g. MS Word); text editors only deal in text.

The text editors available range in ease of use from simple to complex, and each has its pros and cons. In this practical we will briefly look at two editors, pico and nedit.

Pico Pros:

• very easy – e.g. command options are visible at the bottom of the window

• can be used when logged in without graphical support

• fast to start up and use Cons:

• by default it is set to put returns into lines too long for the screen (i.e. using pico for system administration is dangerous!)

• is not completely intuitive for people who are used to word processors

Nedit

Pros: very easy quite intuitive

colouring schemes are available for programming syntax

Cons: it is an X program (i.e. graphical), and can’t be run from a text-only environment it s slower to start up than non-graphical editors

(8)

Exercise

Editing a file with pico In a terminal, type pico.

Write some information into this file. Try the options listed at the bottom of the screen. the ^ means the Control key (Ctrl). So, for example, to check the spelling, use Ctrl-t. The command Ctrl-o saves the file and allows you to continue working on it, and Ctrl-x saves the file and exits pico.

When you are done, save your file and exit.

Editing a file with nedit Type nedit &

Type some text into the window.

Look under the menus for the kinds of options available to you.

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

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

Reading text files

There are many commands available for reading text files on Linux/Unix. Among the most common are cat, more, and less.

cat streams the entire contents of a file to your terminal. It is not generally a good command to use to read files except ones with very little text. cat is a very useful command for concatenating files though!

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

With both more and less, you can use the space bar to scroll down the page, and typing the letter q causes the program to quit – returning you to your command line prompt.

In addition, once you are reading a document with more or less, typing a forward slash / will start a prompt at the bottom of the page, and you can then type in text that is searched for below the point in the document you were at.

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

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

With less (but not more), you can use the arrow keys to scroll up and down the page, and the b key to move back up the document if you wish to.

Exercise

Read the file hsy14678.embl using the commands cat, more and less.

(9)

cat hsy14768.embl

more hsy14768.embl Use the spacebar to scroll down Press q to quit.

less hsy14768.embl Use the spacebar to scroll down, b to go up a page, and the up and down arrow keys to move up and down the file line by line.

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

Press the ? key and search for the letters gene in the file.

Press the n key to search for other instances of gene in the file.

There are many command line options available for each of the above commands, as well as functionality we do not cover here. To read more about them, consult the manual pages:

man cat man more man less

Copying and pasting text

To select text for copying, press the left mouse button to highlight the text.

To paste, you have the window you wish to paste to selected, (usually meaning it is the top window on view), and press the middle mouse button once – if you have a two button mouse, press both buttons simultaneously to emulate the middle mouse button.

Exercise

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

Open up another terminal and start pico.

Copy and paste text from the first terminal into the window running pico.

Command history and filename completion

Using the functionality of your command history and command line can save you a lot of typing!

If you use the up arrow key when you are at the prompt in your terminal, you can see previous commands you have run. This is particularly useful if you have mistyped something and want to edit the command without writing the whole command out again.

You can view past commands using the command history.

To re-run a command listed by the history command, you can just type the command number, preceded by an exclamation mark. E.g.

(10)

!268

If you type in a command with a filename, and instead of completing the filename, you press the tab key part way through, the system, (actually the shell), will try to complete the filename for you. If the part of the filename you have written is unambiguous, i.e. there is only one filename that would fit that pattern, the rest of the filename will be filled in for you. If the pattern is ambiguous, all the filenames that match it will be presented to you. You can then choose to type out the full name of the file, continue typing until the pattern is not ambiguous and press tab again, or, instead, if you press tab twice, you will see that the system will cycle through all the filenames that fit your pattern – you can just keep hitting tab until you get to the correct filename.

Exercise

Type

ls hsy and hit the tab key.

Type

ls test

and hit the tab key. Hit the tab key again. Cycle through the filename options given to you.

Type

history

Run one of your previous commands using ! followed by the number of the command.

Clearing your terminal of text

Your terminal windows can fill up with lots of text, and it can become difficult to see the information you want because of all the clutter.

You can clear the terminal window of all previous text by typing clear

The result is a prompt in a nice clean window.

Copying files

To copy files, the basic command is cp. At minimum, you must also specify the name of the file(s) to be copied, and the destination location.

cp firstfile dest_location cp file1 file2 file3 location

(11)

cp directory/* location copies all files in the directory to location

To move whole directories, with all the subfiles and subdirectories, use the –R option, (meaning recursive).

cp –R mydir location

The Linux/Unix shorthand for “this directory right here” (a dot . )comes in very handy when copying:

cp –R mydir . Copy all files/directories under mydir to this directory here Make sure you leave a space between the directory name and the shorthand dot.

Also useful is the shorthand for someone’s home account. e.g. instead of having to know and type the location of their account, you can use ~username In the case of your own account, you need only use ~

cp ~user2/somefile . copy the file somefile from user2’s home directory here. Note that user2 would have to have given you permission to do this!

cp ~/somedir/somefile . copy the file somefile from within my account/somedir to here.

Exercise

Copy all the files that start with the letters tes and end in .embl into the directory testdir that you made earlier.

There are many different ways to accomplish the above. If you have problems, or would like to know if you have done it in the most efficient way, then please ask a demonstrator.

Removing files and directories

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

rm file1

rm file2 file3 file4

rm cat* remove all files starting with the letters cat

Note

On Bio-Linux the command rm has been aliased to rm –i.

This means the system will ask you if you really mean to delete the file you have just asked to delete, and you must answer yes if you do. Other Linux/Unix systems may not be so polite, and unlike Windows systems, the files you delete are not stored in a trash can for you to retrieve – they’re gone! (Unless the file has been there for some time and you are making proper backups….which you should be!)

If you have a lot of files to delete, confirming each one can be tedious. You can escape this safety feature by using a backslash in front of the rm command.

\rm files

(12)

To remove an empty directory, you can use the rmdir command:

rmdir thisdir

If that directory contains any files, you will not able to delete the directory using rmdir until you have deleted all the files within it.

To delete a directory and all the files in it, use the rm command with the options -rf rm –rf fulldir

You may be prompted to confirm that you wish to delete each file.

If this is too tedious, and you are certain that you want to delete all the files in that directory as well as the directory itself, remember that you can “escape” this safety feature using the backslash:

\rm –rf fulldir

Exercise

Delete one of the files you created earlier with pico or nedit.

Delete the entire testdir directory.

Changing permissions on files and directories

The command to change permissions is chmod. You have to specify who you are modifying the permissions of, what the new permissions are, and what file or directory to act on.

The format of the chmod command is:

chmod who ± permissions filename Who can be:

u means user and refers to the owner of the file

g means group, and refers to the group the file belongs to

o means others, everyone on your systems apart from those above a means all three, i.e. user, group and others

Permissions can be:

r means read permission w means write permission x means execute permission

So, for example, to give read permission to someone in the same group for a file called

“filename” in ~/intro_pract.

chmod g+r ~ gives permission to people in my group to read my home directory

(13)

chmod g+rx ~/intro_pract give permission to people in the group to list files in the intro_pract directory

chmod g+r ~/intro_pract/myfile give permission to people in the group to read the file myfile (assuming they already have permission to “see” into the intro_pract

directory).

A very basic way to stop a process

Sometimes a command or program goes on too long, or is obviously doing something you did not plan. If it is not a situation where there is an obvious way (e.g. a menu option) to stop the program running, try using Control-c.

i.e. the Control key and c-key at the same time.

Logging out of a session

To logout, you can choose the option logout under the System menu.

Please do this at the end of the day – but not now.

References

Related documents