Utility Library

This is a collection of scripts and configuration files for Linux. Many of these are self-authored, others I discovered here and there and made improvements to.

Installation and use of this library of tools.

  1. Download the gzipped tar from here.
  2. Unzip them in some directory on your machine. /usr/local/bin/bsac is my preferred place for them.
  3. Put that special directory on your path. If you use bash you want to say 'PATH=$PATH:/usr/local/bin/bsac; EXPORT PATH' in your .bashrc or .bash_profile file. If you use tcsh then you want to say 'set path=($path /usr/local/bin/bsac)' in your .tcshrc file.
  4. You will also need to set your PERL5LIB environment variable to point to /usr/local/bin/bsac/lib. In bash you do that with PERL5LIB=/usr/local/bin/bsac ; EXPORT PERL5LIB. In tcsh setenv PERL5LIB /usr/local/bin/bsac
  5. If you want to use tcsh command line completion for several common commands, save this file as 'complete' in your home directory and put the line 'source ~/complete' in your .tcshrc file.
  6. If you want to use tcsh command aliases, save this file as 'aliases' in your home directory and put the line 'source ~/aliases' in your .tcshrc file.

TCSH Power Configuration files
aliasestcsh command aliases view
completeconfiguration of tcsh command line completion for some common commands view
Tools for manipulating text files or filtering standard input
srep.plsearch and replace across text files
diffc.pldisplay file differences in color
crlf.plconvert newlines between unix and DOS
wrap.plWrap words in paragraphs at a particular column
unforward.plfilter to strip email forwarding characters from an email message
lw.pldetermine the shortest and longest lines in each file listed
htmlc.plColorize an HTML page
Helpers for better directory listings
xlist a directory or execute a file
seelook at a directory or a file
xdirdisplay a DOSish directory listing
whenshow modification change and access time for files
lsnewerlist files that are newer than a specific file
filesdisplay files in directory
hidfileslist hidden files in directory
subdirslist subdirectories
hiddirsdisplay hidden directories
Tools for processing files
rmuremove files to the KDE trash can
rmcoresremove old core dump files
delmecompare files and delete one if identical
sweep.plsweep backup files away into a trash can directory
chks.plcalculate and verify checksums for multiple files
lnfiles.plcreate symbolic links to all files in a directory
forallexecute a command on all files in a directory tree
cptreecopy a directory tree to another file system
zipwrarchive all writable files in the directory
descattach 4DOS style file descriptions to files
givetochange the ownership and group of a file to a specific user
istext.plcheck if a file is a text file
Tools for editing files
editInvoke my favorite editor or the EDITOR set
viaedit a file wherever it is in your home directory
Helpers for Perl programming
use.plshow where a perl module is found when it is used
regexp.plperform regular expression matching on a string
stripdoc.plstrip comments and documentation from perl source
perlshell.pla simple perl command shell
dblogmonitor a debug log file in the home directory
Tools for developing shell scripts
isevaluate a logic expression and display true ness
dbechoan echo for use while debugging scripts
Miscellaneous
choose.plchoose one item from a list of items
lnurlcreate a shortcut HTML link file to a particular URL
xtitlechange the title bar on an xterm window
Helpers for tcsh command completion or aliases
dotdot.plallow ... abbreviations in path names
pspiddisplay a list of currently running process ids
pscmddisplay a list of currently running process names
svcnamedisplay a list of SysV style init services
_extextract the extension from a files _name
_nameextract the name and extension from a file name
_rootextract the path and name from a file name
_pathextract the path from a file name
Some tools for date/time
dowdisplay the day of the week
deltat.plperform calculations on time of day
Tools for using CVS
mycvsinvoke cvs using vi as editor
pjstat.pldisplay cvs project status
Getting help from the system
grokdisplay maximum help information about a topic
grepdocssearch the installed documentation directories for a string
howtolist HOWTO files or view one
Tools for path manipulation
rmpath.plremove a directory from the path
upath.plremove duplicate directories from the path
Tools for sytem administration
osinfodisplay information about os and machine
lxverdisplay version info for various linux kernel systems
ipinfodisplay machine IP information
fsysdisplay mount points for all mounted file systems
vmsidisplay virtual memory statistics continuously with headers
mntmount a device by trying different filesystem types
snaptake a snapshot of system information
binlist directories containing standard linux programs
chkfsstd.plcheck for conformance with file hierarchy standard
Just for fun
mkfortmake a fortune file of all fortunes matching a pattern
spewtext.plSpew random text continuously on the terminal


