how to output file names surrounded with quotes in SINGLE line?

You can use the GNU ls option --quoting-style to easily get what you are after. From the manual page:

--quoting-style=WORD

use quoting style WORD for entry names: literal, locale, shell, shell-always, shell-escape, shell-escape-always, c, escape

For example, using the command ls --quoting-style=shell-escape-always, your output becomes:

'filename1' 'filename2' 'file name with spaces' 'foldername' 'folder name with spaces'

Using --quoting-style=c, you can reproduce your desired example exactly. However, if the output is going to be used by a shell script, you should use one of the forms that correctly escapes special characters, such as shell-escape-always.


You could also simply use find "-printf", as in :

find . -printf "\"%p\" " | xargs your_command

where:

%p = file-path

This will surround every found file-path with quotes and separate each item with a space. This avoids the use of multiple commands.


Try this.

find . -exec echo -n '"{}" ' \;

this should work

find $PWD | sed 's/^/"/g' | sed 's/$/"/g' | tr '\n' ' '

EDIT:

This should be more efficient than the previous one.

find $PWD | sed -e 's/^/"/g' -e 's/$/"/g' | tr '\n' ' '

@Timofey's solution would work with a tr in the end, and should be the most efficient.

find $PWD -exec echo -n '"{}" ' \; | tr '\n' ' '