Selected Unix/Linux tips:
To catch standard error output to a file:
-
Add 2> <filename> to the command line.
-
Note: 1> <filename> is the same as ><filename> and
pipes standard output to <filename>
-
The standard error output is often used rather than standard output by
programs to put messages to the screen. SAM puts a particularly voluminous
message stream to standard error, which is too long to scroll back through.
This maneuver saves the log of messages into a file for future examination.
The messages will not come to the screen, however.
-
2>&1 <filename> captures both standard output and standard
error to a single file.
To view a text file (like standard error or standard output) while the
program writing it is still running.
-
Open a new terminal window.
-
Or else in the same window, put the program in the background by <control>Z
followed by bg.
-
Or else start the program in the background by ending the command line
with an &.
-
type tail -f <filename>
-
The end of the file will be displayed and updated each time it is written
to.
-
You will have to terminate the tail function with <control>C
when the output is over. Therefore if you use the background method,
you will have to be able to recognize the end of the output.
To kill an errant process.
-
Suspend it with <control> Z
-
Type ps to get the job number.
-
type kill -15 <job number>
-
This tries to close output files and kill the job.
-
If this fails, type kill -9 <job number>
-
This kills without trying to save files.
-
If the job has been put in the background with bg, then bring
it to the foreground with fg, then kill as above.
-
If the job was put into the background and then you logged out, you can
log back in and kill it by:
-
ps -u <your username>
-
Find the job number from the list and kill as above.
-
Note: if you try to kill someone else's process by mistake, you will be
denied permission.
If gcg periodically fails to find its help files or programs:
If ls fails to recognize * as a wildcard:
-
The gcg startup file executed at startup for most bioinf users inactivates
wildcard usage. To reverse this, type set +o noglob.
-
As indicated in the item above, you can put this fix in a gcg initialization
file.
-
Note: ls * lists the directory and all of its subdirectories; just
ls
lists the whole directory; and ls *.* lists all files with
extensions in just the default directory. ls */ -d lists just the
names of subdirectories in the directory. ls -I*.* list just entries
without an extension.
Symbolic directory links:
-
To create a symbolic directory link: ln -s {path to existing directory}
<symbolic directory name>
-
This causes the symbolic name to appear in the default directory followed
by an @. Addressing the symbolic name as if it were a directory name
will be the same as addressing the existing directory to which it is linked.
-
You can create your own symbolic links to reduce the amount of typing in
commands. You can remove them with the rm command.
-
If you follow a symbolic link with cd, the prompt and the pwd
command will reflect the symbolic name and path of the directory rather
than the hard name and path. To find the hard name, go to the directory
with the symbolic link and use ls -l.
To find a misplaced file:
-
Type locate <filename>
-
Will find all files in system containing <filename> as a part of the
filename.
-
This requires that the sys adminiatrator is keeping a database of all files
in the system up to date in a default location for the locate program.
To allow a long job to finish executing while you log out:
-
If you want to retain output that would come to the screen, start the job
with >out.log 2>error.log
-
These two files (which could be any names you like) will retain the standard
output and error output that would otherwise come to the screen.
-
After starting the job, type <control Z> to interrupt it.
-
Then type bg to restart it in the background.
-
You can then do other things in the terminal window, including logging
out. The job will run until finished.
-
You can examine the two log files or other files written by the program
to observe the progress of the program, using the cat or tail
commands
to type the contents of a whole file or just the end of it, respectively.
-
In order to tell if the job is finished when you log back in, you will
need to examine the output files and be able to identify an indication
of completion.
To start a job, log out, and then log back in (possibly from elsewhere)
and reobtain control.
Untarring a file:
-
Detailed instructions are found by typing man tar
-
The following examples found in some tar man entires but not others are
helpful:
-
EXAMPLES
tar -xvvf foo.tar
extract foo.tar
tar -xvvzf foo.tar.gz
extract gzipped foo.tar.gz
tar -cvvf foo.tar foo/
tar contents of folder foo in foo.tar