TCSH Power Configuration files

aliases
configuration of tcsh command aliases
Several aliases are defined for changing and making directories. Other aliases are defined to shorten commands, make 4DOS commands do something similar on linux. There's a few aliases to manipulate the directories in the path.
complete
configuration of tcsh command completion
The following commands are configured for completion with the tab key:
cd pushd wc rmdir set unset man alias unalias finger ftp sftp ssh kill killall rm netscape lynx find tar ls grep egrep fgrep less perl mount umount zip unzip cp mv xargs at cvs chkconfig

Tools for manipulating text files or filtering standard input

srep.pl
search and replace across text files
srep.pl [-n] [-d] s#hey#there#g ...  [-f] filename...

This utility provides a means of searching and replacing text within files.

-d    Debug,  displays all the s/// code which will be used to replace text.
-n    No changes are performed, but each line that would be changed is printed.
-f    Signals the beginning of files to process.  All arguments after -f
      are interpreted as filenames to search and replace.

If you are specifying only one s/// search and replace command, the -f is
optional.  When you specify more than one s/// then you must provide the
-f to signal the end of search and replace instructions and the start of
files to process.  During the search and replace, $_ will contain the line
of text being processed, $file, $path, $base, $ext will contain the full
filename, path name without file, file without extension and extension,
respectively.
         
You can do some really cool stuff with this if you couple it with find:
find . -iname "*.pl" -exec srep.pl s#This::Module#That::Module#g {} \;
find . -iname "*.pm" | xargs srep.pl s#This::Module#That::Module#g
         
diffc.pl
display file differences in color
diffc.pl old_file new_file
or
diffc.pl cvs_file

Display colored differences between the two files old_file and new_file.
Or display colored differences between the local version and the version
control version if only one file name is specified
         
crlf.pl
convert newlines between unix and DOS
crlf.pl [dos/unix] filename(s)

Converts the newline character for the files specified to a DOS or UNIX
newline if specified otherwise converts the newline to one compatible
with the OS this script is running under.
         
wrap.pl
Wrap words in paragraphs at a particular column
wrap.pl [columns]

This script reads lines from standard input and word wraps
them to the specified column width
         
Handy for reformatting e-mail from some brain dead e-mail clients that won't wrap long lines
unforward.pl
filter to strip email forwarding characters from an email message
unforward.pl

This script will remove the pesky >> characters at the start
of every line of an email message that has been forwarded

Typically used on a console window run it, paste the
forwarded email to the window, grab the fixed text with the
mouse and paste back to email program
         
lw.pl
determine the shortest and longest lines in each file listed
lw.pl files...

Display the longest and shortest line widths in the files specified
         
htmlc.pl
Colorize an HTML page
htmlc.pl - display HTML text with colors
           this performs basic coloring of HTML files on the console
         

Helpers for better directory listings

x
list a directory or execute a file.
x filename
This is handy for exploring /bin /usr/bin or other libraries of executables. It will list the contents of a directory or run an executable file.
see
look at a directory or a file.
see filename
Take a look at (see) a directory or file (or more than one) if a directory, just ls it. if it's executable view the man page otherwise view it with less
         
