LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-06-2007, 09:56 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Rep: Reputation: 52
struggling with a Bash script


I am trying to do a recursive "tree" of only some directories contained in a main directory.
I want to print the directory name, subdirectory name and filenames of files ending with .htm .html .php

Nothing I do work, can anyone show me the correct syntax?

Thank you for your help.
 
Old 11-06-2007, 10:25 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
This may result in a very long statement, but one way can be
Code:
find . \( -wholename ./dir_one -o -wholename ./dir_two \) -prune -o -name "*.php" -print -o -name "*.html" -print -o -name "*.htm" -print
this uses the -prune action of find, to exclude from the search the directories enlighted in blue. If you want to add more directories to exclude, simply add them inside the parentheses with the same construct, as in
Code:
find . \( -wholename ./dir_one -o -wholename ./dir_two -o -wholename ./dir_three \) -prune -o -name "*.php" -print -o -name "*.html" -print -o -name "*.htm" -print
Please note that if the starting point is different from the current directory ".", you have to specify the whole name of the directories to exclude accordingly, for example
Code:
find test_dir -wholename test_dir/dir_one -prune -o -name "*.php" -print -o -name "*.html" -print -o -name "*.htm" -print
 
Old 11-07-2007, 01:31 AM   #3
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
Thank you very much, it worked first time.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 07:01 PM
[bash] having trouble debugging this bash script. jons Programming 4 02-08-2007 06:51 AM
Bash script hangs upon starting another script in the background masea2 Linux - Software 4 11-13-2006 05:18 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration