(c) 2001-2005 Matt Chisholm
matt dash shelltools at theory dot org
ShellTools is a set of Python tools designed to enhance the standard *nix set of command line tools. It has four subparts:
I consider a number of these programs as experimental, proof-of-concept, or as demonstrations for enhancements that could be made to existing programs. To that end, they are licensed under the GNU GPL and I would be glad to see their functionality incorporated into other projects. However, that is not to say that they are not ready for everyday use; I use them all the time and find them very robust.
The latest version is available from http://www.theory.org/~matt/shelltools/download/
These tools provide a number of alternative display methods for groups of files. There are five different displays:
dim.py
A reimplementation of my dim layout algorithm, which arranges files in a grid, organized vertically by file name and horizontally by file extension. The algorithm helps you to quickly see relationships between complex sets of files.
canopy.py
A display for directory hierarchies that arranges directories horizontally and their contents vertically, ideal for wide, shallow hierarchies.
tree.py
A display for directory hierarchies that arranges directories and their contents vertically, ideal for narrow, deep hierarchies.
list.py
A basic list of files arranged in columns, similar to ls, but sharing the same set of command line options as the other Termfile tools.
All of the Termfile programs support the user's dircolors, if they exist. They all take the same set of command line options:
Basic options:
-a list all files
-d list directories only
-h show this help
-l list mode (display all file information, total # files)
-L show symbolic link targets
File information options:
-p display permissions (in octal)
-u display username
-g display group
Size display options:
-s display file-size intelligently
-b display file-size in bytes
-k display file-size in kilobytes
-m display file-size in megabytes
-G display file-size in gigabytes
-T display file-size in terabytes
-P display file-size in petabytes
-i use 1024 bytes in a kilobyte (kibibyte) (default)
-y use 1000 bytes in a kilobyte
-U NUMBER use NUMBER as block size
Time/date display options:
-t display modification time intelligently
-t TIMEFMT display modification time according to timefmt (see man date)
Movetools is a set of commands for moving sets of files. When moving a large group of files, the entire group is checked for name collisions against the before any of the files are physically moved. When a name collision is encountered, the colliding files are compared by size and md5sum, and if the files appear to be the same, the moved file will be silently removed. After the entire set of files is compared for collisions, the program either moves the files, or reports the collisions to the user and exits, without altering any files. There are three basic commands:
move.py FILE1 FILE2 ... FILEN DIRECTORY
Moves all FILES into DIRECTORY, after checking for collisions.
merge.py DIRECTORY1 DIRECTORY2 [ DESTINATION ]
Moves all files in directories 1 and 2 into a common directory, after checking for collisions. If destination is omitted, a destination name is guessed based on the common part of directories 1 and 2.
collapse.py DIRECTORY
Moves all files into its parent directory. Equivalent to: move.py directory/* . rmdir directory/
group.py FILE1 FILE2 ... FILEN
Examines the names of all files and guesses a common directory name, and moves all files into that directory, creating the directory if it does not exist, and checking for collisions if it does exist.
Recursive checking of subdirectories is planned for a future release.
The grab - drop - lose set of commands is for selecting a group of files to move in several steps, and then selecting a set of destinations for some or all of those files at a later date. It can be thought of as a superset of the Copy & Paste interface for moving files in some common GUI file managers. It consists of four commands:
grab.sh FILE1 FILE2 ... FILEN
grab.sh calls grab.py and adds all listed files to the $GRAB environment variable.
lose.sh [FILE1 FILE2 ... FILEN]
lose.sh removes all listed files from the $GRAB environment variable, or removes all files from the $GRAB environment variable if it is called without any arguments.
drop.sh [FILE1 FILE2 ... FILEN]
drop.sh moves all listed files to the current directory, if they have been previously grabbed. If called without any arguments, it moves all files in the $GRAB environment variable to the current directory.
grablist.py
Lists the files currently in the $GRAB environment variable.
Here's an illustration of how to use grab - drop - lose set of commands. Assume I have some files in a directory that I want to organize into various places. First, I grab the files:
$ grab.sh image.jpg README.txt script.py
Then, I go looking for where I want to save README.txt, and cd to the directory where I want to move it to, and drop it:
$ drop.sh README.txt
Then, I notice that there is another file in this directory that I want to reorganize too, so I grab it too:
$ grab.sh picture.gif
Then, I go looking for a place to put image.jpg and picture.gif, but in the meantime I decide that I don't actually want to change the location of script.py, so I lose it:
$ lose.sh script.py
Finally, I find a good place for picture.gif and image.jpg, but first, I want to make sure I haven't grabbed any other files along the way by accident:
$ grablist.py
/home/user/path/to/picture.gif
/home/user/other/path/to/image.jpg
Now I'm ready to drop both files into the current directory:
$ drop.sh
That's it. I've moved three files from two different locations into two other different locations, without having to plan out beforehand what I was going to put where.
The number list tools are for displaying and manipulating sets of files with numerical, sequential names.
numls.py
Lists files by collapsing entries that are numerically in sequence, ideal for seeing quickly which files from a series or sequence are missing.
expstr.py PATTERN
Expands numerical ranges in brackets found in PATTERN. For example:
$ expstr.py file[18-22].ext
file18.ext file19.ext file20.ext file21.ext file22.ext
$ expstr.py file[0008-13].jpg
file0008.jpg file0009.jpg file0010.jpg file0011.jpg file0012.jpg file0013.jpg
$ expstr.py file[333-6].ext
file333.ext file334.ext file335.ext file336.ext
expstr.py is meant to be used with backtick (``) syntax in the shell. For example:
$ rm `expstr file[0-100].jpg`