xdir
display a DOSish directory listing
xdir filemask

          221 2001y02m10d Feb Sat 18:09:47 'dbecho'*
          986 2001y02m12d Feb Mon 19:02:08 'dblog'*
         1639 2001y02m10d Feb Sat 18:09:47 'delme'*
          974 2001y02m10d Feb Sat 18:09:47 'deltat.pl'*
         3265 2001y02m10d Feb Sat 18:09:47 'desc'*
         1036 2001y03m05d Mar Mon 21:01:11 'desc2html.pl'*
         4536 2001y03m02d Mar Fri 20:28:33 'describe_tools'*
         4803 2001y03m05d Mar Mon 21:16:35 'diffc.pl'*
          546 2001y02m10d Feb Sat 18:09:47 'dotdot.pl'*
          101 2001y02m10d Feb Sat 18:09:47 'dow'*
         
You can use sort to arrange the listing as you like it:
xdir | sort           to sort by size
xdir | sort +1 +4     to sort by date and time
xdir | sort +5        to sort by full path name
         
when
show modification change and access time for files
when filemask

Uses the find command to display modification, status change
and last access time for files

   last modified       last status changed        last access
2001y02m10d 18:09:47 | 2001y02m10d 18:15:49 | 2001y02m23d 23:12:09 | "dbecho"
2001y02m12d 19:02:08 | 2001y02m12d 19:02:08 | 2001y03m02d 20:38:37 | "dblog"
2001y02m10d 18:09:47 | 2001y02m10d 18:15:49 | 2001y02m23d 23:12:09 | "delme"
2001y02m10d 18:09:47 | 2001y02m10d 18:15:49 | 2001y03m05d 20:17:29 | "deltat.pl"
2001y02m10d 18:09:47 | 2001y02m10d 18:15:49 | 2001y02m23d 23:12:09 | "desc"
2001y03m05d 21:01:11 | 2001y03m05d 21:01:11 | 2001y03m05d 21:01:15 | "desc2html.pl"
2001y03m02d 20:28:33 | 2001y03m02d 20:28:33 | 2001y03m05d 21:01:15 | "describe_tools"
2001y03m05d 21:16:35 | 2001y03m05d 21:16:35 | 2001y03m05d 21:18:05 | "diffc.pl"
2001y02m10d 18:09:47 | 2001y02m10d 18:15:49 | 2001y03m05d 20:17:29 | "dotdot.pl"
2001y02m10d 18:09:47 | 2001y02m10d 18:15:49 | 2001y02m23d 23:12:09 | "dow"
         
lsnewer
list files that are newer than a specific file
lsnewer [directory] file
List all files in a directory tree that are newer than a specific file

        65536 2001y03m05d Mar Mon 22:07:51 './bsac.vtg'
        23798 2001y03m05d Mar Mon 22:07:51 './utilities.html'

         
files
display files in directory.
list just the files and symbolic links in the current directory. does not list hidden files.
hidfiles
list hidden files in directory.
list just the hidden files and symbolic links in the current directory. this is useful because by default, ls .* lists the contents of all hidden directories, not just their names, very annoying
subdirs
list subdirectories.
list just the subdirectories in the current directory. does not list hidden subdirectories. does not recurse into and list the contents of the subdirectories
hiddirs
display hidden directories.
list just the hidden subdirectories in the current directory. does not list contents of the subdirectories, just their names.

Tools for processing files

rmu
remove files to the KDE trash can. This is kind of like the recycle bin from Windows.
ver 1.01

#############################################################################
#  This program is similar to rm and written in Perl.
#  The program, however, doesn't permanently remove files,
#  but puts the files into a ~/Desktop/Trash directory.
#  The program has the following command line options
#  -i enables user prompt  (on by default)
#  -r recursively operates on directories
#  -f suppresses user prompt
#  -c cleans up the trash can (the program exits after the clean up)
#  -p removes files permanently
#  -l displays list of the files that can be undeleted (in the current directory
#     or in  argument directory)
#  -u undeletes files in the argument directory (current directory by default)
#  -h displays help
#  The command line should be : rmu [options] {file list}
#############################################################################
# This program is written by Ilya Goldman as a first assignment for CTI.
##############################################################################
         
rmcores
remove old core dump files and send an email with a list of recent ones
rmcores <directory> <message-file>
         
delme
compare files and delete one if identical
Usage: delme here there

