is there a way to make a generic command run recursivley?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
is there a way to make a generic command run recursivley?
This isn't too important, it's just a thought I had today. I was messing with some software where every file had an extra suffix I needed removed. I didn't know of any program that would automatically truncate a filename so I wrote a basic script to do it. The only problem is my script works on all files in a directory, but not on all directories in my software.
I'm sure I could get around that easily enough, but it left me thinking that it would be convenient if there was a way to run the script recursively without having to modify the script. It seems to me that the need would come up often enough that a method should already exist, but I don’t know what it is. So for the sake of my own curiosity, what would be the standard method for making a generic command run recursively on all subfolders?
why not show us the script you're using, and someone might be more accurately able to suggest a modification on what you're currently doing, to get the results you seek? It sounds like, if you don't want to modify the script, you'd need a for or while loop..
Sasha
Last edited by GrapefruiTgirl; 11-17-2009 at 11:26 AM.
There's no generic way to do recursions, it wouldn't be too complex to do so with bash though, but for that we would first need to know a few details on how exactly is the recursion to be implemented.
However, it's really not the simplest way around this case, you only need find to do this, for example:
Code:
find /path/to -iname foo_\*.mp3 | while read file; do mv "$file" "${file/foo_/}"; done
Thank you for the prompt answer. It looks like find was the command I was looking for. I'm trying to learn all the little programs that come packaged with Linux that are useful for basic scripting, and I figure this one is probably pretty important.
Incidentally I changed my script and it worked correctly. Of course now that I fixed that little problem I have a new compilation issue. It seems every time I stat complaining about "rpm hell" I run into a program I have to install without a RPM and get a new appreciation for them. One day I may be so lucky as to install a package with fancy tools like yum. Yep that would be nice...
It looks like find was the command I was looking for.
Hmmm. You need to know what is available (and is are a LOT) and how to combine linux / unix simple commands (That "do simple things, but do them well") into scripts with truly awesome usefulness. It takes time, but I expect you'll get there. One of my personal favourites is here (Read on down in the link for a much improved script by Disillusionist)
yum ? RPM ? Been there, tried that
apt-get (on all debian-based distros) = Bliss [tredegar ducks incoming missiles].
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.