tour.mm revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.TL "" ""
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerA Tour of the ast Commands and Libraries
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.AU "Glenn Fowler" gsf MH HA6163000 2195 2B-134 "gsf@research.att.com"
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.MT 4
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.H 1 Introduction
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederThe
ad1df93673cf323534cdfe18981ad5daae4c90c0Jonathan von Schroeder.I ast
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroedercommands and libraries were developed by the
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederSoftware Engineering Research Department
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.RI ( aka
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederthe Advanced Software [Technology] Department)
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederat AT&T Bell Laboratories, Murray Hill, NJ.
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederThe strength of
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.I ast
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederis how its individual components
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroedercombine to form a cohesive computing environment across UNIX\u\(rg\d
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederand non-UNIX platforms.
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederCohesiveness*
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroeder.FS
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von SchroederFootnote test.
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder.FE
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederis maintained by well-defined library interfaces for
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederalgorithms upon which the commands are built.
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederIn many cases a library implementation was the driving force behind
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroedercommand implementations.
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder.H 1 Motivation
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederWhy should you consider using the
880945fae9c3f61341f1cd94439c802b7a0af194Jonathan von Schroeder.I ast
c13afb2b57f4673fd4de304b19916fe0b02eaf93cmaedersoftware?
91673dab8e4e249ffb3efe5edab8351dfaf4977dJonathan von SchroederAfter all, many of the commands look like what's already in
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder.L /bin
91673dab8e4e249ffb3efe5edab8351dfaf4977dJonathan von Schroederand
91673dab8e4e249ffb3efe5edab8351dfaf4977dJonathan von Schroeder.LR /usr/local/gnu/bin .
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederAlthough there is some replication, there are also some commands you
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroederwon't find anywhere else:
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroeder.I the
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroederksh93, nmake, the 3d filesystem, cia, and yeast.
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.H 1 Installation
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von SchroederThe
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroeder.I ast
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroedersoftware installs in a single directory hierarchy, rooted at
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.LR $INSTALLROOT ,
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroederusually
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroeder.L /usr/local/ast
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroederor
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.LR /usr/add-on/ast .
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von SchroederThe top level
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.L $INSTALLROOT
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederdirectories are:
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.EX
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder bin executable binaries and scripts
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder fun \fIksh93\fP shell functions
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder lib libraries
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder lib/\fIcommand\fP related files for \fIcommand\fP
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder src/cmd/\fIxxx\fP source for command \fIxxx\fP
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder src/lib/lib\fIxxx\fP source for library \fIxxx\fP
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.EE
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von SchroederTo access the commands and related data files:
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.EX
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroederexport PATH=$INSTALLROOT/bin:$PATH
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.EE
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von SchroederFor each
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.I command
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederthat has a related data file
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.IR file ,
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.I file
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroederis found by searching
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.L $PATH
80ec57e8a62ad520eab08eda504868fe647e71b6Jonathan von Schroederfor
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.IL "" ../lib/ command / file ,
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroedere.g.,
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederthe magic file for the file command is
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.L ../lib/file/magic
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederon
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.LR $PATH .
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von SchroederIf
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.L $HOME/bin
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroederis before
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.L $INSTALLROOT/bin
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederin
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.L $PATH
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroederthen you can selectively override standard
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.I ast
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederrelated files by placing them in the directory
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.IL "" $HOME/lib/ command .
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von SchroederThis allows executables to be built without hard-coded pathnames and also
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederrequires only a change in
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.L $PATH
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederwhen
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.L $INSTALLROOT
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroederchanges.
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroeder.P
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von SchroederOn systems with shared libraries one of
f29920dc584d62689a55b94d9daf1247fedc59f3Jonathan von Schroeder.EX
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroederexport LD_LIBRARY_PATH=$INSTALLROOT/lib:$LD_LIBRARY_PATH
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederexport LIBPATH=$INSTALLROOT/lib:$LIBPATH
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederexport LPATH=$INSTALLROOT/lib:$LPATH
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.EE
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederis required to locate the
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.I ast
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroedershared libraries.
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroeder.H 1 Exploration
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.I tw
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroedercombines
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.I find
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroederand
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.IR xargs .
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von SchroederIt provides C style expressions on path names and elements of
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.LR "struct stat" .
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von SchroederTo find suspicious executables:
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.EX
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroedertw -d / -e "uid=='root' && (mode&'u+s') && parent.uid!=uid"
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.EE
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroederto change the owner of all of bozo's files:
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroeder.EX
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroedertw -d / -e "uid=='bozo'" chown clown:circus
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroeder.EE
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.I tw
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroedercollects file pathname arguments up to the exec arg limit before it
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroederexecutes the command.
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von SchroederFor paranoid users:
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.EX
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroedertw chmod go-rwx
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.EE
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroederwhich is equivalent to:
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.EX
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederchmod -R go-rwx
880945fae9c3f61341f1cd94439c802b7a0af194Jonathan von Schroeder.EE
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder(Now you don't need to add a
880945fae9c3f61341f1cd94439c802b7a0af194Jonathan von Schroeder.L -R
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroederoption to your favorite commands.)
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederTo find all source files that include
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.LR foo.h :
880945fae9c3f61341f1cd94439c802b7a0af194Jonathan von Schroeder.EX
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroedertw -e "name=='*.[chly]'" grep -l '^#.*include.*["<]foo\.h[>"]'
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.EE
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.P
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.I libast
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederhandles the magic number matching for the
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.I file
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroedercommand.
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederThe magic file,
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.LR $INSTALLROOT/lib/file/magic ,
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederis carefully constructed to give the same output across all architectures:
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroeder.EX
880945fae9c3f61341f1cd94439c802b7a0af194Jonathan von Schroedercd $HOME/arch
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederfile */bin/cat
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder.EE
880945fae9c3f61341f1cd94439c802b7a0af194Jonathan von Schroedermight produce:
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.EX
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroederatt.i386/bin/cat: elf i386 executable, 32-bit, little-endian, ..
50bd139c03ca7e618eb93731e152cfaff3aab94dJonathan von Schroederbsd.i386/bin/cat: bsd 386 executable, compact, paged, pure, no..
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroederhp.pa/bin/cat: hp pa-risc executable, shared, dynamically l..
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroedersgi.mips2/bin/cat: elf mips executable, 32-bit, dynamically lin..
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroedersol.sun4/bin/cat: elf sparc executable, 32-bit, dynamically li..
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroedersun4/bin/cat: sun sparc executable, paged, dynamically lin..
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.EE
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.I tw
9c35e9370ba40eda65921ad592e153e8e471e130Jonathan von Schroederuses the same interface, making it easy to search for files based on type,
9c35e9370ba40eda65921ad592e153e8e471e130Jonathan von Schroedername and content.
9c35e9370ba40eda65921ad592e153e8e471e130Jonathan von SchroederThe following searches for executable scripts:
9c35e9370ba40eda65921ad592e153e8e471e130Jonathan von Schroeder.EX
9c35e9370ba40eda65921ad592e153e8e471e130Jonathan von Schroedertw -e "(mode&'+x') && type!=DIR && magic!='*executable*'"
9c35e9370ba40eda65921ad592e153e8e471e130Jonathan von Schroeder.EE
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederThe
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.I tw
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederalgorithm efficiently detects file system loops, so following
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroedersymbolic links is not a problem.
9c35e9370ba40eda65921ad592e153e8e471e130Jonathan von SchroederThe same algorithm is used by all
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.I ast
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroedercommands that traverse
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederdirectory hierarchies,
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroederand the following options to control pathname resolution:
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.EX
9c35e9370ba40eda65921ad592e153e8e471e130Jonathan von Schroeder-L (logical) follow symbolic links
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder-P (physical) don't follow symbolic links
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder-H (metaphysical) -L for command line files, -P otherwise
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.EE
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von SchroederThe
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder.I ksh93
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder.I getconf
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroederbuiltin controls the default traversal mode:
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroeder.EX
0a81f114e958d220a0bebbb90481c0b658f94e8eJonathan von Schroedergetconf PATH_RESOLVE - { logical, physical, metaphysical }
9f6e5ecc1f9743ba77c699f3e533844af9b930bbJonathan von Schroeder.EE
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.H 1 Configuration
87d946b3c13ffd7f6391aa796e786c2b31b122b1Jonathan von Schroeder.H 1 Compression
9503f59b8e16c517ba75df2512b80b354759ad1aJonathan von Schroeder.H 1 Conclusion
bf453a6867cca0aa530bc8cac9eed9c3f70594b4Jonathan von Schroeder