I'm trying to list all directories of a web server that are blocked by Apache via a .htaccess
(containing deny from all
).
I've managed to get the list of blocking .htaccess
but when I try to extract the directory path using dirname
I have some errors:
List of
.htaccess
files:find . -type f -name ".htaccess" ./.htaccess ./config/.htaccess ./files/.htaccess ./plugins/webservices/.htaccess ./plugins/webservices/scripts/.htaccess ./install/mysql/.htaccess ./scripts/.htaccess ./locales/.htaccess
List of blocking
.htaccess
files:find . -type f -name ".htaccess" -exec sh -c "grep -Eli '^deny from all$' '{}'" \; ./config/.htaccess ./files/.htaccess ./plugins/webservices/scripts/.htaccess ./install/mysql/.htaccess ./scripts/.htaccess ./locales/.htaccess
Error come the errors. Same list as in 2. but using
xargs
anddirname
to get the containing directory:find . -type f -name ".htaccess" -exec sh -c "grep -Eli '^deny from all$' '{}' | xargs dirname" \; dirname: missing operand Try dirname --help' for more information ./config ./files dirname: missing operand Try dirname --help' for more information ./plugins/webservices/scripts ./install/mysql ./scripts ./locales
Debug attempt of list 3: we can see 2 blank lines where the 2 errors were:
find . -type f -name ".htaccess" -exec sh -c "grep -Eli '^deny from all$' '{}' | xargs echo" \; ./config/.htaccess ./files/.htaccess ./plugins/webservices/scripts/.htaccess ./install/mysql/.htaccess ./scripts/.htaccess ./locales/.htaccess
Theses 2 blank lines obviously matches the 2 .htaccess
files that were ignore because they don't contains deny from all
. I don't understand why I get these in lists 3. and 4. but not in 2.
{}
within the shell command is a major security risk. If you ever need that effect (which you don't here, anyway), use this pattern instead. (Set the found filename as a shell positional parameter and refer to it as such.) – Wildcard May 13 '16 at 22:57