"Fossies" - the Fresh Open Source Software Archive 
Member "fslint-2.46/fslint/finded" (2 Feb 2017, 2618 Bytes) of package /linux/privat/fslint-2.46.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "finded":
2.44_vs_2.46.
1 #!/bin/bash
2
3 # finded - find empty directory branches
4 # Copyright © 2000-2009 by Pádraig Brady <P@draigBrady.com>.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 # See the GNU General Public License for more details,
15 # which is available at www.gnu.org
16
17 script_dir=$(dirname "$0") #directory of this script
18 script_dir=$(readlink -f "$script_dir") #Make sure absolute path
19
20 . "$script_dir"/supprt/fslver
21
22 Usage() {
23 ProgName=$(basename "$0")
24 echo "find Empty Directory branches.
25 Usage: $ProgName [[-r] [-f] paths(s) ...]
26
27 If no path(s) specified then the current directory is assumed."
28 exit
29 }
30
31 for arg
32 do
33 case "$arg" in
34 -h|--help|-help)
35 Usage ;;
36 -v|--version)
37 Version ;;
38 *|-r)
39 test "$arg" = "-r" && recurse="false"
40 argsToPassOn="$argsToPassOn $(shell_quote "$arg")" ;;
41 esac
42 done
43
44 . "$script_dir"/supprt/getfpf -f "$argsToPassOn"
45 #forcing -f as if specify an empty dir it would not display
46
47 if test "$recurse" = "false"; then
48 find "$@" -empty -type d ! -name "*$LF*" -printf "$FPF\0" |
49 sort -zu | #merge dirs (indirectly) specified multiple times
50 if [ ! -p /proc/self/fd/1 ]; then
51 xargs -r0 ls -b1Ud --
52 else
53 cat
54 fi
55 exit
56 fi
57
58 #flag trailing / as an error
59 if printf "%s\n" "$@" | tr -s '/' | grep -q './$'; then
60 echo "Error: trailing '/' in a parameter is not allowed" >&2
61 exit 1
62 fi
63
64 (
65 #get all dirs
66 find "$@" -type d ! -name "*$LF*" -printf "$FPF\n" |
67 sort -u #merge dirs (indirectly) specified multiple times
68
69 #get all dirs containing files.
70 #Note / not included for absolute dirs, but we assume / has files
71 find "$@" ! -type d ! -name "*$LF*" -printf "%h\n" |
72 uniq | #quick merge of dir names for each file
73 sed -n ':s; p;p; s#/\{0,\}[^/]\{1,\}$##; /./b s' #separate dir nodes
74
75 #Ensure we exclude parents to specified absolute dirs
76 find "$@" -maxdepth 0 ! -name "*$LF*" -printf "%h\n%h\n" |
77 sed '/^\//!d' | #only process absolute dirs
78 sed -n ':s; p;p; s#/\{0,\}[^/]\{1,\}$##; /./b s' #separate dir nodes
79 ) |
80 #get dirs only containing dirs, or nothing at all
81 sort | uniq -u |
82
83 #reduce to parent (prefixes)
84 sed 'p; :s $!N; s/^\(.*\)\n\1\/.*/\1/; t s; D' |
85
86 #make further processing immune to blanks
87 tr '\n' '\0' |
88
89 if [ ! -p /proc/self/fd/1 ]; then
90 xargs -r0 ls -b1Ud --
91 else
92 cat
93 fi