Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I use the 'find' command alot, but I always get stuck on the fact that I can't get the pipe operator to work in the -exec option. Here is what I want to do
find -name -exec echo {} | grep -o whatever \;
This isn't actually what I am doing, but an example. So basically whenever I do this everything after the pipe just gets ignored. I would like each found file to be properly piped into grep -o.
\| and '|' and "|" don't work. Is there an escape sequence to get the pipe to work properly there?
I use the 'find' command alot, but I always get stuck on the fact that I can't get the pipe operator to work in the -exec option. Here is what I want to do
find -name -exec echo {} | grep -o whatever \;
This isn't actually what I am doing, but an example. So basically whenever I do this everything after the pipe just gets ignored. I would like each found file to be properly piped into grep -o.
\| and '|' and "|" don't work. Is there an escape sequence to get the pipe to work properly there?
i normally use a -print combined with xargs in this case.
something like this...
lets say I want to change the extensions on a group of files, say a bunch of jpegs from jpg to jpeg. So I cd to the directory and then I would like to do:
that of course doesn't work because stuff after the | gets ignored. Using xargs seems to just give me everything at once instead of executing on each found item.
-type d won't grab too many jpeg files. And if you 'cd' to the directory, then something like 'for f in *jpg; do mv $f ${f%%.*}.jpeg; done' might suffice. Which has nothing to do with find and pipes but is a way to handle your example. How about citing an actual case? You don't have to use xargs - you can just do a for loop with find or whatever you want. There's a million ways to do stuff, so it's hard to guess which corners of your cases you don't like.
A for loop could work. This is what I am doing. I am trying to change extensions of files, to be uniform. The type d was a typo on my part, I always run the find before I actually try to run the find -exec, I meant to put type f. I will try the for loop, I just like the find, since it is more flexible. This is mainly just a pet peeve since I use find all the time, yet I can never get the pipes to work. I have written scripts to get around it before, but I just thought someone might know a better way.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.