Quote:
1. Find file with file name 'foo'
find / -name foo
find / -name fo*
-name : Pattern could be a exact file name or wildcard * can be used
--------------------------------------------------------------------------------
2. Find file with file name 'FoO'
find / -iname foo
-iname : Same as -name variable but the match is case insensitive.
Same way -lname & -ilname variable works.
-lname : File is a symbolic link whose content matches the pattern specified.
-ilname : Same as -lname variable but the match is case insensitive.
--------------------------------------------------------------------------------
3. Finding all 'conf' files at / or at mentioned path.
find / -name *.conf
--------------------------------------------------------------------------------
4. Backing-up/copying all the conf files found in last example over to a seperate folder.
find / -name *.conf exec cp { } / \;
-exec : Executes command. The string { } replaced by the output of find command.
" \;" needs to be there as it tells the end of arguements provided to -exec variable.
|
A quick note on this use of -name ... be SURE that there's no files
that match the globbed pattern in the directory you invoke the command
from if you don't wrap the search-string in quotes.
E.g.. if you had the following directories in the local path
Code:
pg2xbase-2.3.2
pgaccess-0.98.8
pgadmin3-1.2.2
pgmanage-src
pgsql_session_handler.php
php
phpPgAdmin
php_sessions.sql
platform
pme-1.0.4
and you searched for
you'd be getting the following (somewhat bewildering) error-message:
Code:
$ find -name php*
find: paths must precede expression
Usage: find [path...] [expression]
which won't happen if you do it like this:
Code:
$ find -name "php*"
In other words: the globbing of the wildcard by the shell will take
precedence :}
Cheers,
Tink