Depending on the situation, I might do it slightly differently:

find -regex <pattern> -print0 |xargs -0 mv {} /path/to/other/dir

A good reason to use find over ls|grep is that your criteria can be much
broader including file types, permissions, simple names, create and
modified dates, size, and more.

Here's another alternative:

find -regex <pattern> -exec mv {} /path/to/other/dir \;


find's -print0 means print with the null character \0x0 between filenames.
xargs' -0 means look for names separated by the \0x0 character.
{} means place the current filename being processed here and works with
both find -exec and xargs.

Other simple find arguments are -name and -iname for case
sensitivity/insensitivity.  Find is recursive by default.  -maxdepth 1
to specify the current directory only.

What' Q+D?  

Cory


On Wed, Jan 22, 2003 at 11:57:21AM -0800, Larry Price wrote:
> 
> just some random observations that might be of use,
> in my job I occassionally have to deal with directories containing a very
> large number of files and have a need to sieve them or operate in a
> non-uniform manner on them.
> 
> so if you haven't yet encountered the 'argument list too big' error
> message here's a few useful bits that might stave off the shakes
> 
> note: most of this can be accomplished with find, but these are the q+d
> lines that will let you get the job done while you are reading the man
> page for find
> 
> to get all files whose name matches a pattern and move them to another dir
> 
> ls|grep <pattern>|xargs -l1 mv --target-directory=/path/to/other/dir/
> 
> the important bits: xargs -l1 says to construct new commands from each
> line of stdin it receives and the long option for mv is so that xargs can
> use it as though the invocation of mv were something like
> mv --target-directory=/some/random/path $1
> 
> So that's your Q+D shell trick for the day, remember there is a clinic
> tonight. See you there
> 
> -- 
> http://www.efn.org/~laprice        ( Community, Cooperation, Consensus
> http://www.opn.org                 ( Openness to serendipity, make mistakes
> http://www.efn.org/~laprice/poems  ( but learn from them.(carpe fructus ludi)
> 
> _______________________________________________
> Eug-LUG mailing list
> [EMAIL PROTECTED]
> http://mailman.efn.org/cgi-bin/listinfo/eug-lug
_______________________________________________
Eug-LUG mailing list
[EMAIL PROTECTED]
http://mailman.efn.org/cgi-bin/listinfo/eug-lug

Reply via email to