Find twice:
echo 'directories'
find . -name 'example.com*' -type d
echo 'non-directories'
find . -name 'example.com*' ! -type d
Note too the quoting of the pattern used for the name test. Without quotes, the shell would try to match the string against names in the current directory before calling find
. If the failglob
shell option was set in the bash
shell, or if the NOMATCH
shell option in zsh
was not unset, an unquoted globbing pattern that didn't match anything would generate an error from the shell, and find
would not be called at all.
Alternatively, just output a slash at the end of the directory pathnames (this is how ls -p
would represent directories):
find . -name 'example.com*' \( -type d -exec printf '%s/\n' {} \; -o -print \)
The above find
command first tests that the name is correct. If it is, and it's a directory, it calls printf
to output the pathname of the directory with a slash at the end. If it's not a directory -print
is used to just output the pathname as is.
With GNU find
, the -exec printf '%s/\n' {} \;
bit could be replaced by -printf '%p/\n'
.
With standard find
, you could also use -exec printf '%s/\n' {} +
to call the external printf
utility as few times as possible, but this would mean that directories likely would be outputted last, or at least in batches.
Another alternative is to actually use ls -p
to tell directories apart from other file types. Using ls -p
, a directory would be listed with a trailing /
character, just as above.
find . -name 'example.com*' -exec ls -f -d -p {} +
I'm using -f
here to avoid letting ls
sort the output, and -d
to avoid listing the contents of directories.
You could use ls -F
instead of ls -p
to also put other marks on file types other than directories. For example, executables would be suffixed by *
and symbolic links would be suffixed by @
.
Both -p
and -F
(and -f
and -d
) are standard options to the ls
utility.
./archive/example.com
and./live/example.com
is a directory -although you could say that./archive
and./live
are. Do you want to amend your question?