[Tfug] Need help with a complicated command line copy...

Bowie J. Poag bpoag at comcast.net
Thu Jun 28 02:07:55 MST 2007



No, but it can be made to do so with ease.

Just put a simple accumulator in the loop:

for i in `cat list.foo`
do
let a=a+1
cp $i /destination/directory/where/you/want/the/files/to/go/$a-$i
done

..That will prefix a number on every file that gets copied, producing 
files like "349-foo.pdf"



Cheers,
Bowie


Jim March wrote:
> Cool.  I'll likely slap it into a script but...yeah, I'll try it tomorrow.
>
> One question: is Bowie's recipe doing the datestamp stuff?  I mean,
> I've got seven source disks, and a given file may be on three or four
> of 'em in various stages.  I only want to keep the newest.
>
> Thanks!
>
> Jim
>
> On 6/28/07, Christopher Robbins <robbinsc at gmail.com> wrote:
>   
>> I'm entering this one a bit late, but...
>>
>> No, you can actually type in Bowie's stuff from the command line and it will
>> do it for you...for-loops and the
>> like are implemented in the shell.
>>
>> Good luck
>>
>>   - Chris
>>
>> On 6/27/07, Jim March <1.jim.march at gmail.com> wrote:
>>     
>>> Bowie, I think you mean "stick this stuff in an executable script", right?
>>>
>>> Jim
>>>
>>> On 6/27/07, Bowie J. Poag <bpoag at comcast.net> wrote:
>>>       
>>>> Type this in as you see it:
>>>>
>>>> cd /
>>>> for i in pdf doc xls
>>>> do
>>>> find /this/guys/hard/disk/*.$i >list.foo
>>>> done
>>>>
>>>>
>>>> for i in `cat list.foo`
>>>> do
>>>> cp $i /destination/directory/where/you/want/the/files/to/go/
>>>> done
>>>>
>>>>
>>>> Cheers,
>>>> Bowie
>>>>
>>>>
>>>>
>>>>
>>>> Jim March wrote:
>>>>         
>>>>> Guys,
>>>>>
>>>>> I have a complicated problem.
>>>>>
>>>>> I have a stack of old hard disks with data a friend wants extracted.
>>>>> There are a lot of duplicates, and of course they're scattered across
>>>>> multiple subdirectories.
>>>>>
>>>>> The file types are as you'd expect: .pdf, .doc, .xls, etc.
>>>>>
>>>>> At the DOS command line I'd have trouble with this: I could use XCOPY
>>>>> to move the files (based on extension) from disk to disk including
>>>>> subdirectories, but In this case I don't WANT the target-location
>>>>> files to be in subdirectories.  Instead, as I pile the files into the
>>>>> target location I want to keep them all in one, and as new ones try
>>>>> and come in retain the one with the latest datestamp.
>>>>>
>>>>> I'm using standard Ubuntu Feisty so I figure there has to be a way to
>>>>> skin this cat at the command line, probably with standard tools but,
>>>>> maybe with some add-in package?  Any tips would be welcome :).
>>>>>
>>>>> Thanks!
>>>>>
>>>>> Jim
>>>>>
>>>>> _______________________________________________
>>>>> Tucson Free Unix Group - tfug at tfug.org
>>>>> Subscription Options:
>>>>> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
>>>>>
>>>>>
>>>>>           
>>>> _______________________________________________
>>>> Tucson Free Unix Group - tfug at tfug.org
>>>> Subscription Options:
>>>> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
>>>>
>>>>         
>>> _______________________________________________
>>> Tucson Free Unix Group - tfug at tfug.org
>>> Subscription Options:
>>> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
>>>
>>>       
>>
>> --
>> Chris Robbins
>> Systems Programmer
>> Department of English - University of Arizona
>> http://www.homerengineeringcorp.net
>> _______________________________________________
>> Tucson Free Unix Group - tfug at tfug.org
>> Subscription Options:
>> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
>>
>>     
>
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
>
>   





More information about the tfug mailing list