Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I pipe files from find to less?

Tags:

shell

pipe

I have a bunch of files, and need to examine all which are non-empty. I can find these files e.g. by running

find *e* -maxdepth 1 -size +0 -print

But if I add | less to the above, I only get to see the list of files, not the files themselves.

If I manually give this filelist as an argument to less (less file1.e file2.e file3.e etc.) I get what I want, but this kind of cumbersome. Is there any way I can pipe the output of find to less directly?

like image 521
Nagel Avatar asked Sep 16 '25 01:09

Nagel


1 Answers

To run less on each file in turn:

find *e* -type f -maxdepth 1 -size +0 -exec less {} \;

or:

find *e* -type f -maxdepth 1 -size +0 | xargs less

to run less on the entire list (assuming the number of files is not huge - xargs limits max no of arguments to 5000 typically).

Note that addition of -type f so that you don't return directories from find.

like image 149
Paul R Avatar answered Sep 17 '25 18:09

Paul R