Re: [ILUG] Piping to mv

From: Philip Reynolds (phil at domain redbrick.dcu.ie)
Date: Wed 19 Jun 2002 - 10:34:50 IST


Justin MacCarthy's [macarthy at domain iol.ie] 19 lines of wisdom included:
> Is it possible to pipe into mv ??
>
> I want to do something like
>
> find / 'foobar*' | mv /destfolder
>
> i.e. move all files called foobar* into destfolder
>
> I know find has an -exec flag but I was just wondering ...

When you pipe into a program like that, you're copying what's
printed to the screen (i.e. stdout) to what mv takes as input (i.e.
stdin). commandline options don't count as input unfortunately.

What you want is something like

find / -name 'foobar*' -exec mv {} /destfolder \;

or

find / -name 'foobar*' | xargs mv "$1" /destfolder

should do it, IIRC.

Alternatively, in bash/zsh the following should work:

for file in `find / -name 'foobar*'`
do
    mv $file /destfolder
done

Phil.

-- 
  Philip Reynolds        
   RFC Networks          tel: 01 8832063
www.rfc-networks.ie      fax: 01 8832041


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:17:20 GMT