I'm new to Unix. Got any FAQ for that?
  1. Question: Are you expecting me to be a Unix expert to use Swarm?

  2. Answer: No, but you do have to be willing to learn. If you are new to Unix/Linux, you will no doubt have lots of questions. There will be an initial steep learning curve as you learn commands like these. (The symbol # means "Unix Shell Prompt Here"--that's the place where you type commands. Don't type # at the beginning of commands.)

    # ls --- get a list of files in the current directory (usage tip: "ls -la" gives more information!).
    # cp x y -- copy file x to filename y (usage tip: you can include directory names as part of file names).
    # mv x y--- move file x to file name y (that erases x).
    # rm x --- remove file x (usage tip: type "rm -i x" and watch what happens!).
    # cd dirname ---change to directory "dirname" (cd .. moves you "back one level" in the file system).
    # mkdir dirname --- create a directory called dirname (by default, it is a subdirectory of the current directory).

    After the basics like that, you'll come across more interesting problems and this FAQ is supposed to help you address them.

    Warning about brands and shells. There are several versions of the Unix operating system. You can use Linux, DEC UNIX, HP, etc. There are some subtle differences, especially where free software from GNU is concerned. GNU stuff (like "make" or "gzip") is available as standard on some systems, not others. Also, the shell that is in use--Bourne Shell, Korn Shell, bash, C-shell, etc.--will affect some commands, particularly in the creation of environment variables in the user's setup. So, you have to be self-aware enough to find out what version of UNIX you have and what shell you are using.

  3. Question: I want to know more about those commands. What do I do?

  4. Answer: Try typing

    # man commandname (for example, type "man ls" to see about file lists).

    If the built-in manual system called "man" has an entry for "commandname," you can read it. Some man pages are helpful, many are hopelessly abstract and discouraging to a new comer. There are many manuals you can buy for Unix beginners.

    Also, there is the GNU info program. GNU folks have tried to convince everyone that man pages are bad and that the info format is good (that's why so many man pages say "this is old, use the GNU info page to get the real information). The command "info" will bring up the GNU information pages. If you have Emacs or XEmacs installed, you have easy access to info.

  5. Question: I'm trying to compile a program and the compiler can't find a file. What do I do? Where is that file?

  6. Answer: The compiler probably has to be told in which directory it will find that file. How you specify the location may depend on the program you are compiling. It may be set in an environment variable, a makefile, or a gcc command option.

    Now, how do you find out where the file is on your system? If you have that file in your file system, commands like "find" and "whereis" and "locate" can be used to find out where they are.

    1) The find command

    Example (Rick Riolo): Type this (don't type #. Remember, that's the shell prompt!):

    The above command looks at all the directories on the system below / (root dir), but you could also look in specified subtrees, eg find /usr -name "libX11.a" -print. (Editor's Note: On my system, the -print option is not necessary. It is assumed by default. To speed up the search, add the option -xdev before -name. This confines the search to the current file system, meaning that DOS drives that may be mounted are ignored. If one is unsure of a file's full name, add asterixes around the part that you are searching for, such as "*name*". This is regular expression syntax. The "cannot open" messages are not errors. They are a result from some directories refusing to allow themselves to be inspected because the user does not have permission to open them. )

    To find the all versions of X11 library files, such as libX11.a, one can use regular expression syntax, as in:

    (Of course, the response on your system will depend on what file you have! :) )

    2) The whereis command (Ginger Booth):

    3) The locate command (Jan Kreft):

    I use locate instead of find because I don't have to remember any syntax and locate is much faster so you don't waste time if you made a typo and have to repeat the search.

    locate .gif will print all the gif pictures you have on your disk in an instant. Very nice.

    To be able to use locate, cron.daily (called by the cron daemon) must be configured to update the locatedb database once per day. You must have sys adm rights to do this. The details may be rather system specific.

  7. Question: I need to find a few lines in a massive pile of output that runs up the screen. How?

  8. Answer: The first option is to pipe the results into less or more by adding |less (or |more) on the end of your command. (less is the gnu version of more, so some systems have less and more, but HP or DEC systems might have only more). This will make sure it prints one screen at a time. The more sophisticated and easy answer is to pipe the results to the grep program, which will then pluck out all lines that have a certain word.

  9. Question: My simulation dumps a lot of labels and data into several files. How can I extract the data I want to import into a spreadsheet/plotting package?

  10. Answer (Jan Kreft): Use filters such as grep, cut, paste, uniq, join

  11. Question: My fingers ache from typing long commands and I can't remember all that crap. What can I do about it?

  12. Answer: Use alias. Alias lines can be added to the Unix startup files (.bashrc, .cshrc, or .profile, depending). If you find yourself typing a command all the time, create an alias so that you can type just a few letters and the machine thinks you typed the whole long command.

    Example (Rick Riolo): I find alias very useful for making shortcuts for stuff I do all the time.

    The first is to find out whether some program is running (eg to find out what the process id is so I can kill it!): The second is to find out exactly what command I entered a while ago (without have to scroll or arrow-key back...this depends on using a shell like tcsh which has a history command:) The number on the left is the command number in the history list, next is the time of execution, and then the command.
  13. Question: I've got two files that I need to compare. What to do?

  14. Answer: Consider the "diff" command. It will compare files, and also can execute patches (see the manual...)!

    Example: (Ginger Booth) Compare (few) source code changes between versions.

    An alias command can be added to the .cshrc file like this:

    so the command "cmf" activates "diff" with all those options. Please consult "man diff" for your options. If your shell is different, a slightly different format for the alias command may be needed. Consult documentation for your shell.

    For example, to compare two files, source/Diffuse.h and fromjanwith/Diffuse.h, you type

    It's hard to get really legible output out of this, but the above says I changed (!) an import to an include (lines 2-4 shown for context), and added (+) two routines (lines 64 and 104 in the 2nd file.)
  15. Question: How can I quickly find out how many lines of code I have?

  16. Answer: Use wc -l.

    Example: (Ginger Booth) The command wc -l will count lines of code, as a rough progress measure or version compare.

    # wc -l source/*.m
    127 source/Base.m
    416 source/Carnie.m ...
    39 source/main.m
    14394 total

  17. Question: I downloaded a file with the tar.gz extension. How do I use it? (The extension tgz is usually the same thing, but tar.gz has been contracted. A file with extension Z is compressed with the standard unix compress program and the user should use uncompress to unpack it. There's a man page for it.)

  18. Answer 1. This file is a GNU-zipped tarball! The program "tar" crams a bunch of files into one file (with a tar suffix). GNU-zip is a compression program for UNIX (comparable to PKzip for DOS). First, figure out where you want to unpack the archive. Move it in that directory. Then un-gzip, then untar. Type

    This creates directories if they are called for in the tar file, or writes files into existing directories if you have unzipped the files from a directory where the system can find the right subdirectories.

    If you are fond of pipes, you can do this in one shot (notice we show gunzip in placeof gzip -d for variety).

    The switch -c sends the output of the unzipping process to the command after the pipe, where it is picked up because the "stdin" is called for by the dash after xvf.

    Answer 2. Simple one step command available on some Unix systems (not AIX, DEC, or HP if they are "out of the box" versions):

    This works for files with suffix .tgz as well.

    Answer 3.  For safety, before untarring consider getting a listing of what is in there. It could be that the person who created the tarball did a crappy job and they are going to dump files all over your hard disk, so WATCH OUT. If you have already unzipped a file, you can use the tar command to view a list of the contents by typing:

    This gives a file list.

    If your tar allows the z switch, then you can look at the contents of the tarball without unzipping it. This is the command:

      #tar -tvfz filename.tar.gz | less
    (If you don't have the "less" program, use "more")
  19. Question: Any other interesting tar facts worth knowing?

  20. Answer 1. Tar can create an archive for you. To put all the files and directories under /users/someone/ into a tar archive called bozos.tar, type

      tar cvf bozos.tar /users/someone/*

      The switch "c" creates an archive', "v" gives back a verbose report on the process, and "f" tells tar that a file list is following. The * means that every file and every subdirectory will recursively be put into the tar file. If you only want to get the files with extension jpg, replace * with *.jpg. Caution, do not type this:

      # tar cvf filename.tar *

      That will make the tar program try to put filename.tar into itself! It doesn't cause a crash, just a weird tar file. That's why it is best to put in absolute paths (such as /users/someone/* when you create tar archives.

    Answer 2. Notice that some people put a - sign before the switches in a tar command and others don't. They used to be required on most unix systems, now they aren't, but most commands work either way.  Rather than be consistent, I've left most of the examples provided by others in the style they chose.

    Answer 3. (Rick Riolo) You can extract particular files without dumping them all. If you want a file called Tribble.m that is in a directory called "source" in a tar file, do this:

      tar xvf tarfile.tar source/Tribble.m
    Answer 4. As an example of how tar can be used to ship files to a colleague, consider this example (Ginger Booth). Suppose a directory called backups exists. In backups, we want to create a tarball called prestats.tar. Tar is going to get files from a directory called source (in this case, the files are Base.m and Critter.m).
      # tar -cvf backups/prestats.tar source
      a source/Base.m 8 blocks
      a source/Critter.m 33 blocks
      ...
      # ls backups
      prestats.tar
      ...
      # gzip backups/prestats.tar
      # cd backups
      /users/ginger/Sgecko/gecko/backups
      # ls
      prestats.tar.gz
      ...
    Now, you've got it tarred and gzipped. If you wanted to reverse the process, do this:
      # gunzip prestats.tar.gz
      # tar -xvf prestats.tar
      x source/Base.m, 3674 bytes, 8 tape blocks
      x source/Critter.m, 16419 bytes, 33 tape blocks ...
      #114: ls
      prestats.tar source
  21. Question: I just installed a new shared library and the programs that use it say they can't find it. Unix really stinks!

  22. Answer: That's what I thought too. Then I heard about ldconfig. On my Linux machine, it works like this. The ldconfig program runs every time you start your machine, and it maintains a listing of libraries that are available for programs to use. If you don't restart, chances are the library you installed is not yet known to your system. If you don't want to restart, find out where your system has ldconfig, and execute it. In my Red Hat Linux system, it is in the directory /sbin, so I type

    (Actually, before I do that, I look in the file called /etc/ld.conf to make sure the directory into which I added the library is included in the ldconfig's search path. If it is not in there, I add it.)

    And then to get a listing of the files the libraries the system knows it has, type

    Look it over. On the left are "stub" names of libraries. A library will have a version name like 2.3, where 2 is the "major version" and 3 is the "minor version." In the library, there is a hardcoded "stub" which indicates that this library will respond to a request for a certain library name, usually it cuts off the minor version number. In the listing, on the right are stub names that provide the needed information or there are symbolic links to files that can do it. If a system is looking for Motif library version 1.2.4, for example, the ldconfig program will look at the file libXm.so.1.2.4, and it will do two things. First, it sees the "stub" name, the major version name, is libXm.so.1, and it will create a link that points from libXm.so.1 to libXm.so.1.2. That's from the major name to the first minor version name.  Then ldconfig will create a symbolic link in the directory where it finds that library from libXm.so.1.2 to libXm.so.1.2.4. So, any program that calls for the Motif library should ask for the major version libXm.so.1, and then the ldconfig knows it has that, follows the links to libXm.so.1.2.4.
  23. Question: Even after ldconfig, my program can't find a library. What's up?

  24. Answer: Gee, maybe you installed the wrong version of the library! If you are a Linux user, use the ldd program to find out what version your program is looking for. "ldd program-name" causes a list of libraries that the program uses to be printed on the screen. Other Unix systems have similar facilities.

    Example: Netscape for linux includes a version dynamically linked to Motif library 1.2.4. That file is called libXm.so.1.2.4, but when Netscape-dynamic is executed, it asks for libXm.so.1.2, and the linker figures out what it needs. The output from ldd on a Red Hat Linux 4.2 machine looks like this: