find directories that do NOT contain a certain file extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find directories that do NOT contain a certain file extension
# 1  
Old 04-05-2010
Network find directories that do NOT contain a certain file extension

for x in `find /vmfs/volumes/v01tstn01a01/ -type d`; do find $x -name '*.vmx' > /dev/null || echo $x; done;

The goal of this is to find the subdirectories that do NOT contain a file with the extension of .vmx


Any help would be great!
# 2  
Old 04-05-2010
Try this:

Code:
find $x \( ! -name '*.vmx' \)

# 3  
Old 04-05-2010
Thanks for the reply!

I have pasted my attempts with your suggestion below.



[root@Test23]# find /vmfs/volumes/v01tstn01a01 \( ! -name '*.vmx' \)
/vmfs/volumes/v01tstn01a01
[root@Test23]# for x in `find /vmfs/volumes/v01tstn01a01`; do find $x \( ! -name '*.vmx' \); done;
/vmfs/volumes/v01tstn01a01
[root@Test23]# find /vmfs/volumes/v01tstn01a01/rtest
rtest1/ rtest2/
[root@Test23]# find /vmfs/volumes/v01tstn01a01/rtest1 \( ! -name '*.vmx' \)
/vmfs/volumes/v01tstn01a01/rtest1
/vmfs/volumes/v01tstn01a01/rtest1/rtest1-flat.vmdk
/vmfs/volumes/v01tstn01a01/rtest1/rtest1.nvram
/vmfs/volumes/v01tstn01a01/rtest1/vmware.log
/vmfs/volumes/v01tstn01a01/rtest1/vmware-39.log
/vmfs/volumes/v01tstn01a01/rtest1/vmware-40.log
/vmfs/volumes/v01tstn01a01/rtest1/vmware-36.log
/vmfs/volumes/v01tstn01a01/rtest1/vmware-41.log
/vmfs/volumes/v01tstn01a01/rtest1/vmware-38.log
/vmfs/volumes/v01tstn01a01/rtest1/rtest1.vmdk
/vmfs/volumes/v01tstn01a01/rtest1/rtest1.vmxf
/vmfs/volumes/v01tstn01a01/rtest1/rtest1.vmsd
/vmfs/volumes/v01tstn01a01/rtest1/vmware-37.log


Maybe I'm not understanding how to apply it. I don't have a lot of Linux experience.
Ideally it should print out only a list of subdirectories NOT containing a .vmx file

