A Survival Guide to Unix/Linux Systems

Mihaly Mezei, Ph.D.

Mount Sinai School of Medicine, NYU.
Department of Structural and Chemical Biology
IMI, Rm 15-23A

(212) 659-5475  (Ext. 85475)
E-mail address: Mihaly.Mezei@mssm.edu

Last update: Jan. 23, 2008

CONTENTS

1.  Unix/Linux
1.1.  File systems
1.2.  Navigating file systems, moving files
2.  Editors.
2.1.  vi
2.2.  emacs
3.  Communicating Among Computers on the Net
3.1.  Logging on to Computers on a Network
3.2.  File transfer across the Network

1. Unix/Linux Survival Guide

This section gives the 'survival skills' necessary to manage your files under a Unix/Linux operating system. It gives a basic introduction to several editors and describes the basics of the operating system. There are many varieties of Unix and Linux but they all have the basic fetures described here in common. Notice that Unix is case sensitive and usually uses lower case letters.

1.1. File systems

Unix uses a tree-structured hierarchy (similar to most operating systems in use). At each level of this hierarchy, one can have actual files containing data, programs and the like or a directory that points to a lower level of the hierarchy. Figure 1.1 shows such an example.

>>
.login
etc/ ...
user/
grosics/ ...
buzanszki/ ...
lorant/
.login
workshop.i
amber/
mopac/
mopac.exe
readme
vitamin_c/
am1.inp
m1.out
min.inp
min.out
benzpyrene/ ...
water/ ...
lantos/ ...
bin/ ...
lib/ ...

Fig. 1.1. A sample Unix file system.

Here anything that ends with a / is a directory. The ellipsis (...) is used to indicate a directory that is not described here. Files are specified by the path of directories leading to them, thus the full name of the .login file at the second level is /.login while the .login file at the fourth level is /user/lorant/.login.

Most computers have more than one directory trees, called file systems. File systems of one computer can be made accessible on different computers by the process called 'mounting' it through the network. It should be kept in mind, however, that accessing a file system mounted through the network is slower than accessing a local file system and thus for I/O intensive job it is preferable to use files on file systems local to the computer that runs the calculation.

1.2. Navigating file systems, moving files

When a user logs on the system is in the user's home directory, i.e.,, the user Lorant will be in the directory /user/lorant/.

Note that loggin on generally requires a password. To change your password, on Unix you have to type passwd. words that are not easy to guess. In particular, it should not be a word than can be found in a dictionary.

To find out which directory you are currently in type pwd.

To change the directory to a new one use the command cd <new>. Here <new> can be

Issuing command A any time the user will change to the mopac directory. Issuing command B while in the login directory results a change into the vitamin_c directory. Issuing it from any other directory would result in an error message. Command C can be issued from any directory, it will step the user up with one level. For example, issuing it after a successful command B, the user will be in the mopac directory.

To obtain a list of files and directories in a given directory, type ls.

To find out how much disk space is used by your files, the command du -sk <directoryname> gives the number of blocks used by that directory (if <directoryname> is omitted, the space used by all the files and directories in the current directory will be shown).

To see the contents of a text file, type more <filename>. The more commands stops after each page - hit space to continue. CNTRL-C aborts the listing.

To copy file A to file B issue cp A B. Here A and B can include directory path. For example

cp mopac/vitamin_c/min.inp mmm.i or

would copy min.inp to the login directory, assuming that the copy command is issued while in the login directory.

To rename a file, type mv <old_name> <new_name>.

To delete a file, type rm <filename>. To delete a directory (after having emptied it) type rmdir <dir_name>.

Generally a filename can contain any alphanumeric characters, underscore and some others. It usually consists of two parts, separated by a period (.) where the second part is used to say something about the type of the file, e.g., prog.f indicates a Fortran source code file. However, the extension is not required. Also, multiple extensions are allowed. Examples for legal filenames are

whatnot    0.5in test.prog.c    out_put

When referring to files, the symbol * is used as a 'Wild Card', meaning that anything that matches the rest of the name will be referred to. Thus the command rm *.f on Unix deletes all files with extension f. Use it with extreme care, especially when deleting files!

To back up or move a directory tree Unix provides a tool to create a single file from that directory. The command tar -cvf <file>.tar <file> will create a single file called he <file>.tar containing all the files in the directory (and in its subdirectories, if any) <file>. To recreate the directory tree, type tar -xvf <file>.tar. To see the content of the 'tar' file type tar -tf <file>.tar.

In our example, if user lorant is in his home directory, the command tar -cvf lorant.tar mopack will create a file named lorant.tar that contains all the files in the directory mopack.

