cmd:find 

Usage 

find . -group 500
find ~/www/ai -name lget-log.txt -print -exec cat {} \;

— Should use parameters at full length

find files newer than 

find /etc/ -newer /root/anaconda-ks.cfg

find files for size 

-size N[bckw]

True if the file uses N units of space, rounding up.  The units
are 512-byte blocks by default, but they can be changed by adding a
one-character suffix to N:
`b' 512-byte blocks
`c' bytes
`k' kilobytes (1024 bytes)
`w' 2-byte words

find files in multi-dirs 

find /java/expresso/webapps/expresso/expresso/doc/edg/ /www/html/docs/expresso/javadoc/ -name '*.html'

Naive 

host:~/ndl>find . -name *.tar -exec echo mv {} `fname {}`.bar \;
mv ./st.tar .bar
host:~/ndl>find . -name *.gz -exec echo mv {} `fname {}`.bar \;
find: paths must precede expression
Usage: find [path...] [expression]

— the same syntax with previous, the only difference is this time many files note that the previous is not working as supposed to be.

find with prune 

find /var/ -path '*/spool' -prune -o -path '*/cpan' -prune -o -path '*/www' -prune -o -type d

Try to quote the -exec param: 

host:~/ndl>find . -name *.tar -exec 'echo mv {} `fname {}`.bar \;'
find: missing argument to `-exec'
host:~/ndl>find . -name *.tar '-exec echo mv {} `fname {}`.bar \;'
find: invalid predicate `-exec echo mv {} `fname {}`.bar \;'
host:~/ndl>find . -name *.tar -'exec echo mv {} `fname {}`.bar \;'
find: invalid predicate `-exec echo mv {} `fname {}`.bar \;'
find ~/www/ai -name lget-log.txt -print '-exec echo ; cat {} \;'
find: bad option -exec echo ; cat {} \;
find: path-list predicate-list
iitrc:~/ndl/libwww/libwww-perl-5.41/bin$ find . -name '*.PL' -exec echo mv {} {}.bar \;
mv ./lwp-rget.PL {}.bar
mv ./lwp-download.PL {}.bar
mv ./lwp-mirror.PL {}.bar
mv ./lwp-request.PL {}.bar

Conclusion: 

  • Should use '' when using */?
  • Can only use {} once!
  • give up trying to use more than one command, or {}

find -exec support ` 

1999.09.02 Thu 16:56:06

>How can I use ` in find -exec?
>E.g.:
>find  -name '*.tgz' -exec echo mv {} `basename {}` \;

The simplest solution is to write a script that does what you want, and invoke that with the -exec option. E.g. create a script named moveit that contains:

#!/bin/sh
mv "$1" "`basename $1`"

and then do:

find -name '*.tgz' -exec moveit {} \;
find ~/temp -name 'b*.tgz' -exec fileh fnh mv basename {} \;

Barry Margolin