![]() |
Intro to Scientific Computing |
![]() |
You are probably used to the Point-and-Click (GUI) environment of Windows and Macs: when you want to do something, you (double) click on its icon, possibly enter some parameters (a file to edit for example), and then work within that appliction. At the end you might save your work to a file, or print it.
The other big difference is that to find your files, you use a Graphical File Browser, like the one below.
To find files and folders, you navigate your way around by clicking on
icons, like this
In Unix, folders are called directories.
That's why the Unix command to move to a new directory is called cd, for Change Directory. This command moves you to another folder--which I will henceforth call by its proper name, a directory.
Using a Graphical File Browser, you usually see all the files and subfolders as little icons which often represent the type of file. You probably know how to change this behavior.
Click View at the top menu bar, and in the second group take note of what the
View style you have set now (Thumbnails, Icons, Tiles, etc.). Notice the last two:
List and Details.
We will do something very similar to this, listing files from the prompt in an xterm.
First we need some files to play with.
We'll come back to this in a minute.
Second, we need to put them somewhere.
The default directory for each user is her Home directory. This is why we set an environment variable during setup so that all programs would know where this directory is located.
Recall that your Home directory is C:\cygwin\home\YOURUSERNAME.
When you start an xterm, or if you login to a computer where you have a unix account, the terminal gives you a prompt and locates you in your Home directory. This is where your init files are, like .login and others.
In fact the way I have set up your system, the prompt tells you this.
A short hand symbol for your HOME dir is the symbol "~" (the
tilda). Notice that in your prompt there is the following: [~], meaning
that the prompt is located in your Home dir
Two more shorthand notations are the dot "." and the double dot "..". These mean:
. The current directory .. The directory above this one |
For example, do this
ls (that's ell ess)
What you just did was to cd (change directories) to the directory above your Home directory. You then made a list of what files and directories were there. Notice that your prompt changes to [home], meaning that you are in the directory called home.
When you do the listing, you see your own Home direcory "YOURUSERNAME", whatever that is.
If you were logged onto a machine with many users, like the Pacific SunRay system, or if you
have other users using cygwin on your PC, you would see their Home directories too. For now, you probably
only see yours.
Now do
Any time you do cd without specifying a directory, you are taken to your home dir. This is handy; wherever you are, a bare cd command will take you Home.
We'll come back to these things again below.
For now I just wanted you to move around the filesystem a bit.
As we learned above, your Home directory should be:
C:\cygwin\home\YOURUSERNAME
Using the Windows file browser (Start->My Computer), navigate your way to
Drive C: -> cygwin -> home
Find your Home directory there and right click on it, selecting "Create Shortcut". Once you've made a shortcut to your Home dir, you can drag the shortcut to your Desktop (and remame it to just "Home" if you like).
With this shortcut you can easily find your unix files in the graphical folder browser.
A note about "/" and "\"Notice that above when talking about a Windows Folder the path given wasC:\cygwin\home\YOURUSERNAME, with "\" (Backslashes).
In Unix, a directory path uses Forward Slashes:
/home/jhetrick/projects/quarks/.
|
When you first login, your prompt is placed in your home directory.
Your home directory has the same name as your user-name, for example, jhetrick (or "~" for short;
To find out what is in your home directory, type
ls
The ls command lists the contents of your current working directory.

If there were no files visible in your home directory, the prompt would simply be returned. However, we put some there by unpacking the tar command so there should be some files and directories there.
ls does not, in fact, cause all the files in your home directory to be listed, but only those ones whose name does not begin with a dot (.) Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information, such as .login which I had you download. These are hidden because you should not change them unless you are fairly familiar with UNIX!!!
To list all files in your home directory including those whose names begin with a dot, type
ls -a
As you can see, ls -a lists files that are normally hidden.
ls is an example of a command which can take options: -a
is an example of an option (sometimes called a switch).
The options change the behaviour of the command.
There are online manual pages that tell you which options a particular command
can take, and how each option modifies the behaviour of the command.
ls -F
Another option I like to add to you ls is the -F (Format) option. This option puts "/"s at the end of each directory, which makes it easier to distinguish files from subdirectories. It also puts a "*" at the end of each file which is executable meaning that it's a program that can be run.
We will often need to make a subdirectory in your current directory to hold new files,
or start a new project.
To make a subdirectory
called newdir in your current working directory type
mkdir newdir
To see the directory you have just created, type
ls -F
so you can see the files formated by type.Is newdir/ there?
The command cd directory means change the current working directory to 'directory'. The current working directory may be thought of as the directory you are in, i.e. your current position in the file-system tree.
To change to the directory you have just made, type
cd newdir
Type ls to see the contents (which should be empty)
In the following pages I have highlighted a number of
Still in the newdir directory, type
ls -a
As you can see, in the newdir directory (and in all other directories), there are two special directories called (.) and (..)
In UNIX, "." means the current directory, so typing
cd .
means stay where you are (the newdir directory).
This may not seem very useful at first, but using "." as the name of the current directory will save a lot of typing, as we shall see later.
We also need the . when trying to copy files to the current directory.
".." means the parent of the current directory, so typing
cd ..
will take you one up on level in the directory hierarchy (back to your home directory in this case).
You should see the name newdir in the [] part of the prompt, helping you to remember where you are.
Pathnames enable you to work out where you are in relation to the whole file-system.
For example, to find out the absolute pathname of your newly made subdir directory in the
newdir directory (below your home directory)
navigate to subdir using the
pwd
The full pathname will look something like this
/home/jhetrick/newdir/subdir
which means that subdir is a subdirectory of newdir which is itself a subdirectory, located in your Home directory jhetrick. Your Home directory is, along with any other user's Home directories, in the home directory, which is located below the top-level "root" directory called " / " .

For example you can start at the top level by doing cd /
(Remember, if you get lost, type cd by itself to return to your
home-directory--in fact try to get lost and use cd to "go home"!)
First type
ls newdir
to list the conents of your newdir directory.
Now type
ls subdir
You will get a message like this -
subdir: No such file or directory
The reason is, subdir is not in your current working directory. To use a command on a file (or directory) not in the current working directory (the directory you are currently in), you must either cd to the correct directory, or specify its full pathname. To list the contents of your subdir directory, you must type
ls newdir/subdir
Home directories can also be referred to by the tilde ~ character. It can be used to specify paths starting at your home directory. So typing
ls ~/newdir
will list the contents of your newdir directory, no matter where you currently are in the file system.
cd down into subdir/
Try to list the contents of newdir/ by doing
This fails since newdir/ is not in subdir.
Now use the full pathname with the ~ shortcut:
This time it works.
What do you think
ls ~
would list?
What do you think
ls ~/..
would list?
| Command | Meaning |
|---|---|
| ls | list files and directories |
| ls -a | list all files and directories |
| mkdir | make a directory |
| cd directory | change to named directory |
| cd | change to home-directory |
| cd ~ | change to home-directory |
| cd .. | change to parent directory |
| pwd | display the path of the current directory |
Now, let's get some files to play with.
We're using a very common unix way of getting a set of files.
They are packed in a Tar File (sometimes called a tarball), which you can tell from
the .tar suffix.
In an open xterm window, type
You should see the somefiles.tar file in the list.
To unpack the tar file, we'll use the command
Do
Because you used the verbose option, you should see a report of the contents as the files are extracted.
Now you have some files to play with, let's learn more Unix command.