like thisls)Some descriptions in these notes have more detail available, and are denoted like this:
More details of this item would appear here. The printed notes include all of the additional information
These notes are updated from time to time. The "development"
set of notes are
http://northstar-www.dartmouth.edu/~richard/classes/unix2
Those who do not understand Unix are condemned to reinvent it, poorly.
Usenet signature, 1987
-Henry Spencer

Table of Contents
(1)
pwd -- print working directory). The current directory is initially set to your home directory ($HOME).
cd classes
- All Unix systems have a root filesystem, mounted on /
- A file system is physically a partition of a disk, a whole disk, a logical combination of disks, a removeable device (CDROM), a remotely mounted fileserver, or possibly a virtual construction made to resemble a directory hierarchy
- File systems are mounted and become a part of the hierarchy. They are not referred to as separate entities (unlike MacOS volumes and Windows drive letters).
dfshows mounted file systems- For most purposes, you do not need to know where a file physically resides, only the pathname to it.
ls -li shows links.
There is only one 'real' file.
ln -s real_file link_name ln -s hosts1 h1 ln -s ~richard/public/sendmail mail-notes
Unix actually references all files internally using a numeric value (unique in a given filesystem). The directory itself is just a special file storing human-readable names and their equivalent identifiers (called inodes). Several features are made possible by this arrangement:
- File names can be almost unlimited length, since they aren't moved around internally
- File name lookups are very fast. Obtaining the additional information about a file takes time, (to retrieve the inode data) but simply looking up the names is fast.
- The "." and ".." entries in a directory are trivially implemented as hard links.
- Column 2 of
ls -loutput is the number of links to a file or directory- e.g.
ls -l /usr/bin/mc*
- e.g.
ls -li /usr/bin/mc*
- Creating a hard link:
The same command (ln) is used to create hard links and symbolic links, but with no option.ln existing-file-name new-file-name- The system call to delete a file is
unlink(). When the link count reaches zero, the filesystem actually deletes the file.
(2)
echo $path)printenv) available to other programs.
This is one of the common ways of passing information to programs without
typing it explicitly - typically used for configuration settings.(3)
echo $shell)
, (grep richard /etc/passwd) more .login)echo $path, (echo $variable_name),
the ($) tells the shell that you want the the next text string to be treated like a variable, substitute
the value before evaluating the commandset)set path = /usr/local/bin , (set [variable_name] = [value],
set path = ($path /usr/local/bin))unset path, (unset [variable_name])(4)
echo $shell, to see a user's default shell finger jwallace
/bin/sh (just like any other program)
chsh (works on some systems, not all. Send mail to manager)
$HOME, $PRINTER
*?[] into a sorted list of matching filenames (pathnames).
>> outfile ). Remove
these items - the program does not see this information
echo `date`)
echo, cd)
which ls)
Most commands take optional flags introduced by a "-".
How the arguments are interpreted is up to each individual program, but most programs accept
filename arguments in a predictable way, or attempt to do something natural with standard input if no
filename arguments are present.
Example:
ls
ls *
setenv LSFLAGS -lF
ls $LSFLAGS
(5)
history
set history=100, set savehist=50;
will save history in a file (".history") when you log out
!!; recalls last command,
!10; re-run command 10!pico; re-run last command starting with "pico"
set autolist, set nobeep
set autocorrect, set correct=all
set prompt="%m:%c:%h"
alias his history"
creates an short name for the history command
alias ls ls -FC"
unalias alias_name"
`command`, e.g. "echo `date`"(6)
set cdpath=(~ ~/dir1 ~/dir1/dir2 ...)
set prompt="`hostname`"; Prompt variables
%/ - Full name of current directory
%~ - The current directory using (~) if possible
%m,%M- First component of machine name, entire machine name
set prompt=%n@%m:%~
(7)
* - Match zero or more characters.
? - Match a single character
[...] - Match a range of characters
ls exam[12345] will match files exam1-exam5; can specify a range with ls exam[1-5]
[^..] - Match any character NOT named (tcsh)
^pattern - Match file names NOT matching the pattern
ls exam* - Lists all files that begin with the string "exam"
echo pattern
(8)
> - Takes the output of a command/program and send it to a file,
ls -la > list_file
< - Directs a file to standard input, mail unix10 < list_file
>> - Will append to a file,
note that > will overwrite a file
| takes the output (stdout) of one command and makes
it the standard input (stdin) of another command, connects commands together
ls -la | mail joe.the.smith@dartmouth.edu will take the output of the
ls command and "pipe" it into the mail command;
cat /etc/passwd | wc will send all the lines of the password file to wc (word count)
tee - Displays input and writes it out to a file,
good for verifying arguments; find /usr -name README -print | tee to_read
(9)
chmod ### file_name
chmod 755 - (-rwxr-xr-x)
chmod 744 - (-rwxr--r--)
chmod 000 - (----------)
chmod u=rwx,go=rx - (-rwxr-xr-x)
chmod u=rwx,go=r - (-rwxr--r--)
chmod ugo-rwx - (----------)
(10)
command & - Will place a job in the background
^Z
bg
fg
kill #
renice
at time
(11)
ls
rm
mkdir
rmdir
pwd
chmod
chgrp
ln
find
quota
cp
mv
more,less,pg
view
cat
head
tail (Ex.)
grep
sed
awk
tr
sort
uniq
cut
paste
diff
compress,uncompress,gzip,gunzip
uuencode,uudecode
strings
od
(12)
jmenu
xload
ps
top
kill
nice
jblitz
mail, Mail
pine
elm, mush, mh, xmh
textblitz,xblitz,mbm
lpr
lpq
lprm
pr
lwf
sftp,ftp
sftp is encrypted, built on ssh. ftp is plain
text and no longer recommended
ssh,telnet,rlogin
ssh is encrypted. telnet is plain text
talk
irc
rn,nn,tin
nedit,emacs
vi,emacs,joe,pico
nroff
TeX,LaTeX
spell
framemaker
xv
Photoshop
pbmplus package
gnuplot
(13)
vi
emacs
vim, joe, pico
nedit
cc, c++, javac
f77 FORTRAN 77,f90 FORTRAN 90, BASIC, Cobol, Pascal
(14)
make
Make gets its knowledge of how to build your program from a file called makefile (or Makefile). Make is traditionally used for preprocessing, compiling and linking of source code to build programs, but can also be used for other purposes. It streamlines the process of compiling complex programs by automatically determining which source files of a program need to be recompiled and/or linked. Only the files which are out of date with respect to their dependants are rebuilt.
A makefile consists of rules with the following format:
target: dependencies ...
commands
...
By examining the timestamps on the target file and the
dependencies, make determines if the target is out of date,
in which case the commands (rule) for
this target are executed. Dependency files can themselves be targets, and so a dependency
tree can be constructed. Default rules are supplied for commonly used
operations. A null dependancy set means the target is always out of date, and
the rule is always executed.
myappl: srcfile1.o srcfile2.o srcfile3.o
cc -o myapp1 srcfile1.o srcfile2.o srcfile3.o -lm
srcfile1.o: scrfile1.c myinclude.h
cc -c srcfile1.c
srcfile2.o: scrfile2.c myinclude.h
cc -c srcfile2.c
srcfile3.o: scrfile3.c myinclude.h
cc -c srcfile3.c
clean:
rm -f myapp1 srcfile1.o srcfile2.o srcfile3.o
Note: You need to put a tab character at the beginning of each command line.
It is usually easiest to start with an existing makefile and edit it for a new application. Using the name Makefile is preferred - it appears near the top of the directory listing.
Macros make it easier to define commands and sets of dependancies, and simplify your makefile
Here is an example macro defintion:
OBJS=srcfile1.o srcfile2.o srcfile3.o
To use this macro type $(OBJS)
Here is a new version of the makefile
OBJS=srcfile1.o srcfile2.o srcfile3.o
myappl: $(OBJS)
cc -o myapp1 $(OBJS) -lm
srcfile1.o: scrfile1.c myinclude.h
cc -c srcfile1.c
srcfile2.o: scrfile2.c myinclude.h
cc -c srcfile2.c
srcfile3.o: scrfile3.c myinclude.h
cc -c srcfile3.c
clean:
rm -f myapp1 $(OBJS)
$(CC) - C compiler command (cc)
$(FC) - Fortran compiler command (f77)
$(CFLAGS) - C compiler flags
$(FFLAGS) - Fortran compiler flags
You can add macros to the command line : make myapp1 CC=gcc
Make has many default rules for creating one type of file from another.
There are additional built-in macros to make this easier. ($< stands for the file that
triggered the rule, i.e. the .c or .f file). The mechanism uses the filename suffix
convention used by most compilers.
For example, to compile a C source code file prog.c
and create the object code file prog.o, we need to construct the
command:
cc -c prog.c
The built-in rule which does this is:
.SUFFIXES: .c
.c.o:
$(CC) $(CFLAGS) -c $<
.f.o:
$(FC) (FFLAGS) -c $<
You can add your own default rules to process files in any way that uses the
suffix convention, simplifying the explicit commands in the Makefile.
Use the command make -p to see a list of all predefined
suffixes and macros.
(15)
(16)
(17)