Just in case it's not perfectly clear, in the command above you're piping the stdout of
find into the stdin of
grep. So you have grep searching for the literal string "fuser" in the
text output of find; you're searching the file
names, not the contents of the files themselves.
If you tried piping it directly into fuser you'll simply get an error, because as pwc101 points out, fuser doesn't read from stdin.
What you really want to do is execute the fuser command once for each name found. As demonstrated, find's -exec option or xargs are common ways to do it.
It's also possible to use a bash loop like this:
Code:
while IFS="" read -r -d "" dir; do
fuser "$dir"
done <( find . -type d -print0 )
http://mywiki.wooledge.org/BashFAQ/001
Or if you're using bash v4+, you can try this:
Code:
shopt -s globstar
for dir in . **/ ; do # Use . to include the top level too.
fuser "$dir"
done
** is the new globstar
globbing pattern, which matches recursively. You have to enable it first. Adding a
/ after it makes it match only directories. You can tack on additional globs onto it to search for files inside a directory tree (e.g. **/*.txt to grab all text files). You can also enable
shopt -s dotglob to match hidden files.
find may sometimes still be more efficient however.