NAME
rmhere - Remove all files in the current directory (with options)
VERSION
version 0.02
SYNOPSIS
In a directory with many files which you want to delete:
% rmhere -f
To show progress:
% rmhere -fp
To show progress and count the number of files first (so it'll show percentage up to 100% and estimated completion time):
% rmhere -fP
Delete recursively, set location:
% rmhere -Rf --here /tmp/files
Don't actually delete files, only show:
% rmhere -f --dry-run
Only delete files matching a wildcard:
% rmhere --nodir -R --match '*.txt'
DESCRIPTION
NOTE: Early release, some options not yet implemented: --dir, --file, --match, --recursive.
When deleting many files in a directory (thousands, millions), the venerable rm Unix command is rather cumbersome to use. If you issue rm *
the shell will usually complain with "Argument list too long" because it expands the wildcard first. You can also use find ./ -type f -maxdepth 1 -delete
. This rmhere command is equivalent to that, with some extra options and features:
Progress report
Dry-run
Just set DRY_RUN=1 or
--dry-run
to enter dry-run (simulation) mode.Recursive option
Using
-R
.
For safety, the default behavior is -i
. That means, if rmhere is executed without argument, it will ask before deleting each file.
COMMAND-LINE OPTIONS
--[no]dir, -d
Whether or not to delete directories. The default is to not delete directories.
--dry-run
--estimate
Count the number of files to delete first.
--[no]file
Whether or not to delete files. Default to yes.
XXX Should we have this option at all? Considering that -f is already taken for --force.
--force, -f
Equivalent to --nointeractive.
--here=DIR
Set directory to start deleting.
--[no]interactive, -i
Whether to ask interactively before deleting each entry.
--match PAT
Only delete item matching wildcard pattern PAT
.
--progress, -p
Show progress report.
-P
Equivalent to --progress --estimate.
--recursive, -R
Delete recursively. Turn on --dir
implicitly.
PERFORMANCE NOTES
My system: customer SATA HDD 7200rpm, Debian/Linux, ext3fs, Core i5-2400 3.1GHz. rmhere performs worse than rm for small to medium number of files (1-200k files), but as the number of files approaches 1+ million, there are practically no difference in performance as the bottleneck lies in the filesystem. Some numbers:
Creating 200k files using touch `seq 1 200000`
: 5s.
Deleting 200k files using rm
: 6s.
Deleting 200k files using rmhere -fP
: 1m10s.
Creating 1 million files using touch `seq 1 200000`;touch `seq 200001 400000`;touch `seq 400001 600000`; touch `seq 600001 800000`; touch `seq 800001 1000000`
: 32s.
Deleting 1 million files using rm
fails ("Argument list too long").
Deleting 1 million files using find -type f | xargs -n 50000 rm
: about 30m.
Deleting 1 million files using rmhere -fP
: about 30m.
SEE ALSO
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-rmhere.
SOURCE
Source repository is at https://github.com/sharyanto/perl-App-rmhere.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-rmhere
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHOR
Steven Haryanto <stevenharyanto@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.