Executing a command line in a directory and its subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing a command line in a directory and its subdirectories
# 1  
Old 12-07-2013
Executing a command line in a directory and its subdirectories

I'm finally about to make the jump from PHP's mysql driver to the newer mysqli one using the mysqli converter tool.

The tool is called by this command line:
Code:
php /usr/share/nginx/html/rather/converter/cli.php -d [a dir] -p ".php,.shtml,.inc" -u -b -v -w  >> /tmp/convert.log

e.g. at the web root:
Code:
php /usr/share/nginx/html/rather/converter/cli.php -d /usr/share/nginx/html -p ".php,.shtml,.inc" -u -b -v -w >> /tmp/convert.log

It's a fast tool and I'm trying to minimize downtime and errors I might make by missing a subdir level.

How would I get a list, starting at /usr/share/nginx/html and drilling down, then feed it to that command line?

Thanks for any pointers.

Last edited by Franklin52; 12-08-2013 at 06:55 AM.. Reason: Please use code tags
# 2  
Old 12-07-2013
Quote:
Originally Posted by dheian
How would I get a list, starting at /usr/share/nginx/html and drilling down, then feed it to that command line?
I suggest to consult the man page for find. Switches you probably will find useful include:
  • -type limits the resulting list to file system items of the specified type: -type -f finds only files, -type -d only directories, etc.
  • -name only items matching the given name pattern are found. -name "*php" will find only php-files.
  • -exec allows to execute an arbitrary command on every item found.

You might find this little introduction to find useful.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 12-07-2013
-execdir may also be of interest.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command to search files in a directory excluding subdirectories

Hi Forum, I am using the below command to find files older than x days in a directory excluding subdirectories. From the previous forums I got to know that prune command helps us not to descend in subdirectories. Though I am using it here, not getting the desired result. cd $dir... (8 Replies)
Discussion started by: jhilmil
8 Replies

2. Shell Programming and Scripting

Copying subdirectories of a directory to some other directory and renaming them

Hi, I am a newbie in shell scripting. I have to copy a particular sub-directory (data) from a large no. of directories (all in the same folder) and paste them to another directory ( /home/hubble/data ) and then rename all the subdirectories (data) as the name of its parent directory. please... (8 Replies)
Discussion started by: sholay
8 Replies

3. Shell Programming and Scripting

executing/including command in mailx subject line

Hi, Is it possible for me to include the results from a command in the subject line? What I am looking to do is get the file count and include it into the subject line as well as the list of files in the body. Example Subject line: Currently 25 files in directory My Code: #!/bin/ksh cd... (2 Replies)
Discussion started by: ozifer
2 Replies

4. Shell Programming and Scripting

executing command from subdirectories

Hello, I've been trying to run 'ls -1R | wc -l' inside of sub directories to in order to determine how big each folder is. find . -maxdepth 1 -type d | while read folder do cd "$folder" && echo "$folder has $(ls -1R | wc -l) files" && cd .. done or for... (3 Replies)
Discussion started by: NoobProgrammer
3 Replies

5. Shell Programming and Scripting

CD (change directory) - Not advisable for executing a command

Hi, This is a quick one. I have got a review comment in one of the scripts that i wrote: "In UNIX script it not advisable to use cd to a directory and then run command." Is this true? I was trying to cd to log directory and use some cat or head or ls command. Many Thanks, Sam (2 Replies)
Discussion started by: samplify
2 Replies

6. UNIX for Dummies Questions & Answers

How to remove directory with subdirectories and files?

I'm trying to remove several directories which contains sun-dirs and files inside. I used the command rm -r <dirname> But, it always ask "examine file in directory <dirname> yes/no?" line by line. So, i need to write "y" for every line. How can i skip this step and remove all directories with... (9 Replies)
Discussion started by: ppa108
9 Replies

7. Shell Programming and Scripting

How Can I Make Subdirectories In A Directory?

I cant remember how, i use to know but its been like 2 years since ive used shell can anyone help me? (7 Replies)
Discussion started by: kprescod4158
7 Replies

8. Shell Programming and Scripting

Monitoring a directory for new files with .xx and executing command if found

Hi Guys. I am a complete shell scripting newbie with some syntax and commands understanding. I'm more of a win admin. With that said: I need to write a shell script to monitor a directory '/Mon_Dir' for new occurrences of files with .xx extension. Once a new file is detected in the directory, a... (4 Replies)
Discussion started by: krkan
4 Replies

9. UNIX for Dummies Questions & Answers

makefiles in a directory and subdirectories

I need to develop a makefile that spans across directories. For example, let's say i have an upper level directory (main) and about 2 subdirectories. I want my .cpp files and .o files to be in one subdirectory. I want my .a files to be in the other subdirectory. The .a files are made up of the... (0 Replies)
Discussion started by: benjie_asu
0 Replies

10. Programming

Executing command line options

Can someone please tell me how to modify/add to this code so that it recognizes UNIX command options (all beginning with "-") and executes the command with options? #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv) { int i; system("stty -echo"); ... (8 Replies)
Discussion started by: Safia
8 Replies
Login or Register to Ask a Question