Just the directories

Just the directories

Post by argos.. » Wed, 03 May 2000 04:00:00



Hi all,

How can find just the directories, that contain certain types of files?

find / -name "*.cfm"
- will give me all the .cfm files.

find / -type d
- will give me all the directories on the system.

find / -name "*.cfm"  -type d
- gives me nothing

I was thinking of cut, and looked at the man pages.
There wasn't anything to cut from the tail end of a string,
that I could see.  If so, it could be delimited by "/".

Is there a way to combine some commands to get just the
directories that contain the .cfm files?

Thanks,

Argosy

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Just the directories

Post by argos.. » Wed, 03 May 2000 04:00:00


How about in awk or sed?

Is there a way to find the last "/",
and then snag everything in front of it?

I've been looking at my reference pages,
but can't find anything.



> Hi all,

> How can find just the directories, that contain certain types of
files?

> find / -name "*.cfm"
> - will give me all the .cfm files.

> find / -type d
> - will give me all the directories on the system.

> find / -name "*.cfm"  -type d
> - gives me nothing

> I was thinking of cut, and looked at the man pages.
> There wasn't anything to cut from the tail end of a string,
> that I could see.  If so, it could be delimited by "/".

> Is there a way to combine some commands to get just the
> directories that contain the .cfm files?

> Thanks,

> Argosy

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Just the directories

Post by Barry Margoli » Wed, 03 May 2000 04:00:00



>How can find just the directories, that contain certain types of files?

find / -name '*.cfm' | sed 's;/[^/]*$;;' | uniq

--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Just the directories

Post by Jason Sain » Wed, 03 May 2000 04:00:00



> Hi all,

> How can find just the directories, that contain certain types of files?

> find / -name "*.cfm"
> - will give me all the .cfm files.

> find / -type d
> - will give me all the directories on the system.

> find / -name "*.cfm"  -type d
> - gives me nothing

> I was thinking of cut, and looked at the man pages.
> There wasn't anything to cut from the tail end of a string,
> that I could see.  If so, it could be delimited by "/".

> Is there a way to combine some commands to get just the
> directories that contain the .cfm files?

> Thanks,

> Argosy

Perhaps not the most efficient way, but the following
script will do the trick.

-----------
#!/bin/sh

for i in `find / -type d`
do
    if [ -f $i/*.cfm ]
    then
         echo $i
    fi
done

----------
--
______________________________________________________

 
 
 

Just the directories

Post by argos.. » Wed, 03 May 2000 04:00:00


This saves me a LOT of time.

Thanks Barry!





> >How can find just the directories, that contain certain types of
files?

> find / -name '*.cfm' | sed 's;/[^/]*$;;' | uniq

> --

> Genuity, Burlington, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to
the group.

Sent via Deja.com http://www.deja.com/
Before you buy.
 
 
 

Just the directories

Post by Deadhead A » Wed, 03 May 2000 04:00:00


Try something like this:

 find / -name "*.cfm" -exec dirname {} \; | uniq


>Hi all,

>How can find just the directories, that contain certain types of files?

>find / -name "*.cfm"
>- will give me all the .cfm files.

>find / -type d
>- will give me all the directories on the system.

>find / -name "*.cfm"  -type d
>- gives me nothing

>I was thinking of cut, and looked at the man pages.
>There wasn't anything to cut from the tail end of a string,
>that I could see.  If so, it could be delimited by "/".

>Is there a way to combine some commands to get just the
>directories that contain the .cfm files?

>Thanks,

>Argosy

>Sent via Deja.com http://www.deja.com/
>Before you buy.

 
 
 

Just the directories

Post by John Hobso » Wed, 03 May 2000 04:00:00



>How about in awk or sed?

>Is there a way to find the last "/",
>and then snag everything in front of it?

You don't know about basename(1).

John Hobson

 
 
 

Just the directories

Post by Randal L. Schwar » Thu, 04 May 2000 04:00:00


argosy22> Is there a way to combine some commands to get just the
argosy22> directories that contain the .cfm files?

In two total processes (well, one, if you want to do it repeatedly):

    ## do this once
    $ find2perl / -name '*.cfm' \
      -eval '$seen{$File::Find::dir}++' \
      -eval 'END { print map "$_\n", sort keys %seen }' >my_finder
    ## do this each time you want the list
    $ ./my_finder >cfm_list

If you have Perl, you have find2perl.  Even on Windows. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

 
 
 

Just the directories

Post by Volker Borche » Thu, 04 May 2000 04:00:00


|> >How can find just the directories, that contain certain types of files?

|> find / -name '*.cfm' | sed 's;/[^/]*$;;' | uniq

                        | xargs -n 1 dirname |

--



 
 
 

Just the directories

Post by kros.. » Thu, 04 May 2000 04:00:00




> Hi all,

> How can find just the directories, that contain certain types of files?

> find / -name "*.cfm"
> - will give me all the .cfm files.

> find / -type d
> - will give me all the directories on the system.

> find / -name "*.cfm"  -type d
> - gives me nothing

> I was thinking of cut, and looked at the man pages.
> There wasn't anything to cut from the tail end of a string,
> that I could see.  If so, it could be delimited by "/".

> Is there a way to combine some commands to get just the
> directories that contain the .cfm files?

I have a feeling that there's a cleaner solution, but this should do the
trick: Caution! this may eliminate directories whose name matches *.cfm

#!/bin/sh
DIRS=/tmp/Dirs.$$
# Create an empty file
touch $DIRS
for file in `find $HOME -name "*.cfm" -print`
do
        dirname $file >> $DIRS
done
sort $DIRS | uniq
rm $DIRS

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Just the directories

Post by Mike Spoone » Thu, 04 May 2000 04:00:00





> > Hi all,

> > How can find just the directories, that contain certain types of files?

> > find / -name "*.cfm"
> > - will give me all the .cfm files.

> > find / -type d
> > - will give me all the directories on the system.

> > find / -name "*.cfm"  -type d
> > - gives me nothing

> > I was thinking of cut, and looked at the man pages.
> > There wasn't anything to cut from the tail end of a string,
> > that I could see.  If so, it could be delimited by "/".

> > Is there a way to combine some commands to get just the
> > directories that contain the .cfm files?

> I have a feeling that there's a cleaner solution, but this should do the
> trick: Caution! this may eliminate directories whose name matches *.cfm

> #!/bin/sh
> DIRS=/tmp/Dirs.$$
> # Create an empty file
> touch $DIRS
> for file in `find $HOME -name "*.cfm" -print`
> do
>         dirname $file >> $DIRS
> done
> sort $DIRS | uniq
> rm $DIRS

There is a less messy way - use a pipeline:

find $HOME -name \*.cfm -exec dirname {} \; | sort | uniq

 
 
 

Just the directories

Post by Matthew Land » Thu, 04 May 2000 04:00:00



> How about in awk or sed?

> Is there a way to find the last "/",
> and then snag everything in front of it?

> I've been looking at my reference pages,
> but can't find anything.

dirname  (gives path)
basename (gives file)

$ dirname /path/to/file
/path/to
$ basename /path/to/file
file

 - Matt

--
_______________________________________________________________________

   << Comments, views, and opinions are mine alone, not IBM's. >>

 
 
 

Just the directories

Post by Matthew Land » Thu, 04 May 2000 04:00:00



> There is a less messy way - use a pipeline:

> find $HOME -name \*.cfm -exec dirname {} \; | sort | uniq

All the "uniq" only solutions don't work right since the output is
not sorted.  There could be multiple copies.  Using sort then uniq
solves that, but sort itself can do it all at once.  Get the
dirname OUTSIDE of the find and into an xargs and things might
speed up a bit.

find $HOME -name \*.cfm | xargs -I {} dirname {} | sort -u

 - Matt

--
_______________________________________________________________________

   << Comments, views, and opinions are mine alone, not IBM's. >>

 
 
 

Just the directories

Post by Ken Pizzi » Fri, 05 May 2000 04:00:00




>|> >How can find just the directories, that contain certain types of files?
>|> find / -name '*.cfm' | sed 's;/[^/]*$;;' | uniq
>                        | xargs -n 1 dirname |

Which spawns one "dirname" per matching file, instead of just
one sed script for the whole batch.

Both of these solutions have a bug, however.  Consider what
happens if the output from the find command is:
   /foo/bar/apple.cfm
   /foo/bar/android/c3po.cfm
   /foo/bar/nanook.cfm
This is easily fixed by using sort:
   find / -name '*.cfm' -print | sed 's;/[^/]*$;;' | sort -u

                --Ken Pizzini

 
 
 

1. cd to a directory with a whitespace in the directory name



   >> The trick is I need to define a variable in the script. (This
   >>variable is  required by other part of the script)
   >> SUB="aa\ bb"
   >> cd $SUB       (DOESN'T WORK in script).
   >The probelm is a variable called the Internal Field Separator (or
   >IFS). Normally, the IFS variable contains three characters: a space,
Actually all you need to do here is
cd "$SUB"
And in the line  SUB="aa\ bb"   using double quotes and a backslash is like
wearing a belt and suspenders.  One or the other is enough.

Net-Tamer V 1.08X - Test Drive

2. IO signal

3. propagating directory perms to new files in that directory

4. Konqueror and Javascript

5. Script that recurses through all directories tries to check file/directory named "*"

6. Extremely Slow

7. How to recursively search through directories in a giving directory

8. Newbie Help: Getting a window manager...

9. Can't create more than 32768 directories on a single directory?!?

10. Login Error -- getcwd: cannot access parent directories: No such file or directory

11. httpd - Error: "Expected </Directory> but saw </Directory>"

12. home directory=root directory

13. directories in the document root directory