Compare the files in the 'here' directory with the ones in the 'there' directory
if the files are identical, the one in 'here' is deleted.  Otherwise the files
are visually differenced (with diffc.pl) and the user is asked if the 'here'
file should be deleted.  If the files appear to be binary they are not differenced
         
sweep.pl
sweep backup files away into a trash can directory
sweep.pl [-l] [-s] from_dir home_dir [trash_sub_dir]

This tool sweeps your backup files away to the trash bin.
Backup files match *~.  Ignores files in home_dir/autosave
and home_dir/trash.  Use alias sweep 'sweep.pl ~ ~' to sweep
your home directory.

-help          Displays this usage
-l             Lists the files that would be moved but doesn't move them
-s             Displays a shell script to perform the move but doesn't move them
from_dir       The directory to begin sweeping from
home_dir       The base directory for the trash bin, usually ~
trash_sub_dir  The subdirectory under home_dir. Default is .trashcan
         
chks.pl
calculate and verify checksums for multiple files
chks.pl [-quiet] [-dir] [-recurse] [-output file]
   [-strip path] [-target path]
   [-verify] filenames or directories

Calculate checksums or verify file checksums against a previously
generated checksum listing.

-q or -quiet   When -verify is in effect, only displays failures.
-d or -dir     Scans the list of directories provided and checksums
               all the files in each directory
-r or -recurse If -dir is specified, recurses into each directory
               listed checksumming all files
-o or -output  Specifies the name of a file to echo the checksum
               list to.  Once generated, this file can be used
               with the -verify option.
-s or -strip   When -verify is in effect specifies an initial path
               to strip from the filename read from the checksum file
-t or -target  When -strip is in effect specifies a new base target
               directory to replace the one stripped from the file name
-v or -verify  Reads a checksum file and verifies that the listed
               files still have the same checksum value

Examples:
chks.pl -r -d -o dir.chk /orig
   generate a checksum listing for the /orig directory tree
