On Friday 09 March 2007 13:41, Vince Oliver wrote:
> ...
>
>
> I was not precise enough
>
> I would just like to know if I could do more then one tast with the
> -exec. For example to remove all "*dat" files from DH1 and list the
> content with ls, to remove all "*.dat" from DH2 and list and so on
> ... for each DH* file
You can use as many criteria as you like before you commit to an action
such as -print or -exec. But -exec can only directly trigger the
execution of on process. (See below.)
> This attempt
>
> find DH* -type f -name "*.dat" -exec rm {} \; | ls
>
> does not work properly
There are many variations possible. You could have find exec a shell
script that does everything you need. Or you could add an
explicit -print.
It's worth knowing that on Gnu find, such as we use on Linux, the -print
is implied when no other action is found, keeping in mind that actions
(such as printing or execing) are distinct from criteria, such as name
patterns, types, modes, sizes, dates, etc. So most of the time we omit
the -print and see the items that meet the specified criteria. But as
soon as you include an explicit action, such as -exec, the
implicit -print is suppressed and you don't see the items found. But
you can always explicitly -print along with your -exec.
It's also good to know that unlike most other Unix / Linux programs that
can invoke other programs, find does not use a shell to interpret the
command. Rather, it builds a simple argument list from discrete
arguments given to it and passes them on to the exec(2) system call.
If you put a -print before your -exec, everything that meets the
preceding criteria will be printed. If you put it after, only those
items for which the -exec returns a success status will be printed.
Lastly, it's a complete misunderstanding to think that ls will read its
standard input for the names of files to list (or anything else).
Instead, you can use the command substitution syntax:
ls $( find DH* -type f -name "*.dat" -exec rm {} \; -print )
If there will be many files so processed, the top-level shell may
complain that the argument list is too long and not invoke ls (even
though the find will have completed normally). In that case, do this:
find DH* -type f -name "*.dat" -exec rm {} \; -print |xargs ls
That should give you enough to go on for further experimentation.
Randall Schulz
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]