Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 'mv' all files containing a certain string to a sub-directory



Matt,

Matt Wozniski wrote:
>> Are you looking for smth like:
>>
>> find . -type f -exec grep -e "a certain string" {} \; -exec mv {} tmp \;
>>
>> HTH
> 
> Heinrich's suggestion would move files both in the current directory
> and subdirectories that match your search string.  If you only want
> the current directory, you should be fine to use a
> 
> mv *somestring* tmp

this moves all files containig 'somestring' in it's filename, not in the
file itself, as I understood it and as it would in the former command.

But you are right, the find expressens prerequisite would be that it is
 not allowd to have 2 or more files matching the grep with the same name
in different directories in '.'. Otherwise you would sould only find a
subset of files in tmp

And tmp should not be a subdirectory of the directory you are searching
in it would break with an error for moving the same file to itself

> 
> ~Matt
> 
> PS - Sorry Heinrich, I accidentally sent this to you instead of the
> list at first.  My bad.  :)
don't worry, happend to me 10 Minutes ago as well :-)


cheers

Heinrich
> 
> On 10/31/06, Heinrich Götzger <goetzger@xxxxxx> wrote:
>> zzapper wrote:
>> > Hi
>> > I want to 'mv' all files containing a certain string to a
>> sub-directory.
>> > Should be trivial but cant think how w/o creating a temporary file
>> >
>> >
>> >
>>
>> Are you looking for smth like:
>>
>> find . -type f -exec grep -e "a certain string" {} \; -exec mv {} tmp \;
>>
>> HTH
>>
>> Heinrich
>>



Messages sorted by: Reverse Date, Date, Thread, Author