cp -r /orig/* /copy
chks.pl -q -s /orig -t /copy -v dir.chk
   verify that the files under the /copy directory are identical to the
   files in the /orig directory
         
lnfiles.pl
create symbolic links to all files in a directory
lnfiles.pl target_dir link_dir

This tool will create symbolic links in link_dir to each file in target_dir.
It probably doesn't work right if target_dir contains subdirectories.
         
This is handy to make a giant directory of wallpaper images from various places on your file system for use with the KDE random wallpaper feature
forall
execute a command on all files in a directory tree
from Tips-HOWTO
Raul Deluth Miller,  rockwell@nova.umd.edu
A way to search through trees of files for a particular regular expression.

forall /usr/include grep -i ioctl
forall /usr/man grep ioctl
         
cptree
copy a directory tree to another file system
Usage: cptree source destination

Copy an entire directory tree efficiently.  Useful for copying a tree from
 one file system to another

Modified From Tips-HOWTO
Moving directories between filesystems.
Alan Cox, A.Cox@swansea.ac.uk
         
zipwr
archive all writable files in the directory
Usage: zipwr path archive

Archive and zip all writable files in the directory specified.
Useful when you keep files marked read only and then set writable
the ones that have been modified.
         
desc
attach 4DOS style file descriptions to files
desc filename [description]
or -l [filemask] or -m filename target_dir or -L [filemask]
creates descriptions for files similar to 4DOS
if no description is provided, the current description will be removed.
if -l is used, file descriptions are listed using the optional filemask if provided.
if -m is used, the file and description are moved to the target directory.
if -c is used, the file and description are copied to the target directory.
if -L is used, all files are listed with their descriptions
Note: the -m and -c options assume the file is in the current directory.
         
If you like file descriptions like 4DOs or the old Norton file info this is a good replacement, it just uses symbolic links so you can even use the file description to open or execute the file itself
giveto
change the ownership and group of a file to a specific user
giveto username file
Changes ownership of a file and changes group to 'users'
         
istext.pl
check if a file is a text file
Check if a file is a text file
returns exit code 1 if it is a text file and 0 if it appears to be a binary file
         

Tools for editing files

edit
Invoke my favorite editor or the EDITOR set
edit filenames

invoke my favorite editor or the one set by $EDITOR
         
Handy for writing scripts that need to edit a file
via
edit a file wherever it is in your home directory
Usage: via [-l] [-L] [-r] [-e editor] filename

Edit a file from anywhere in your home directory or anywhere on the file system
without knowing the exact path to the file.  You can specify a partial file match
and select a file from the list of matches.

-l   Uses the 'locate' database to locate files instead of a 'find' in your home directory
-L   Uses grep with the file ~/_files.lst to locate files
-r   Regenerate the file ~/_files.lst containing a list of files in your home directory tree
-e editor Use a specific editor to launch the file found or chosen

If you do not like vi then set the EDITOR variable appropriately.  This script uses choose.pl
to pick the file if more than one is found

Examples:
via *.txt
via -l "*HOWTO*"
         

Helpers for Perl programming

use.pl
show where a perl module is found when it is used
use.pl module

Display what Perl modules are used when included by a 'use' command.
         
regexp.pl
perform regular expression matching on a string
regexp.pl [-nocase] [-nnn] [--] pattern string

Perform Perl regular expression match against a string.
Returns 1 if the pattern matched the string and prints out the match.

-nocase  Ignore case differences in the pattern and string.
-nnn     Instead of displaying the full match, display submatch number nnn.
--       Stops processing options.  The next parameter after this will be the pattern.
pattern  A Perl regular expression to match against the string.
string   The string to match against.
         
stripdoc.pl
strip comments and documentation from perl source
stripdoc.pl

Strip documentation from a Perl file to make it smaller.
         
This has support for POD and # comments but can screw up so be careful
perlshell.pl
a simple perl command shell
dblog
monitor a debug log file in the home directory
dblog [restart] [view] [wipe]
restart   will start a root-tail command to watch your debug.log file on the desktop
view      will allow you to view the entire debug.log file
wipe      will delete the debug.log file

You can activate the Perl DebugLog by setenv DEBUGLOG 1 to append to the log file.
Use setenv DEBUGLOG clobber to always overwrite the log file.  However, this won't
work very well with root-tail
         

Tools for developing shell scripts

is
evaluate a logic expression and display true ness
is logic-expression

Evaluates a logic expression ala the test command and displays 0 or 1 based on trueness
         
dbecho
an echo for use while debugging scripts
dbecho [-n] message

behaves like echo command in tcsh but useful for debugging
when finished debugging just search for dbecho and remove all those lines
         

Miscellaneous

choose.pl
choose one item from a list of items
choose.pl file

Allow the user to choose one item from a file containing a list of items
by using an interactive menu.

You can do some neat stuff:

set file=`choose.pl "ls|"`  # pick one file from current directory
vi `choose.pl "locate document |"`
vi `choose.pl "find ~ -type f -name document |"`
         
lnurl
create a shortcut HTML link file to a particular URL
lnurl filename "title" 'url'

creates a shortcut html file to a particular URL using 'title' as the
description of the target url
         
This just takes a URL from the command line and creates a small HTML file with a link to the URL
xtitle
change the title bar on an xterm window
xtitle title message

Change the title bar of the xterm window
         

Helpers for tcsh command completion or aliases

dotdot.pl
allow ... abbreviations in path names
dotdot.pl [--help] [-pushd] directory

This script is designed to be used along with the alias facility of a number
of shells.  It allows you to change directories upwards by stringing a number
of '.' characters together, just like 4DOS alows you to do.  For example:
cd .... will move you up 3 directory levels, one additional directory for
each . character after the initial ..  The aliases you want to set up are
something like this (in tcsh)

alias cd 'cd `dotdot.pl \!*`'            # allow cd ...../dir
alias pushd 'pushd `dotdot.pl -pushd \!*`'     # allow pushd ...../dir
alias cd.. cd ..
alias .. cd ..
alias ... cd ../..
alias .... cd ../../..
alias ..... cd ../../../..
         
pspid
display a list of currently running process ids
A helper for command line completion of process IDs
display all the process IDs from the ps command

use this to set up completion for the kill command in tcsh:
complete kill 'p/*/`ppid`/'
         
pscmd
display a list of currently running process names
A helper for command line completion of process name for killall command
display all the process names from the ps command

use this to set up completion for the killall command:
complete killall 'p/*/`pscmd`/'
         
svcname
display a list of SysV style init services
A helper for tcsh command line completion, uses chkconfig to get a list of
Sys V init style services found in the /etc/rc.d/init.d directory

Use this to set up TCSH command line completion for the chkconfig program
 complete chkconfig \
  'n@--{list,add,del}@`svcname`@' \
  'c/-/(-list -add -del -level)/' \
  'c/--/(list add del level)/' \
  'n/--level/(2345 345 5)/' \
  'N@--level@`svcname`@' \
  'p/2/(on off reset)/' \
  'p/4/(on off reset)/' \
  'p/1/`svcname`/' \
  'c/*/n/'
         
_ext
extract the extension from a file's name
_ext path/filename.ext will print out 'ext'
_name
extract the name and extension from a file name
_name path/filename.ext will print out 'filename.ext'
_root
extract the path and name from a file name
_root path/filename.ext will print out 'path/filename'
_path
extract the path from a file name
_path path/filename.ext will print out 'path'

Some tools for date/time

dow
display the day of the week
deltat.pl
perform calculations on time of day
deltat.pl expression

This script evaluates a mathematical expression using time.
For example:  8:00 + 0:15 would print out 8:15
         

Tools for using CVS

pjstat.pl
display cvs project status
pjstat.pl

Display cvs project status with color highlighting no less
         

Getting help from the system

grok
display maximum help information about a topic
grok topic

display all information available about the topic
from which, whereis, whatis, man, locate, etc
         
grepdocs
search the installed documentation directories for a string
grepdocs word

grep all the installed documentation for a string
         
this will search /usr/doc, /usr/share/doc, /usr/local/doc, /usr/local/share/doc successively for the word you specify
howto
list HOWTO files or view one
From Tips-HOWTO -- with modifications by Brent S.A. Cowgill
Script to view those compressed HOWTOs.
Didier Juges,  dj@des­tin.nfds.net
         

Tools for path manipulation

rmpath.pl
remove a directory from the path
rmpath.pl [--help] [-cwd] [directories]

Remove specifically named directories from the path.
If no directories are specified then the path is left alone.
If -cwd is specified, it removes the current working directory as supplied
by the `pwd` shell command.

To change the path in a shell (tcsh) use:
set path=(`rmpath.pl directories`)

or

alias rmpath 'set path=(`rmpath.pl !:*`)'
rmpath directories
         
upath.pl
remove duplicate directories from the path
upath.pl ["separator"]

Strip off duplicated directories on the path thus leaving it unique.
The optional separator character is used to join the directories back
together again.  By default it uses the ' ' as a path separator character.

to use this to change the path in a shell (tcsh):
set path=(`upath.pl`)
alias upath 'set path=(`upath.pl`)'
         

Tools for sytem administration

osinfo
display information about os and machine For example, you get something like this:
System Name: Linux
Release:     2.6.12-12
Machine:     i886
Processor:   unknown
Node Name:   hostname
         
lxver
display version info for various linux kernel systems
ipinfo
display machine IP information
fsys
display mount points for all mounted file systems
vmsi
display virtual memory statistics continuously with headers
mnt
mount a device by trying different filesystem types
         
snap
take a snapshot of system information
Take a snapshot of computer system information for record keeping
for consistency, run this immediately after a reboot into X with no programs
running except the single terminal window.
         
bin
list directories containing standard linux programs
chkfsstd.pl
check for conformance with file hierarchy standard
         

Just for fun

mkfort
make a fortune file of all fortunes matching a pattern
         
spewtext.pl
Spew random text continuously on the terminal