Skip to content
Advertisement

Inserting text in a ‘find’ command search

I have a find string that finds all the instances of a particular filename in a path, like so:

find /opt/logs* -type f -name "deploy.log" -exec ls {} ;

I need to return the result with ‘FINENAME=’ prepended on each line. Having a hard time figuring the best way.

Advertisement

Answer

find /opt/logs* -type f -name deploy.log | sed 's/^/FILENAME=/'

Note that if you have a directory named /opt/logs (and you’re not trying to look in /opt/logs-foo/ and /opt/logs-date, or the like) you can drop the * and write find /opt/logs -type ...

Advertisement