Hi friends! 🤓 I am on a gnulinux and trying to list all files in the active directory and it’s subdirectories. I then want to pipe the output to “cat”. I want to pipe the output from cat into grep.
Please help! 😅
Use
find
instead.Seconded, but I always have to look up the syntax. --type=file --name=“string”?
Thank you! 🤩
Bro you can just run
find
thanks dude
To answer your og question since it is a valuable tool to know about, xargs.
ls | xargs cat | grep print
Should do what you want. Unless your file names have spaces, then you should probably not use this.
find -print0 | xargs -0 can handle spaces
Edit and you probably want xargs --exec instead of piping after
thank you
It’s valuable to learn how to do an inline loop
ls | while read A; do cat $A | grep print; done
This will read each line of ls into variable A, then it’ll get and grep each one.
thank you
I think you can just do
grep print **/*
.ty
ripgrep
does exactly what you wantdeleted by creator
ty
grep -r print .
I.e. Grep on
print
recursively from.
(current directory)Or for more advance search
find . -name "*.sh" -exec grep -H print {} \;
I.e find all files with sh extension and run grep on it (
{}
become the filename).-H
to include filename in output.this is great ty!