From e321bbfb7322dc87dae68f77490350ce48fbe600 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Fri, 23 Jul 2021 13:49:07 -0400 Subject: [PATCH] new implementation intended to avoid traversing snapshots --- scripts/files/fast_counter.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/files/fast_counter.sh b/scripts/files/fast_counter.sh index c85723e9..c0d0c1fd 100644 --- a/scripts/files/fast_counter.sh +++ b/scripts/files/fast_counter.sh @@ -1,16 +1,23 @@ +#!/bin/bash +# an attempt to have a "fast" counter of the number of files in a folder, or folders, which will not stray into any snapshot directories present in the filesystem. for dir in "${@}"; do - echo -n "files in '$dir':" - /bin/ls -1fR "$dir" | grep -v "^$" | grep -v "^\.$" | grep -v "^\.\.$" | grep -v ".*:$" | grep -v "\.snapshot" | wc -l + echo -n "files in '$dir': " + # seek out all files under the directory, except ones under the snapshot folder (pattern will match snapshots for either netapp (.snapshot) or dell (.snapshots). + find "$dir" -iname ".snapshot" -prune -or -iname "*" -type f | grep -v "\.snapshot" | wc -l + +#this implementation is the former one, and does not avoid traversing the .snapshot folder on netapp, thus making it super inefficient and complainy. +#the new implementation above is necessitated by needing to avoid multiplying our task by maybe 30 times, due to the snapshots looking mostly just like the original and having just as many files, in general. +# /bin/ls -1fR "$dir" | grep -v "^$" | grep -v "^\.$" | grep -v "^\.\.$" | grep -v ".*:$" | grep -v "\.snapshot" | wc -l +# # patterns that remove files from being counted, above: +# # +# # ^$ -- all blank lines +# # ^\.$ -- all lines with just a dot (current directory) +# # ^\.\.$ -- all lines with just two dots (parent directory) +# # .*:$ -- all lines that end with a colon (directory heading from recursive ls) +# # \.snapshot -- all lines mentioning the snapshot directory. - # patterns that remove files from being counted, above: - # - # ^$ -- all blank lines - # ^\.$ -- all lines with just a dot (current directory) - # ^\.\.$ -- all lines with just two dots (parent directory) - # .*:$ -- all lines that end with a colon (directory heading from recursive ls) - # \.snapshot -- all lines mentioning the snapshot directory. done -- 2.34.1