Initial commit
This commit is contained in:
commit
a363cfc3a2
6
Makefile
Normal file
6
Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
PREFIX=/usr/local
|
||||
BINDIR=$(PREFIX)/bin
|
||||
NAME=sfind
|
||||
|
||||
install:
|
||||
install -m 755 $(NAME) $(DESTDIR)$(BINDIR)/$(NAME)
|
42
sfind
Executable file
42
sfind
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env perl
|
||||
# Summary: Find regular files with size greater than one or between two given sizes.
|
||||
# Author: Tilman Kranz
|
||||
# Authoremail: t.kranz@tk-sls.de
|
||||
# License: MIT License <https://opensource.org/licenses/MIT>
|
||||
# Depends: libnumber-bytes-human-perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Find;
|
||||
use Number::Bytes::Human qw(format_bytes parse_bytes);
|
||||
|
||||
our $human = shift @ARGV if defined $ARGV[0] && $ARGV[0] eq '-h';
|
||||
our $min = parse_bytes($ARGV[0]);
|
||||
our $max = defined($ARGV[2]) ? parse_bytes($ARGV[1]) : undef;
|
||||
our $dir = defined($ARGV[2]) ? $ARGV[2] : $ARGV[1];
|
||||
our @warnings = ();
|
||||
|
||||
local $SIG{__WARN__} = sub {
|
||||
push @::warnings, shift;
|
||||
};
|
||||
|
||||
sub compare {
|
||||
-f || return;
|
||||
|
||||
my $size = -s;
|
||||
|
||||
defined $::human
|
||||
? printf "% 10s %s\n", format_bytes($size), $File::Find::name
|
||||
: printf "% 10d %s\n", $size, $File::Find::name
|
||||
if defined $::max ? ($::min <= $size <= $::max) : ($::min <= $size);
|
||||
}
|
||||
|
||||
die "Usage: $0 [ -h ] MIN [ MAX ] DIR\n" unless
|
||||
$min >= 0 &&
|
||||
(!defined $max || ($max >= 0 && $min <= $max)) &&
|
||||
-d $dir;
|
||||
|
||||
find(\&compare, $dir);
|
||||
|
||||
map { /^.+$/m; print STDERR $&."\n"; } @warnings;
|
Loading…
Reference in New Issue
Block a user