1

I have the following find command:

find /home/  -type d -name "something"

what I want to achieve is to know which directory/file is checked by the find command no matter the fact that it does or does not match the name I have set.

Basically I want to see every action that the find command will perform once I launch the above piece of code.

Thank you!

3 Answers3

3

With an

lsof -p `pidof find`

you can see, where is your find command currently.

With a

strace -p `pidof find`

you can check, what it is doing currently.

None of them have really beautiful output - they are debug tools, but the little bit of learning their output is also really useful.

peterh
  • 4,914
  • 13
  • 29
  • 44
  • 1
    Thank you! I actually found similar solution myself searching over the web. It seems that the find command does not actually have a log option for example or an option where similar output to the strace command can be provided. Thank you once again and have a great day! – Simeon Mitev Feb 19 '14 at 14:00
2

The man file for find has debug options

you probably want find -D search -type d -name "something" 2>&1

it doesn't seem to be in the man file but find -D help

prints

search Navigate the directory tree verbosely

0

Although the above two commands do actually answer the question I would like to present a less verbose output which satisfies the part:

to know which directory/file is checked by the find command no matter the fact that it does or does not match the name I have set.

find /home/ -print -type d -name "something"

Using the -print expression.

As stated in the manual:

  • If no expression is given, the expression -print is used by default as if it were put at the end of the command
    • find /home/ -type d -name "something"
      • as if it were --> find /home/ -type d -name "something" -print

but if you place the print expression at the beginning as follows

  • find /home/ -print -type d -name "something"
    • It will print out every file that is being checked
      • of course the matched file will also be printed as it forms part of the checked files, but you do not have a way of knowing which one it was

If you place the print expression at the beginning and end:

  • find /home/ -print-type d -name "something"-print
    • It will print out every file that is being checked
    • It will print out every matched file aswell

So now the ones that matched will appear twice. Although a bit difficult to see if there are a lot of files.

So using the expression printf instead of print you can use ANSI excape color codes within the format of the printf command, but as explainted in this answer the -printf flag of find is different from the usual built-in from bash and "the color code sequence and the %p needs to be in the same argument". This can lead to the following expression:

find /home/ -print -type d -name "something" -printf '\033[;34m%p\033[0m\n'

This will print the matches out in blue

more info available in the find man docs