[SOLVED] Script to open all subdirectories of a single directory and then run a command (help)
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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Script to open all subdirectories of a single directory and then run a command (help)
Just as the title says, I am trying to write a very simple script that will go to every subdirectory of a single directory and run a command (lets call it make_ndx).
I know I can write this the long way with in a text document with something like:
cd /"the directory"/"the 1st subdirectory"
cd "the 2nd subdirectory"
Alternatively, I also tried:
for i in 'find /path/somemorepath -type d -mindepth 1'; do cd $i; make_ndx -f *.gro; done
which returns me with the error cd: find: no such file or directory.
But if I run the find command by itself to test if I am calling the right directories, it gives me the exactly the output I am looking for. Any ideas? Should I just write the find results to a file and loop through the contents of the file (which seems a little bit like overkill) or am I just making a simple typographical mistake and I am just not seeing it?
As a follow-up, not that I have this working, I want to look into just one subdirectory whose name is repeated within the set of subdirectories...ok this is kind of convoluted so maybe I'll put it this way:
I am interested in looking at only a set of subdirectories with the same name (i.e. I have a set of directories that have another set of directories in them with the same name. Like a set of directories that are months, and then inside of them there are directories called days and I only want to look at day 30 of every month)
I try a simple script:
for i in `find /year/ -type d -mindepth 1`; do; if [ $i = "30"]; then; command_of_some_sort; fi; done