1

I am able to open on file at a time using cat -- -file00 but I want to open multiple files at once. Tried using find, can't figure it out.

find ./ -name '*.txt' exec cat {} \;

find ./ -name '*.txt' exec grep 'inhere' {} \;

None of this working. I have multiple files in the dir in this form: -file00 -file01 -file03 -file04 -file05 -file06

3

-name '*.txt' is to match on files whose name ends in .txt. That won't match yours. Use a pattern that matches your files:

find . -name '-file*' -exec cat {} +

Or

cat ./-file*

if they are all in the current directory (would also have the benefit of concatenating those files ordered alphabetically contrary to find which list files in random order).

Note that the -- is not needed above as the arguments passed to cat all start with ./, not -.

For a more specific match (only -file followed by exactly two decimal digits): ./-file[0-9][0-9]

0

You can also use xargs if you'd like.

find ./ -name '-file0*' | xargs cat 

As noted above none of your files actually have .txt as an extension. If they did you could replace -file0* with *.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.