I have a range of .html files all containing spaces in between.

What I need is to locate the file using find in conjunction with grep, and if a match is found, basically I just want xargs to open it in view mode using less. Nothing fancy.

This is what I tried

pietro@scum:~/Downloads$ find |grep 'Register\sfor\srehousing.html' |xargs -trE  less
echo ./Register for rehousing.html 
./Register for rehousing.html

pietro@scum:~/Downloads$ find |grep 'Register\sfor\srehousing.html' |xargs -0 less
./Register for rehousing.html
: No such file or directory

I have gone through the xargs man but I just can't figure out why xargs doesn't pickup the filename + PATH to file and execute the less command.

The file does exist and here is how it looks

pietro@scum:~/Downloads$ ls -l |grep 'Register\sfor\srehousing.html' 
-rw-rw-r-- 1 pietro pietro    764611 Mar 14 14:44 Register for rehousing.html
  • 1
    Why don't you use find -name instead of find | grep ?
    – pLumo
    Commented Apr 8, 2019 at 14:38
  • @RoVo Simply I do not know how to use find -name when file contains spaces in between.
    – mailman
    Commented Apr 8, 2019 at 14:40
  • 2
    and why don't you use less "Register for rehousing.html" if you know the file exists?
    – pLumo
    Commented Apr 8, 2019 at 14:41
  • In reality this will be one of the few functions I am adding to an interactive script I am creating. I just needed to figure out how it would work before embedding it to the script.
    – mailman
    Commented Apr 9, 2019 at 8:57

2 Answers 2


try with:

xargs -d '\n' less

the input to xargs, in your case are not null character terminated

  • Wow that worked. Thank you so much.
    – mailman
    Commented Apr 8, 2019 at 14:35

No need for a pipe, use find only with -name instead of grep and -exec instead of xargs:

find . -name 'Register for rehousing.html' -exec less {} \;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .