Find *.tar files under all subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find *.tar files under all subdirectories
# 8  
Old 12-03-2010
Thanks Radoulov,

It works fine.. If i give only the directory.. for examaple here "abcd". But my situation is like "/abc/defh/abcd" means i just wanted to eliminate this complete path not all the abcd directory.

I tried giving the complete path but its not excluding ""/abc/defh/abcd" directory.

Code:
find  /home -type d \( -name /abc/defh/abcd -o -name bbbb -o -name cccc \) -prune -o -name '*.tar' -print

I tried with single & double qoutes as well its not working.
Any option i can exclude entire path ?

Last edited by radoulov; 12-03-2010 at 03:46 PM.. Reason: Code tags!
# 9  
Old 12-03-2010
I don't understand what you mean,
could you give an example of the desired output?
# 10  
Old 12-04-2010
Hi,

It work fine.. But it's not excluding when i use the entire path for example(/home/cccc) and it works when i give only the directory as cccc. I just wanted to exclude the entire directory path and I need xxxx to be searched when it is not in(/home/cccc). Below is code the used which was not excluding the /home/cccc.

find /home -type d \( -name /home/cccc -o -name -o -name aaaa \) -prune -o -name '*.tar' -print

But it still searching under(/home/cccc) where it should exclude but aaaa got completely excluded.

Thanks in advance!
Vasanth


---------- Post updated at 10:30 PM ---------- Previous update was at 10:03 PM ----------

Hi,

It work fine.. But it's not excluding when i use the entire path for example(/home/cccc) and it works when i give only the directory as cccc. I just wanted to exclude the entire directory path and I need xxxx to be searched when it is not in(/home/cccc). Below is code the used which was not excluding the /home/cccc.

find /home -type d \( -name /home/cccc -o -name -o -name aaaa \) -prune -o -name '*.tar' -print

But it still searching under(/home/cccc) where it should exclude but aaaa got completely excluded. Can anyone help with the above situation ???

Thanks in advance!
Vasanth


---------- Post updated at 11:50 PM ---------- Previous update was at 10:30 PM ----------

Plz see the above conversation.

Thanks,
Vasanth.
# 11  
Old 12-04-2010
I still don't understand. Consider the following example:

Code:
zsh-4.3.10[sysadmin]% find /home/sysadmin/t/abcd -name '*.tar'
/home/sysadmin/t/abcd/aaaa/pippo.tar
/home/sysadmin/t/abcd/bbbb/pippo.tar
/home/sysadmin/t/abcd/cccc/pippo.tar
/home/sysadmin/t/abcd/dddd/pippo.tar
/home/sysadmin/t/abcd/pippo.tar

If have .tar files in:

Code:
/home/sysadmin/t/abcd
/home/sysadmin/t/abcd/aaaa
/home/sysadmin/t/abcd/bbbb
/home/sysadmin/t/abcd/cccc
/home/sysadmin/t/abcd/dddd

The following command skips any aaaa, bbbb and cccc directory under /home/sysadmin/t/abcd/:

Code:
zsh-4.3.10[sysadmin]% find  /home/sysadmin/t/abcd -type d \( -name aaaa -o -name bbbb -o -name cccc \)  -prune -o -name '*.tar' -print
/home/sysadmin/t/abcd/dddd/pippo.tar
/home/sysadmin/t/abcd/pippo.tar

