find + printf help

Hi, I have a scripting assignment for an intro to linux class and I'm really confused about how to do something seemingly simple.

I am supposed to Print the name of each file in the /data/dir16/subdir1 directory in the following format: "My name is: bin"

The desired output example looks like:
My name is: /data/dir16/dir1/testfile1
My name is: /data/dir16/dir1/testfile2
so on...

So first question is, am I on the right track in thinking I am supposed to use the find and printf combination?

Right now, all I've tried is various combinations of find /data/dir16/dir1 printf "My name is:" which just produces 13 instances of "My name is:".

How do I append the filenames to the end of the "My name is" string?

If you do a man find, you'll notice that in order to print you need to use %p and terminate with a newline. printf is a GNU find only extension. You can accomplish the same thing with -exec , which will work with any find command. Hold on .. this should be in the homework forum :slight_smile:

1 Like