Friday, September 16, 2005

find comand

When you use a pipeline to run vi like this, it's stdin isn't the
terminal any more. That's what "Input not from terminal" means. The
input is coming from the pipe instead.

Try

vi `find . -name config.xml`

or

find . -name config.xml -exec vi {} \;

or

find . -name config.xml | while read f;do vi $f;done

Joe

uppose we want to compress all .txt
files in an entire subtree. Simple enough, using what we've learned
before:

find /path/to/tree -name '*.txt' | xargs gzip

Another extremely useful way find can sift through files is to find
files created or modified recently. Often you want to know what has
changed recently. For instance, to list all of the files in your home
directory that changed within the past two days hours:

find ~/ -mtime -2

To find the files that haven't been modified in the past two days, you
can change the -mtime parameter:

find ~/ -mtime +2

You can also select files by the last time they were accessed (atime)
or created (ctime). Like bash's test command, find has a wide variety
of options; reading the manpage is advised (not just for reference,
either; it will give you an idea of the flexibility of this peculiar
command).

0 Comments:

Post a Comment

<< Home