Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Verbose display of action

4 views
Skip to first unread message

Owen

unread,
Oct 2, 2010, 5:09:59 AM10/2/10
to

This command will do what I want to do, almost

# find ./ -name picasa.ini | xargs rm

When I delete one, I would like it to show on stdout, like "/path/to/
picassa.ini"

I would appreciate any suggestions.


TIA


Owen

Ben Bacarisse

unread,
Oct 2, 2010, 7:22:33 AM10/2/10
to
Owen <xem...@gmail.com> writes:

You might find that you rm has a -v option:

find ./ -name picasa.ini | xargs rm -v

or that you have a device called /dev/stderr that means you can do this:

find ./ -name picasa.ini | tee /dev/stderr | xargs rm

Neither of this is portable across a wide range of systems, but then you
may not need that for this simple action.

--
Ben.

Janis Papanagnou

unread,
Oct 2, 2010, 7:45:44 AM10/2/10
to
On 02/10/10 13:22, Ben Bacarisse wrote:
> Owen <xem...@gmail.com> writes:
>
>> This command will do what I want to do, almost
>>
>> # find ./ -name picasa.ini | xargs rm
>>
>> When I delete one, I would like it to show on stdout, like "/path/to/
>> picassa.ini"

If you use xargs everything on stdout will be processed. What you are
looking for is the tee(1) command and writing to the terminal; basically
something like

find . -name picasa.ini | tee /dev/tty | xargs rm

>>
>> I would appreciate any suggestions.
>
> You might find that you rm has a -v option:
>
> find ./ -name picasa.ini | xargs rm -v
>
> or that you have a device called /dev/stderr that means you can do this:
>
> find ./ -name picasa.ini | tee /dev/stderr | xargs rm
>
> Neither of this is portable across a wide range of systems, but then you
> may not need that for this simple action.
>

What complicated the matter is the OP's requirement to display /path/to/file.

To show the absolute path on /dev/tty there are a couple choices; e.g.
you can use process substitution and do all processing you like, as in

find . -name picasa.ini | tee >( awk '...' >/dev/tty ) | xargs rm

with an appropriate awk (or sed) command to substitute the absolute path
for the '.' at the place indicated by '...'. Maybe something like

find ... | tee >( awk -v p="$PWD" 'sub(/\./,p)' >/dev/tty ) | xargs rm

Or you may find the following code simpler and easier to understand

find ... | xargs printf "$PWD/%s\n" | tee /dev/tty | xargs rm


(The usual caveat: if you have pathological file names (instead of just
picasa.ini) in your search hierachy you can make severe damage, especially
if you invoke such commands as root; the command prompt '#' is a hint that
the OP might be doing that.)

Janis

Stephen Jones

unread,
Oct 2, 2010, 12:30:19 PM10/2/10
to
Owen <xem...@gmail.com> wrote:
>
>This command will do what I want to do, almost
>
># find ./ -name picasa.ini | xargs rm
>
>When I delete one, I would like it to show on stdout, like "/path/to/
>picassa.ini"

How about: find ./ -name picasa.ini -exec rm {} \; -print

This will print each path to as the file is removed.


--
..!sdf.org!martians / SDF Public Access UNIX System / http://sdf.org

Owen

unread,
Oct 3, 2010, 12:29:38 AM10/3/10
to
On Oct 3, 3:30 am, marti...@sdf.lNoOnSePsAtMar.org (Stephen Jones)
wrote:

Thanks,

find ./ -name picasa.ini -exec rm {} \; -print

worked like a charm.

owen@owen-desktop:/mnt/sdb10/My_Pictures$ find ./ -name picasa.ini -
exec rm {} \; -print
./Ged's Funeral/picasa.ini
./Coffee and Chat/picasa.ini
./Midweek Rides/picasa.ini
./Bicycle Rides/picasa.ini
./Binalong 2005/picasa.ini

Using the "xargs rm" failed outside the directory, the error message I
received was;

owen@owen-desktop:/mnt/sdb10/My_Pictures$ find ./ -name picasa.ini |
xargs rm
xargs: unmatched single quote; by default quotes are special to xargs
unless you use the -0 option

owen@owen-desktop:/mnt/sdb10/My_Pictures$ find ./ -name picasa.ini |
xargs -0 rm
rm: cannot remove `./Ged\'s Funeral/picasa.ini\n./Coffee and Chat/
picasa.ini\n./Midweek Rides/picasa.ini\n./Bicycle Rides/picasa.ini\n./
Binalong 2005/picasa.ini\n': No such file or directory

(where did that \n come from?)

Thanks for your help, several hundred picasa.ini files deleted

Owen

Janis Papanagnou

unread,
Oct 3, 2010, 4:03:28 AM10/3/10
to

Your xargs -0 probably requires a find ... -print0

0 new messages