I have rigged the rtest1 directory to not contain a vmx
# 4  
Old 04-05-2010
Code:
find /vmfs/volumes/v01tstn01a01 -type d | while read dir ; do 
    ls ${dir}/*.vmx > /dev/null 2>&1
    if [ $? -ne 0 ] ; then
         echo "$dir"
    fi
done

# 5  
Old 04-05-2010
Looks like that will work.

Thanks!

I also managed to google this up....

find /vmfs/volumes/v02tstn02a01/ -type d | while read dir; do if [ ! -f $dir/*.vmx ]; then echo $dir; fi; done;

Very similar.

Thanks a bunch for the replies.
# 6  
Old 04-05-2010
Quote:
Originally Posted by hodnov
Looks like that will work.

Thanks!

I also managed to google this up....

find /vmfs/volumes/v02tstn02a01/ -type d | while read dir; do if [ ! -f $dir/*.vmx ]; then echo $dir; fi; done;

Very similar.

Thanks a bunch for the replies.
That will probably break if you have more than one file in a directory. If you have only one vmx can be in a directory you'll be fine.
# 7  
Old 04-05-2010
If you really, really, really want to protect against oddball filenames and you really, really, really want to avoid as much process creation as possible (perhaps there are many directories and files to go through) the following would be a good approach:
Code:
find top -type d -print0 | xargs -0 filecheck.sh

filecheck.sh:
Code:
#!/bin/sh

for d; do
    for f in "$d"/*.vmx; do
        [ -f "$f"  ] && continue 2
    done 
    echo "$d"
done

Note that the above checks strictly for a file ending in .vmx. A directory or a pipe or some other type of directory entry ending in .vmx will not be considered a match.

Also, filecheck.sh needs to be in your $PATH or a pathname with a "/" must be used to invoke it.

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

Bash to create sub directories from specific file extension

In the bash below I am trying to create sub-directories inside a directory from files with specific .bam extensions. There may be more then one $RDIR ing the directory and the .bam file(s) are trimmed (removing the extension and IonCode_0000_) and the result is the folder name that is saved in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. UNIX for Beginners Questions & Answers

Find file with extension and excluding directory

Hi, I have an inquiry on how do I use the find command in Solaris Unix to find some file ends with extension : txt, err in the root directory with modified date of 30days and this find command will also need to exclude b directory and its subdirectory. All the files from the above find criteria... (5 Replies)
Discussion started by: snowfrost88
5 Replies

3. UNIX for Dummies Questions & Answers

Getting directories resulted from Find in one file

Hi Need help for the following scenario. I am having two directories /tmp/a and /tmp/b. /tmp/a again has subdirectories /tmp/a/aa and /tmp/a/ab. I want to run a script from /tmp/b to search for a file user.lst in the folders /tmp/a/aa and /tmp/a/ab, if available, i want to make a file in... (3 Replies)
Discussion started by: sudeep.id
3 Replies

4. Shell Programming and Scripting

awk and regex to find out file extension

From following data, I want to only publish those lines in which column 6 has the value with extension .dat. col1,col2,col3,col4,col5,col6.txt,col7,col8 col1,col2,col3,col4,col5,col6.date,col7,col8 col1,col2,col3,col4,col5,col6.jpg,col7,col8 col1,col2,col3,col4.dat,col5,col6.dat,col7,col8... (3 Replies)
Discussion started by: fahdmirza
3 Replies

5. UNIX for Dummies Questions & Answers

creating separate directories according to file extension and keeping file in different directory as

unix program to which a directory name will be passed as parameter. This directory will contain files with various extensions. This script will create directories with the names of the extention of the files and then put the files in the corresponding folder. All files which do not have any... (2 Replies)
Discussion started by: Deekay.p
2 Replies

6. Shell Programming and Scripting

How to find the recent file in many sub-directories?

Hi guys, Under my root directory there are many sub-directories which contains log file for every day of running. How can I find , in one command only, the recent log file in each sub-directory? For example, If I run the following: find . -name "exp_prod_*_*_yes_*_.log" -exec ls -ltr {} \;... (12 Replies)
Discussion started by: nir_s
12 Replies

7. Shell Programming and Scripting

Find Directories That Do Not Contain A Certain File

I'm having problems figuring out the process to find directories that DO NOT contain a certain file. I have a mp3 collection that all the album art is name "folder.jpg". Not all the albums have images. I need a way to find the albums/directories that do not contain "folder.jpg". I can find the... (2 Replies)
Discussion started by: subsonic
2 Replies

8. Shell Programming and Scripting

compress directories with .tar extension

hi guys.. Since am a bit new to shell scripting, can anyone help me with this problem please.. i've been struggling with it since 2 days. :( I have a directory lets say myFolder and within it I have sub directories let say myFolder1.tar, myFolder2, myFolder3, etc. I need to write a shell... (12 Replies)
Discussion started by: kanexxx
12 Replies

9. Shell Programming and Scripting

Find a file in sub-directories.. o/p just the path

Hello All, I am somehow stumped with this ting. 'Find' will sure show me.. but I want only thepath of all the occurences of the file in any of the sub-dirs.. Any help will be sincerely appreciated. thanx! (3 Replies)
Discussion started by: pranavagarwal
3 Replies

10. Programming

to find a file in set of directories

Hi, what is the command in unix to find a file abc.c in a directory which had n number of sub-directories. thanx (3 Replies)
Discussion started by: jazz
3 Replies
Login or Register to Ask a Question