Skip to end of metadata
Go to start of metadata

Why does this page exist?

Icon

This page is designed to provide some information (hopefully useful) for those using Linux on campus for the first time. It was written originally for those taking the PH30056 (Computational Physics B) unit, but the information is useful to other courses as well.

This is a work in progress - some bits are just ideas of content to be added later. I'll probably change the order of things as well.

There are a few pages to go along with this - please see under "Linux info for Undergrads" in the menu on the left.

First steps

So, you've suddenly found yourself in one of the Physics units that uses linux. Probably either 'programming skills' or 'computational physics' - you've managed to log in to the servers by following the instructions, and what do you see?

-------------------------------------------------------------
   __        ______ .______    __    __
  |  |      /      ||   _  \  |  |  |  |
  |  |     |  ,----'|  |_)  | |  |  |  |
  |  |     |  |     |   ___/  |  |  |  |   . BATH . AC . UK
  |  `----.|  `----.|  |      |  `--'  |
  |_______| \______|| _|       \______/

------------------------------------------------------------
 When using this service you must comply with the conditions
of our acceptable use policy at: http://go.bath.ac.uk/it-aup
------------------------------------------------------------
You are logged into lyness.bath.ac.uk
Please include this in any support requests you raise.
-------------------------------------------------------------
-bash-3.2$

Helpful, isn't it? No menus, no icons, nothing. So, it's time to find out a few things. For a start, where are we? The prompt (known in this case as the 'BASH prompt') on the left is of little help. When you first login you'll be in your 'home directory' on one of our servers - the home directory is your top level, and is the equivalent of the Windows h:\ drive - any file you can see directly in h:\ will be here at the top level in your home directory.

Finding your way around

The first thing we'll do is see exactly what is here. To do this we want a 'directory listing' and the command for this is 'ls', like this:

-bash-3.2$ ls
Desktop    dos        Favorites-backup-campusts.zip  Music     Profiles_Do_Not_Delete  PUTTY.RND  Templates  WINDOWS
Documents  Downloads  Favorites-backup-campus.zip    Pictures  Public                  scripts    Videos

and yours will probably look similar to that. Some of the names shown will be files, some will be directories, but it may not be easy to see. To help a bit we'll add a 'flag' to the ls command, to ask for more information. In this case using 'ls -l' will produce a 'long listing' which is a bit more helpful:

-bash-3.2$ ls -l
total 60
drwxr-xr-x  2 pys-tu00 pys 4096 Sep 28  2009 Desktop
drwxr-xr-x  2 pys-tu00 pys 4096 Dec 14 15:12 Documents
drwx--x--x 10 pys-tu00 pys 4096 Feb 16 12:49 dos
drwxr-xr-x  2 pys-tu00 pys 4096 Dec 14 15:12 Downloads
-rwx--x--x  1 pys-tu00 pys 2965 Feb 16 12:50 Favorites-backup-campusts.zip
-rwx--x--x  1 pys-tu00 pys 3048 Mar  3 12:06 Favorites-backup-campus.zip
drwxr-xr-x  2 pys-tu00 pys 4096 Dec 14 15:12 Music
drwxr-xr-x  2 pys-tu00 pys 4096 Dec 14 15:12 Pictures
drwx------  4 pys-tu00 pys 4096 Feb 16 12:49 Profiles_Do_Not_Delete
drwxr-xr-x  2 pys-tu00 pys 4096 Dec 14 15:12 Public
-rwxr--r--  1 pys-tu00 pys  600 Jul  5  2010 PUTTY.RND
drwxr-xr-x  2 pys-tu00 pys 4096 Mar  9  2005 scripts
drwxr-xr-x  2 pys-tu00 pys 4096 Dec 14 15:12 Templates
drwxr-xr-x  2 pys-tu00 pys 4096 Dec 14 15:12 Videos
drwx------  3 pys-tu00 pys 4096 Feb 16 12:49 WINDOWS

Panic! A lot of almost indecipherable information! Let's break it down a bit, by looking at just one line:

drwxr-xr-x  2 pys-tu00 pys 4096 Sep 28  2009 Desktop

Or to split it out a bit into more obvious columns:

drwxr-xr-x

2

pys-tu00

pys

4096

Sep 28 2009

Desktop

File permissions (a big subject), with the d at the start showing this is a directory

Number of links (ignore!)

The owner user (related to permissions)

The owner group (permissions again)

File size in bytes - think of 4096 as a dummy value for directories

File timestamp (last edited or time created) - shows year instead of time if that's more relevant

The file/directory name

So, a lot of information, much of it related to permissions.

ls

Icon

Use the ls command to obtain a 'directory listing' to see what is in the current directory

Changing directory

So, you have this list of directories in front of you - how do you get into one of them? Simple, you 'change directory', using the 'cd' command. i.e. to change into the 'dos' directory (which happens to be "My Documents" on the Windows PCs):

-bash-3.2$ cd dos
-bash-3.2$ ls -l
total 212
-rwxr--r-- 1 pys-tu00 pys  2120 Mar  1 15:30 Default.rdp
-rwxr--r-- 1 pys-tu00 pys   160 Feb 16 12:49 desktop.ini
drwxr-xr-x 2 pys-tu00 pys  4096 Mar  9  2010 MATLAB
drwx--x--x 3 pys-tu00 pys  4096 Sep 17 09:50 My Music
drwx--x--x 3 pys-tu00 pys  4096 Sep 17 09:50 My Pictures
drwx--x--x 3 pys-tu00 pys  4096 Sep 17 09:50 My Videos
drwxr-xr-x 2 pys-tu00 pys  4096 Mar 17  2010 Palm OS Desktop
drwx--x--x 2 pys-tu00 pys  4096 Jul 28  2010 $RECYCLE.BIN
drwxr-xr-x 3 pys-tu00 pys  4096 Sep 10  2004 RECYCLER
-rwx--x--x 1 pys-tu00 pys 64138 Jul 15  2010 spm errors.txt
-rwxr--r-- 1 pys-tu00 pys 98741 Jul  1  2010 test.txt
drwxr-xr-x 3 pys-tu00 pys  4096 Mar 17  2010 Visage PDF Files

cd

Icon

Use the cd command to change directory - i.e. move into a different directory.

I think it's worth mentioning at this point that linux is case sensitive, so you need to ensure you get your upper and lower case characters correct.

Icon

Linux is case sensitive - so you have to be careful about file and directory names. Windows is not. In Windows a file names "file1" is identical to one called "FilE1" but in linux these could be 2 completely separate files.

A note about the differences between Linux and Windows text files

If you start transferring text files (i.e. program code, or output) between Windows and UNIX you'll soon hit some problems, as they treat the end of a line of text differently.

For historical reasons Windows (based on the dos format) finishes text lines using the ASCII codes for both 'New Line' and 'Carriage Return' - and UNIX just uses 'New Line'

Windows text editors, including Notepad, get confused when they don't see the 'Carriage Return' at the end of a line, and tend to run all of the text together. UNIX editors (pico, vi, emacs etc) are generally better behaved, and don't complain too much if they get a windows style carriage return command at the end of a line - compilers however don't like it much.

So, what can you do about this - well, you could just stick to using UNIX tools to do all of the work, or you can use a text editor on Windows that understands UNIX text files (Notepad++ or TextPad are my favourites), or you can use some tools installed on the campus UNIX servers to convert the files for you

Converting text files using dos2unix and unix2dos

There are 2 commands that you need, depending on which way you're going (and you need to specify that we're using ASCII - you don't need to know what that means!): 

If you're taking a file you've created in Windows (in dos format), to use in UNIX, you should use 'dos2unix'

 e.g.

(where 'test.txt' is the name of the Windows text file)

If you're taking a file you've created in UNIX, to use in Windows, you should use 'unix2dos' 

Linux file paths

Explain the meaning of the paths - i.e. home, /, ~/dos etc.

Echoes, pipes and command logic

>>, >, |, !, !!, &, &&, < and << all handy to know about.

Creating files and directories

mkdir, touch, pwd, rmdir, rm, find etc.

Viewing files - more or less

cat, more, less

File manipulation

grep, wc, wc -l, sort, head and tail. If brave, sed and awk!

Some other useful commands

ps, chmod, chown, find, quota, du, kill

Going beyond the basics

jobs, fg, bg etc. Screen?

  • No labels