Files used infrequently can be compressed to a smaller size using the compress or gzip commands (gzip is not installed automatically on every system): type compress xyz to obtain a smaller file called xyz.Z or gzip xyz to obtain a smaller file called xyz.gz To restore the original file type uncompress xyz or gzip -d xyz. Other compression programs (mostly used on PC's) create complessed files with extensions such as .zip, .zoo, .lzh. Files with .zip extension can be created or uncompressed by the zip and unzip commands on the SGI's. The others can be uncompressed on a PC - contact Dr. Mezei for a copy of those decompression programs.

To run a program, i.e., execute a compiled code, you simply type the name of the file. For example, executing the program mopac.exe in the file system on Figure 3.1. the user Lantos would type /user/lorant/mopac/mopac.exe. This assumes that the protection on the file mopax.exe allows user Lantos to execute it. Protections can be changed, of course.

When the execution of a program requires several commands, they are usually put in a file, called script file. To execute this file type source <filename>. When running jobs in batch mode (see sec. 3.7. of the facilty guide) the argument of the qsub command is the name of the script file.

Previous commands can be recalled and edited. !! reexecutes the last command, ^oldstring^newstring^ modifies the last command by replacing <oldstring> with <newstring> and executes it. If you are in the Unix tcsh shell, the up and down arrow keys let you scan the previous commands typed. A command brought back in such a way can be edited before execution.

There are extensive built-in help facilities on most systems. The man <subject> command will reproduce the manual (reference) pages for the <subject>, if there are any. Typically, <subject> is the name of a command. apropos <subject> gives a list of commands that involve <subject>

2. Editors

Editors are word processors that have been oriented toward a particular computer's requirements or to particular software format requirements. This section gives a very brief description of the most important editors. Much more can be learned by their help facility or by perusing the documentation.

Each editor is invoked by the editor name followed by the name of the file to edit. Full-screen editors allow the use of the arrow keys to position the cursor within the file.

2.1. vi

vi is the standard full-screen editor available on all Unix systems that people love to hate.

vi <filename> starts an editing session using the file <filename>

There are three modes in communicating with vi:

  1. 'Surfing' mode where the cursor can be moved around the file without changing it and anything you type is interpreted as an instruction;
  2. Writing mode where anything you type will be added to the file at the cursor's position;
  3. Command mode.
When vi starts, it is in the surfing mode.

In the surfing mode:

The command mode can be accessed only from the surfing mode by typing :, followed by a single command like the ones described below. Having executed that command, vi returns to the surfing mode.

2.2. emacs

Emacs is a popular Unix full-screen editor from Free Software Foundation, installed on most Unix systems. It allows the use of the delete key besides the arrows (unlike vi). It also automatically saves the original copy with a different name, so if the changes turn out to be unneeded, you can go back to the previous version. There is a command line at the bottom of the screen, and at certain times prompts will appear there.

Cntrl-V moves the cursor one page down, ESC followed by V moves one page up. To go to a specific line number, type ESC, followed by X then the text goto line followed by the linenumber.

To replace a certain string with another, type ESC followed by X, then the text replace string, followed by the old and the new string, both closed by enter key.

To exit, type: CNTRL-X and CNTRL-C. It will query you if you want to save the changes.

3. Communicating Among Computers on the Net

While most information is gathered on the Internet with the help of Browsers, there are other ways of communicating among networked computers. Selecting a computer on the network to work on requires logging on to that computer. When working on multiple systems, transferring files from one system to an other is a constant necessity.

3.1.Logging on to Computers on a Network

Loggin on to a Unix system from a PC requires a terminal emulator program (such as Putty or TeraTerm - both are freely available). Starting these programs requires the specification of the network address of the compute you want to log in. Once he terminal window is opened the usual login information (username and password) has to be given.

Once logged on to a Unix system one can log in to an other one (in the same terminal window by typing one of the following:

slogin and ssh encrypt the passwords transmitted and are considered secure - some systems require it for access.

There are a growing number of applications that use the X-windows graphics interface. First, to run such applications, you have to be logged on to an X-terminal. If that terminal is on the machine you want to run the program you are ready to run. If the application resides on a different system, you have to tell that system that you actually logged on from an X terminal by issuing the comand setenv DISPLAY <hostname>:0 .

Running an X-windows application using a PC as a display requires a different terminal emulator, e.g., Hummingbird. Contact our system manager, Mr. Kevin Kelliher at Ext. 41614, (E-mail address: kevin.kelliher@mssm.edu) to obtain a copy and help in setting it up.

3.2.File transfer across the Network

Exchanging files between a PC and a Unix system requires a program capable of using ftp (File Transfer Protocol), e.g., WINSCP (freely available). Staring such programs opens up a pair of windows after having specified the network address of the Unix system and giving a valid username and password. The directories in the two windows can be independently browsed and files can be marked for transfer in either direction.

The scp command can be used to transfer a file to a different Unix system:
scp filename user@computer:directory
or from a different Unix system to the current system:
scp user@computer:directory/filename ..
Here filename is the name of the file to transfer, user is the username on the remote computer computer is the network address of the remote computer and directory is the directory on the remote computer the file to be copied to or from.

Return to contents page