Skip to content

Instantly share code, notes, and snippets.

@mgregoro
Created June 27, 2018 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgregoro/ae9943891feccc799b9b011ba5ee93d7 to your computer and use it in GitHub Desktop.
Save mgregoro/ae9943891feccc799b9b011ba5ee93d7 to your computer and use it in GitHub Desktop.
Perl One-liner: Find size of all subdirectories in a given path; and report time taken to scan sub-directory
perl -MString::ShellQuote -E 'opendir(DIR, $ARGV[0]) or die "no: $!\n"; while (my $dir = readdir(DIR)) { next if $dir =~ /^\.+$/; if (-d join(q|/|, join(q| |, @ARGV), $dir)) { say "---------- START $dir ----------"; system("bash -c \"time du -hs @{[shell_quote_best_effort(join(q|/|, join(q| |, @ARGV), $dir))]}\""); say "----------- END $dir -----------\n" }}' $HOME/Library
@mgregoro
Copy link
Author

mgregoro commented Jun 27, 2018

#!/usr/bin/env perl

# The not-line-nose version
use String::ShellQuote;
use v5.10;

opendir(DIR, join(' ', @ARGV) // '.') or die "no: $!\n";

while (my $dir = readdir(DIR)) {
  next if $dir =~ /^\.+$/;
  $ctx_dir = join(q|/|, join(q| |, @ARGV), $dir);
  if (-d $ctx_dir) {
    say "---------- START $dir ----------";

    # time is a bash builtin
    system("bash -c \"time du -hs @{[shell_quote_best_effort($ctx_dir)]}\"");
  
    say "----------- END $dir -----------\n"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment