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.
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.
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!):
find: cannot open /dev/diag
/usr/lib/X11R5/libX11.a ...
To find the all versions of X11 library files, such as libX11.a, one can use regular expression syntax, as in:
find: cannot open /dev/diag
find: cannot open /usr/lib/X11/fonts/ifo.st/typefaces
/usr/lib/X11R4/libX11.sl
/usr/lib/X11R5/libX11.sl
/usr/lib/X11R5/libX11.a
2) The whereis command (Ginger Booth):
X11: /usr/bin/X11 /usr/local/bin/X11 /usr/local/lib/X11 /usr/contrib/bin/X11 /usr/contrib/lib/X11
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.
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.
ginger 24257 24088 0 13:10:26 ttyp4 0:04 netscape -install
# ls -al /tmp | grep "Aug 25"
drwxrwxrwx 3 root root 37888 Aug 25 13:40 .
-rw-r--r-- 1 ginger staff 0 Aug 25 10:17 SPCBAAa23733
-rw------- 1 ginger staff 366 Aug 25 10:46 jea23850
-rwx------ 1 ginger staff 771475 Aug 25 13:37 mbox.ginger
-rw------- 1 ginger staff 1724 Aug 25 13:40 snd.24249
Answer (Jan Kreft): Use filters such as grep, cut, paste,
uniq, join
file 1: bac.log
min 0 vol 0.399996
Time: 0
min 0.1 vol 0.40122
Time: 1
min 0.2 vol 0.402444
Time: 2
file 2: bac.biomassGraph
0 231.997666 0.805550
1 232.707558 1.611180
2 233.417510 2.418453
Aim: Only the values for min and vol of the first file and the second column of the second file are to be imported into a spreadsheet.
Step 1: grep file 1 for lines containing min, then cut fields 2 and 4 and output into file tmp.
grep min bac.log | cut -f2,4 -d" " > tmp
Step 2: cut field 2 from file 2 and output into file tmp2.
cut -f2 -d" " bac.biomassGraph > tmp2
Step 3: combine corresponding lines horizontally from files tmp and tmp2 and output into file tmp3.
paste -d" " tmp tmp2 > tmp3
Result: file tmp3
0 0.399996 231.997666
0.1 0.40122 232.707558
0.2 0.402444 233.417510
This file can be imported into Excel etc. Note that the option -d" " was used throughout to produce blanks as delimiters (memo d=delimiter). The option -f was used to specify the field numbers for cut (memo f=field). Use command --help to remind you of the syntax and options and man command for more detailed explanations.
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.
1085 950 2 21:58:43 ttyp7 0:00 grep emacs
1009 946 0 08:58:37 ttyp6 0:07 emacs Notes-Series3.txt
191 15:20 wc Classifier/BasicCollection.m
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:
For example, to compare two files, source/Diffuse.h and fromjanwith/Diffuse.h, you type
! #import <objectbase.h>
#import "Base.h"
--- 2,4 ----
! #include <objectbase.h>
#import "Base.h"
***************
*** 63,64 ****
--- 63,65 ----
-copymom; // self=mom, returns copy
+ -copyTo: (DiffuseQuad*) newbie; // no alloc
-addSiteParams;
***************
*** 102,103 ****
--- 103,105 ----
-(int) getCellsY;
+ -(int) getSubSteps;
-setSubSteps: (int) i;
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
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
(The commands "gzip -d" and "gunzip" are the same!)
and then (if you trust the package, proceed. Otherwise, look at answer 3 below)
#tar -xvf filename.tar.gz
If you are fond of pipes, you can do this in one shot (notice we show gunzip in placeof gzip -d for variety).
Answer 2. Simple one step command available on some Unix systems (not AIX, DEC, or HP if they are "out of the box" versions):
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:
If your tar allows the z switch, then you can look at the contents of the tarball without unzipping it. This is the command:
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
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 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:
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
And then to get a listing of the files the libraries the system knows it has, type
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: