| Parent Directory | Basic Shell Scripts | |
|
Below is a collection of my basic shell scripts: those that I usually make sure are available to me on my desktop systems, typically in /usr/local/bin. Some are better maintained than others. Most were written before I knew how to use the "getopts" function, and so parse any command line arguments "the hard way". I will improve these scripts and add explanation and commentary to this page as time allows. Note: in the usage examples "tty1$ " represents the command prompt. Users need to type in what comes after the "$ ". |
||
|
bookdiff |
Usage:tty1$ bookdiff bookmarks.html bookmarks2.htmlA tool for reconciling forked Mozilla/Firefox bookmark files. The URLs in the two bookmark files are compared, and unique URLs are sorted and written to a file "bookdiff.html" Usage procedure:
Actually, this script could be used to compare any two text files to generate a list of URLs that are in one but not both. Or it could be used to extract all the URLs from any text file by using a blank, "dummy" file as one of the command arguments. |
|
|
c |
Usage: tty1$ cA convenient, one character, screen clearing command, c does more than just "clear". It clears and reinitializes the display. This can help when previous commands have left your display in a strange state. Though written with a text editor, some utilities classify this as a binary file because it contains a CTRL character and uses ANSI control code. |
|
|
cdcopy |
Usage: tty1$ cdcopyA simple one word command for copying CDs. cdcopy assumes cdparanoia and cdrecord are installed on system. It also assumes that the same drive will be used as source and destination, and that this drive is "/dev/cdrw". This script needs work, such as testing these conditions, and addition of comments |
|
|
chargecycle |
A script to be run while a battery powered computer goes through a charge or
discharge cycle, chargecycle will output a timestamped snapshot of the
battery's current charge state, one per line, every two minutes, until stopped
by Output can be collected into logfiles to profile a battery. Usage: tty1$ chargecycle [ OPTIONS ] OPTIONS: -b show battery info only (default) -t show battery and thermal info -T show only thermal info -h show this help message and exit Suggested usage: tty1$ chargecycle | tee chargelog.txt |
|
|
clean |
Usage: tty$ cleanMany of the text editors that I commonly use, including vim, kedit, and kwrite, will create a backup copy of any preexisting file, as opened, upon first file save operation. These backup files will have the same file name as the original, but with a tilde (~) appended to the end. Though it is possible to change the configurations of these editors to turn this feature off, it has saved my bacon just often enough that I don't. To reduce clutter in my working directories, I just run clean from time to time when I'm sure I'm good with the current versions of my files. |
|
|
clearline |
Usage:tty1$ clearline [n] (Default: n=0)clearline is a line clearing terminal utility. Moves cursor upwards n lines, overwriting each line with blank spaces along the way. In the UNIX spirit of terseness I am tempted to call this script cln, but from concern about conflicting with some compiler utility, or some such, with the same name. So I'm sticking with the longer name and aliasing it to cln on a system by system basis. |
|
|
d |
Usage: tty1$ d [file descriptors]A shorthand "dir" command. d outputs a list of almost all files matching [file descriptors] (includes hidden files except the implicit . and ..), in "semi-long" format (like long format except that group ownership is excluded) and pipes output to less filter, while preserving colorization. less exits immediately if the output doesn't fill the screen, or the second time the bottom of the list is reached. After the less exits the disk usage summary of the listed files is given. |
|
|
dff |
Usage:tty1$ dffA utility script with a "one off" name, dff executes df, pipes the output through some filters to remove (usually) extraneous information and formats the output for easy reading. The one off (one extra letter) name allows programs that rely on the output of the standard version to function normally. For example the graphical kdf quit working when I named this file just df. Don't like it? Don't use it. The standard df is still there. |
|
|
dupelist |
Usage:tty1$ dupelist [ OPTIONS ]
OPTIONS:
-h Help: display this usage message and exit.
-o Output to file: Output list of duplicates found to file
'DuplicateFiles.txt' only.
-O Output to file: Output list of duplicates found to file
'DuplicateFiles.txt' and stdout.
-k Keep: Don't delete temp files on exit.
-v (Very) Verbose: output description of each action as it's
done. (debugging only, really)
dupelist is a duplicate file listing script. I originally wrote it
several years ago. It has gone through many revisions. If I were writing it
today I would probably go about it differently, but I have this, and it does
what I need it to do.Executed with no arguments dupelist will output, to stdout, all duplicate files it finds within the current and all child directories. When run with the -o or -O option dupelist will write output to DuplicateFiles.txt. Output filenames will be grouped one filename per line, with blank lines between groups. Keeping the temp files could be useful for further indexing. Verbose output is really only useful for debugging this program itself. dupelist works by calculating, and collecting MD5SUMS of all regular files in the current directory, then recursing all subdirectories calculating and logging MD5SUMs for all regular files found. After collection, MD5SUMS are sorted and checked for duplicates. |
|
|
filecount |
Usage:tty1$ filecount [path]A really simple script I wrote years ago. Looking at it now, it is too verbose for a basic utility, and could use could use more features. But it does what it does, which is give a count of files in the named directory, or current directory if none is given. I'm not rewriting it today. |
|
|
hashline |
Usage:tty1$ hashline [n] (Default: n=1)hashline A terminal utility for writing lines full of hash marks. Useful for demarcating between lines of output of multiple commands. Usage: hashline [n] (Default: n=1) Writes n lines of hash marks to console. In the UNIX spirit of terseness I am tempted to call this script hln, but from concern about conflicting with some compiler utility, or some such, with the same name. So I'm sticking with the longer name and aliasing it to hln on a user by user, system by system basis. |
|
|
how |
Usage: tty$ how [topic]how - a script to list and read Linux How To files. Called without argument how will list all the Linux How To files installed in /usr/share/doc/howto/en/txt . If installed elsewhere script must be edited. How To files are assumed to have filenames of the form: TOPIC.gz or TOPIC-HOWTO.gz . |
|
|
htman |
Usage:tty1$ htman [n] topicThe gnu man command has a switch "-H" or "--html" that directs the output be converted to html and piped to a browser. The browser is either determined by the $BROWSER environment variable or declared on the command line. This command simply saves typing, using Firefox as the browser. |
|
|
infoo |
Usage:tty1$ infoo topicAnother "one letter off" spelling variant command, infoo provides cli access to Linux info pages filtered through the less pager. less is the default pager of the man page system. Man pages are often helpful, but often, particularly with gnu utilities, the user is told to see the info page for complete details on the topic. The info system has its own presentation layer that has several quirks in addition to its intended advantages. The most annoying quirk is the notorious "half page jumpy scroll" where by the displayed page will scroll a half page at a time. By using infoo in place of info the user gains the deeper level of detail of the info page, delivered with the smoothness of the less pager, in exchange for the losing the hyper link capabilities of the info system. I can never remember the magic key sequences needed to make that work any ways. (If I need to go that deep into the info system I'll use a graphical info browser like konqueror.) |
|
| ls commands | Below are several "ls commands" patterned after the common system commands like: ls, ps, lspci, lsusb, and lsof. br> | |
|
lscpu |
Usage:tty1$ lscpulscpu will output, to stdout, the description(s) of the system's cpu(s) stored in /proc/cpuinfo. |
|
|
lsdma |
Usage:tty1$ lsdmaAs the venerable old ISA (Industry Standard Architecture) fades into the sunset the status of static DMAs (Direct Memory Access settings) become essentially meaningless. But if you want it, here it is, listed by lsdma as stored in /proc/dma. |
|
|
lsirq |
Usage:tty1$ lsirqAs with DMAs above, so go IRQ (Interrupt Request) settings. Another legacy of outmoded architectures, IRQ still exist but are largely unused on modern x86 systems. lsirq will output the information stored in /proc/irq. |
|
|
lslibc |
Usage:tty1$ lslibc[ OPTIONS ] OPTIONS: -v verbose description of C standard library. -f list file name of current C standard library (libc.so). -p output version descriptor string from libc.so file. -h help: output this usage information and exit.lslibc: A script to determine the version of C standard library in use on the current system. |
|
|
lsmem |
Usage:tty1$ lsmemMore detailed and verbose than the more common free command, lsmem provides a detailed listing of system memory usage and allocation. |
|
|
lspath |
Usage:tty1$ lspathI find the standard $PATH string hard to read with all the directory names run together. So I wrote lspath which lists the directories in the path string, one per line. Much easier to read. |
|
| End of "ls" commands | End of "ls" commands | |
|
mh |
Usage:tty1$ . <path>/mhWho controls the past controls the future. Who controls the present controls the past. You can control part of your past by managing your bash command history. The bash shell retains in memory (almost) all commands entered, good and ungood, correct and uncorrect, and writes then to a designated history file on exit. Refer to the HISTFILE statement in my example .bashrc file for a comprehensive way to save histories of all logged bash sessions. Memory hole, mh, is a script that kills all bash processes on the current tty without writing any history to disk. To function correctly the file must be sourced. It can be sourced from an alias for convenience. See my sample .alias file for example. (Note some distros use the file name .aliases instead of .alias .) |
|
|
nullcheck |
Usage:tty1$ nullcheck [ OPTIONS ] OPTIONS: -a include hidden files and directories" -d dereference symlinks (to be implemented)" -h print this message and exit" -v verbose: explain what is being done (for debugging only)"A crude test of file system integrity, nullcheck was developed to detect faulty CDs. Method: Crawl the file system, starting in the current directory and copy each file to /dev/null. Only I/O error messages will be shown on console except, in verbose mode. This is an old script I really haven't looked at in years. It worked the last time I needed to use it. (Several years ago I bought a spindle of bad blank CD-Rs.) |
|
|
nwk |
Usage:tty1$ nwkTyping nwk (Of course root permissions are needed to modify init scripts, or network status.) |
|
|
picnamer |
Usage:tty1$ picnamer [ OPTIONS ]
OPTIONS: -h Display this help message and exit.
An interactive script for bulk renaming all jpeg files in current directory
with incrementally numbered files with optional, user defined, prefix and
suffix. Originally written to replace ugly camera generated filenames
picnamer has evolved into a somewhat more general purpose picture
management tool.
DANGER! In some, rather rare, circumstances files with same names but different extentions can get clobbered! |
|
|
picpager |
|
|
|
pinger |
|
|
|
printcrap |
|
|
|
prompt_command |
|
|
|
puzzler |
|
|
|
rip |
|
|
|
rx |
|
|
|
sysinfo |
|
|
|
tputter |
|
|
|
ver |
|
|