As suggested by derobert, your best bet is to use
find. However, you can in fact use the result in a pipeline with other commands.
Find supports the
-print0 (should appear last) option which tells it to delimit results with a NULL character, which character isn't allowed within a file name and guarantees there won't be a collision. Other commands can be instructed to use the NULL as their input delimiter.
The most important of which is
xargs, which runs the command you specify and passes to it the list of files as command line arguments. You want to run
xargs -0 in conjunction with find's
-print0 For example:
find -type f ! \( -name \*.pdf -o -name \*.txt \) -print0 | xargs -0 ls -ld
This safely prints a long directory listing of all the pdf and txt files, including those with spaces or unprintable characters in the name.
You can also use it with
tar as follows:
tar -zcf myarchive.tar.gz --null --files-from <( find -type f ! -name \*.tar.gz -print0 )
This builds a tar.gz file of all the files whose names don't end in .tar.gz
rsync also accepts null-delimited files with the
-0 parameter, as do several others. But
xargs is the glue you'll ususally use for this type of purpose. Either that or