1.TL "" "" 2A Tour of the ast Commands and Libraries 3.AU "Glenn Fowler" gsf MH HA6163000 2195 2B-134 "gsf@research.att.com" 4.MT 4 5.H 1 Introduction 6The 7.I ast 8commands and libraries were developed by the 9Software Engineering Research Department 10.RI ( aka 11the Advanced Software [Technology] Department) 12at AT&T Bell Laboratories, Murray Hill, NJ. 13The strength of 14.I ast 15is how its individual components 16combine to form a cohesive computing environment across UNIX\u\(rg\d 17and non-UNIX platforms. 18Cohesiveness* 19.FS 20Footnote test. 21.FE 22is maintained by well-defined library interfaces for 23algorithms upon which the commands are built. 24In many cases a library implementation was the driving force behind 25command implementations. 26.H 1 Motivation 27Why should you consider using the 28.I ast 29software? 30After all, many of the commands look like what's already in 31.L /bin 32and 33.LR /usr/local/gnu/bin . 34Although there is some replication, there are also some commands you 35won't find anywhere else: 36.I the 37ksh93, nmake, the 3d filesystem, cia, and yeast. 38.H 1 Installation 39The 40.I ast 41software installs in a single directory hierarchy, rooted at 42.LR $INSTALLROOT , 43usually 44.L /usr/local/ast 45or 46.LR /usr/add-on/ast . 47The top level 48.L $INSTALLROOT 49directories are: 50.EX 51 bin executable binaries and scripts 52 fun \fIksh93\fP shell functions 53 lib libraries 54 lib/\fIcommand\fP related files for \fIcommand\fP 55 src/cmd/\fIxxx\fP source for command \fIxxx\fP 56 src/lib/lib\fIxxx\fP source for library \fIxxx\fP 57.EE 58To access the commands and related data files: 59.EX 60export PATH=$INSTALLROOT/bin:$PATH 61.EE 62For each 63.I command 64that has a related data file 65.IR file , 66.I file 67is found by searching 68.L $PATH 69for 70.IL "" ../lib/ command / file , 71e.g., 72the magic file for the file command is 73.L ../lib/file/magic 74on 75.LR $PATH . 76If 77.L $HOME/bin 78is before 79.L $INSTALLROOT/bin 80in 81.L $PATH 82then you can selectively override standard 83.I ast 84related files by placing them in the directory 85.IL "" $HOME/lib/ command . 86This allows executables to be built without hard-coded pathnames and also 87requires only a change in 88.L $PATH 89when 90.L $INSTALLROOT 91changes. 92.P 93On systems with shared libraries one of 94.EX 95export LD_LIBRARY_PATH=$INSTALLROOT/lib:$LD_LIBRARY_PATH 96export LIBPATH=$INSTALLROOT/lib:$LIBPATH 97export LPATH=$INSTALLROOT/lib:$LPATH 98.EE 99is required to locate the 100.I ast 101shared libraries. 102.H 1 Exploration 103.I tw 104combines 105.I find 106and 107.IR xargs . 108It provides C style expressions on path names and elements of 109.LR "struct stat" . 110To find suspicious executables: 111.EX 112tw -d / -e "uid=='root' && (mode&'u+s') && parent.uid!=uid" 113.EE 114to change the owner of all of bozo's files: 115.EX 116tw -d / -e "uid=='bozo'" chown clown:circus 117.EE 118.I tw 119collects file pathname arguments up to the exec arg limit before it 120executes the command. 121For paranoid users: 122.EX 123tw chmod go-rwx 124.EE 125which is equivalent to: 126.EX 127chmod -R go-rwx 128.EE 129(Now you don't need to add a 130.L -R 131option to your favorite commands.) 132To find all source files that include 133.LR foo.h : 134.EX 135tw -e "name=='*.[chly]'" grep -l '^#.*include.*["<]foo\.h[>"]' 136.EE 137.P 138.I libast 139handles the magic number matching for the 140.I file 141command. 142The magic file, 143.LR $INSTALLROOT/lib/file/magic , 144is carefully constructed to give the same output across all architectures: 145.EX 146cd $HOME/arch 147file */bin/cat 148.EE 149might produce: 150.EX 151att.i386/bin/cat: elf i386 executable, 32-bit, little-endian, .. 152bsd.i386/bin/cat: bsd 386 executable, compact, paged, pure, no.. 153hp.pa/bin/cat: hp pa-risc executable, shared, dynamically l.. 154sgi.mips2/bin/cat: elf mips executable, 32-bit, dynamically lin.. 155sol.sun4/bin/cat: elf sparc executable, 32-bit, dynamically li.. 156sun4/bin/cat: sun sparc executable, paged, dynamically lin.. 157.EE 158.I tw 159uses the same interface, making it easy to search for files based on type, 160name and content. 161The following searches for executable scripts: 162.EX 163tw -e "(mode&'+x') && type!=DIR && magic!='*executable*'" 164.EE 165The 166.I tw 167algorithm efficiently detects file system loops, so following 168symbolic links is not a problem. 169The same algorithm is used by all 170.I ast 171commands that traverse 172directory hierarchies, 173and the following options to control pathname resolution: 174.EX 175-L (logical) follow symbolic links 176-P (physical) don't follow symbolic links 177-H (metaphysical) -L for command line files, -P otherwise 178.EE 179The 180.I ksh93 181.I getconf 182builtin controls the default traversal mode: 183.EX 184getconf PATH_RESOLVE - { logical, physical, metaphysical } 185.EE 186.H 1 Configuration 187.H 1 Compression 188.H 1 Conclusion 189