Table of Contents

Name

direntries - fast manage entries in a directory

Synopsis

direntries [directory]
direntries -r [directory]
direntries -m [ -d depth ] [directory[/./subdirectory]]
direntries -s [ -p ] [ -e filename-extension ] [ -P filename-prefix ] [directory]
direntries -D [ -e filename-extension ] [ -P filename-prefix ] [ -t min-age-in-days ] [directory]

Description

The primary purpose of this tool is native and fast working with directories containing many files. Some filesystems like ext2, ext3 and more have dramatically performance breakdowns on directories with hundreds of thousands files in it. Common tools like "ls" or shell wildcards with sorting make listings, deletions and more too slow too manage. This tool steps natively through the directory entries list, does not sort and makes use of leaf optimization if possible.
In the first mode ( normal mode ) direntries just counts all entries within a directory.
In the second mode ( recursive mode ) it does the same with recursively stepping into subdirectories. In recursive mode direntries makes use of leaf optimization to speed up counting.
The third mode is called maximum mode and it is used to search recursively for the directory with the most entries. With the parameter depth a limit of the recursion level can be set (0 means no limit). If you specify one dot in the path of the directory/subdirectory it will be interpreted as a wildcard like "*" in the shell but even faster, i.e. /home/./html is the same as /home/*/html in the shell.
In show mode you get a small statistic about some frequently on webservers found extensions like i.e. .gif or .jpg. You can also specify a extension or a prefix for the filenames. The specified extension has priority over a specified prefix. The p-option enables the printing of all matching filenames.
The delete mode is very useable if you have have directories with hundreds of thousands files (i.e. .gif) within a directory. In the delete mode direntries removes entries in a dir faster than any combination of standard shell commands. You can also specify a extension or a prefix for the filenames. An optional min-age-in-days argument can be used for deletion of files older than min-age-in-days days. The specified extension has priority over a specified prefix. After deleting the amount of deleted files is printed.
If no directory is given then the working directory "." is used.

Examples

direntries /tmp # fast replaces "find /tmp 2>/dev/null|wc -l"
direntries -m -d 2 /home/www/./html/typo3temp
direntries -s -e .html ~webXXXX/html
direntries -D -e .gif ~webXXXX/html/typo3temp/pics


Common command sequence:

$ direntries -m -d 2 /home/www/./html/typo3temp

234564

/home/www/webXXX/html/typo3temp/pics

$ direntries -s /home/www/webXXX/html/typo3temp/pics

jpg: 0

.gif: 234564

.js: 0

234564

$ direntries -D -e .gif /home/www/webXXX/html/typo3temp/pics


Caveats

The maximum internal absolute pathname length is 16384 chars.
In normal mode also the directory entries "." and ".." will be counted.
Errors like "permission denied" are silently ignored.
Due to "leaf optimization" in recursive mode it can produce wrong results on non-unix-like filesystems.

Author

Frank Bergmann, http://www.tuxad.com


Table of Contents