I suppose that skipping, for example, /home/sysadmin/t/abcd/dddd/aaaa could be an issue for you, but your problem seems to be different, could you please clarify providing an example (files that should/shouldn't be included in the output)?
# 12  
Old 12-04-2010
Hi Radoulov,
Exactly what you guessed below is right!
Thanks for your help Radoulov!

Quote:
I suppose that skipping, for example, /home/sysadmin/t/abcd/dddd/aaaa could be an issue for you,
Quote:
Later I found myself a simple method and got the result as per my requirement.
I used 2 separate find command for source and copybook :
Code:
/home/apps/**/source

where it always searches in the test source/copybook.Sorry for the unwanted thought of mine Smilie
Anyways below is my requirement. Hope you will understand. Thanks again.

My requirement :
my test environment path example: /home/apps/xx/source where xx is the test region.
my production path example : /home/apps/source

Now i need to find like :
Code:
 find /home/apps -name "1234"

The above will search for the 1234 under /home/apps.. here i need to skip the /home/apps/source which was production and i need to search on all test region. If i skip "source" directory in the below code it will skip both production and test regions source directory well where my requirement is it should not skip the test environment.
Code:
find  /home -type d \( -name /home/apps -o -name  -o -name xxxx \)  -prune -o -name '*.tar' -print

So to skip the production directory I used the complete path /home/apps which was ignored in my code. Hope you understand my situation now.

-Vasanth
# 13  
Old 12-04-2010
You could try something like this:
Code:
perl -MFile::Find -le'
  BEGIN {
    $skip = {
      "/home/apps/source" => 1,
      };
    $pat = qr/\.tar$/;  
    }
  find { 
    wanted => sub {
      $File::Find::prune = 1 and return 
        if  exists $skip->{$File::Find::dir};   
      /$pat/o or return;
      print $File::Find::name;
      }
    }, shift    
  ' /home/apps

---------- Post updated at 08:20 PM ---------- Previous update was at 07:51 PM ----------

The code is easily extensible, you could skip more directories just by adding them to the hash skip in the BEGIN block:


Code:
$skip = {
      "/home/apps/source" => 1,
      "/dir/2"            => 1,
      "/dir/3/1"          => 1,
      };


Last edited by radoulov; 12-04-2010 at 02:59 PM..
This User Gave Thanks to radoulov For This Post:
# 14  
Old 12-06-2010
Hi, I think I have a similar problem.

Code:
find /storage/cas/extracts/ -name "usage_1_*" -type f -mtime +7

I want to limit the search to /storage/cas/extracts only.

Thanks in advance!

Last edited by radoulov; 12-07-2010 at 06:42 AM.. Reason: Code tags, please!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search subdirectories and find and print total files

Hi All, I have a folder name lets say path/to/folder/CUSTOMER and under this i have several folders and each of these subfolder have serveral subfolders and so on and at some point i will have a folder name called "FTP_FILES" . I need to search for these folders named "FTP_FILES and then... (10 Replies)
Discussion started by: Kevin Tivoli
10 Replies

2. Shell Programming and Scripting

Find files only in current directory...not subdirectories

Hi, I have to find files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..I tried to use maxdepth..but it is not working in AIX. (2 Replies)
Discussion started by: vsachan
2 Replies

3. Shell Programming and Scripting

how can i find number of lines in files & subdirectories

how can i find number of lines in files & subdirectories ? (3 Replies)
Discussion started by: pcbuilder
3 Replies

4. Shell Programming and Scripting

How to find files only inside the subdirectories only?

Hi I have a directory with two subdirectories and also have a code like below to search files modified in last 2 minutes. # ls hello080909.txt inbox outbox # find . -type f -mmin +2 ./inbox/hello2080909.txt ./outbox/hi0080909.txt ./hello080909.txt The above code just searches and... (3 Replies)
Discussion started by: Tuxidow
3 Replies

5. Shell Programming and Scripting

to parse a directory and its subdirectories and find owner name of files

hi all, i need to capture all the files in a directory and its subdirectories that have owner name different than the root owner. for one file it is " stat -c %U filename " but i need to search for each and every file and record it. thanks in advance (14 Replies)
Discussion started by: vyasa
14 Replies

6. UNIX for Dummies Questions & Answers

Find Files in a Directory Excluding Subdirectories

Hi, I have a filename Location.txt in a directory /abc. Similar name file is present in its subdirectory /abc/xyz. I want to find the file which is present only in /abc and not in /abc/xyz. Please any1 of u can provide a quick suggestion. Its very urgent. Thanks, Amol (2 Replies)
Discussion started by: Amol_Dicholkar
2 Replies

7. Shell Programming and Scripting

Find files ignoring subdirectories

Hi guys, I am searching some files not equal to the pattern with this command find ! -name "PATTERN" -type f but my problem is the find command because he also search inside subdirectories and that's the thing i don't want that. Is there any comand to ignore the directories... (4 Replies)
Discussion started by: osramos
4 Replies

8. Shell Programming and Scripting

Shell:Find a word in files in a directory and subdirectories

I'm looking to write a ksh code with will be alble to find a word like 'toto' in all files going from my current directory. eg. /doc ----------->have: text.c which "toto" /doc/usr-------->have: build.pc, help.java which "toto" /doc/usr/cach -->have: test.sh which "toto" /doc/build... (4 Replies)
Discussion started by: yeclota
4 Replies

9. UNIX for Dummies Questions & Answers

Find all files created by a specified user in a directory and its subdirectories

Is there a command or shell script which can be used for Finding all files created by a specified userid in a directory and its subdirectories. Say, I want to find all such files in directory /abc as well as in all the subdirectories such as /abc/xyz or /abc/xyz/pqr aqnd so on which was created... (5 Replies)
Discussion started by: abhilashnair
5 Replies

10. UNIX for Advanced & Expert Users

tar subdirectories for specific files

I have a sample directory structire like following # pwd /user/test and I have files like following out.txt A/a.txt B/b.txt C/c.txt (A,B,C are directories ) # tar cvf test.tar * a A/a.txt 1 blocks a B/b.txt 1 blocks a C/c.txt 1 blocks a out.txt 1 blocks But whenever I give (4 Replies)
Discussion started by: ronald_brayan
4 Replies
Login or Register to Ask a Question