From a363cfc3a2a7feb7f5c26b2e2879976e40118ea7 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sat, 27 Aug 2022 02:01:32 +0200 Subject: [PATCH] Initial commit --- Makefile | 6 ++++++ sfind | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 Makefile create mode 100755 sfind diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8b89e39 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +PREFIX=/usr/local +BINDIR=$(PREFIX)/bin +NAME=sfind + +install: + install -m 755 $(NAME) $(DESTDIR)$(BINDIR)/$(NAME) diff --git a/sfind b/sfind new file mode 100755 index 0000000..f350b2e --- /dev/null +++ b/sfind @@ -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 +# 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;