“find” output relative to directory

find

I'd like to use find to list all files and directories recursively in a given root for a cpio operation. However, I don't want the root directory itself to appear in the paths. For example, I currently get:

$ find diskimg
diskimg
diskimg/file1
diskimg/dir1
diskimg/dir1/file2

But, I'd like to get

file1
dir1
dir1/file2

(note the root is also not in my desired output, but that's easy to get rid of with tail).

I'm on OS X, and I'd prefer not to install any extra tools (e.g. GNU find) if possible, since I'd like to share the script I'm writing with other OS X users.

I'm aware this can be done with cut to cut the root listing off, but that seems like a suboptimal solution. Is there a better solution available?

Best Answer

If what you are trying to do is not too complex, you could accomplish this with sed:

find diskimg | sed -n 's|^diskimg/||p'

Or cut:

find diskimg | cut -sd / -f 2-