LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   is there a way to traverse a directory structure & execute a command (https://www.linuxquestions.org/questions/linux-newbie-8/is-there-a-way-to-traverse-a-directory-structure-and-execute-a-command-29777/)

hemlock 09-06-2002 07:34 PM

is there a way to traverse a directory structure & execute a command
 
Is there a way to traverse a directory structure & execute a command for each directory it enters? Or maybe every file in each directory? The command needs to be a bash script I'd write.

What I'm trying to do is walk (a part of) a directory structure of a filesystem from system A mounted on system B & gzip the files onto another HD on system B, but sleeping between each file so it doesn't load down the network access to system A's files. Nice'ing the job running on system B wouldn't work as there's really nothing running on B most of the time. In fact there's nothing much running on either systems, just serving files.
Perhaps I misunderstand nice (& how servers work) but as I read it, it just lowers priority of that job, and Windows machines accessing the files on A would be unknown/unseen by B as a process that it should be lower than.

I know I can write a bash script that will traverse the directory structure, but I figure someone's already done it & probably better than I could, so why reinvent the wheel.

neo77777 09-07-2002 12:22 AM

Look up http://www.cpan.org , espacially http://search.cpan.org/author/JHI/pe...b/File/Find.pm
also take a look at find (man find), definetely you need find (it has an ability to execute commands on its results), be aware this is a very time consuming task to traverse a directory tree, so you'll need more intellegent AND rules for find, dig it through.


All times are GMT -5. The time now is 12:11 PM.