Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google site



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-17-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
Recursive copy to a RANDOM name

Dear Group,

after trying numerous suggestions and racking my brain I cannot manage something which seems so simple.

Essentiallly, I would like to perform a recursive copy to a destination but give it a random name.

I assumed (incorrectly) that the following would work:

cp -r /destination_folder/$RANDOM

but I only get the response: cp: missing destination file operand after `/destination_folder/19977'

Can someone with a bigger brain than mine please help?

Many thanks,

Roki
Sponsored Links
  #2 (permalink)  
Old 10-17-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,169
cp takes two arguments
cp fromdirectory/file todirectory/file

There is also a problem with what you are doing. If you were to try this, say a few hundred times, you would be likely to get duplicates. In other words $RANDOM is random and will produce the same value again sometime in the future.
  #3 (permalink)  
Old 10-17-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
Hi Jim,

Many thanks for the reply.

You are right in saying that I would get duplicates...I now remember why I was trying to get the original filename next to the $RANDOM variable. I gave up after many attempts.
There are thousands of files in these directories.

Does this mean that the only easy way to do this is by writing a bash script?:

#! /bin/bash

for filename in `find . -type f`; do

cp $filename /destination_folder/$filename.$RANDOM

done


when I try to run this it just hangs.

Any suggestions?

Thanks,

R
  #4 (permalink)  
Old 10-17-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,169
If there are thousands of files your script will run a while. If there are sub-directories on the source side, you will also get errors.

What are you trying to accomplish? It looks like you are just duplicating a directory.
  #5 (permalink)  
Old 10-17-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
Yes I there are subirectories on the source side.

I'm trying to clean up thousands of image files which I have collected over the years. Unfortunately I haven't been keeping track of what copies I have where. It is very likely that there are duplicates of files spread out.

My goal is to consolidate these files into one directory and remove duplicates using md5sum.

The folder structures they are in have been copied over from Windows systems which means that there is white space in some of the path names (and possibly other characters) which may make copying them less than straightforward. This is why I thought of doing a recursive copy to one directory and incorporating a random name to the file would help.

If you have an easy way to do this, I would greatly appreciate hearing it.

I've tried experimenting with bash scripts but none have worked (which probably says more about my scripting skills than anything else.)

Thanks
  #6 (permalink)  
Old 10-17-2008
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,150
Count the files so we know how many:
find . -type f | wc -l


Post a few sample filenames showint desired transformation:

grand canyon.gif -> 000123456.gif
or
grand canyon -> 00001112233

or whatever. There are ways to to get unique random numbers, but do they really need to be random? Naming them 1, 2, 3, etc is a snap.
  #7 (permalink)  
Old 10-17-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
Hello Perderabo,

the total file count with the command is 88127.

The typical folder/file structure is:

with spaces
./cdell/Documents and Settings/Roki/My Documents/Exported Pics/images/Fl_0112.jpg

or with square brackets
./epd/Pics/Chris/Temp Folder/665109_7_t[1].jpg

To be honest, the numbers don't need to be random at all. The only reason I suggested random number is that that way I would be sure not to have a duplicate filename if concatenated with an actual filename.

The goal would be to have all the 88127 files inside one folder so that I can easily remove duplicates based on md5 hash.

I hope I've explained myself clearly.

Many thanks again.

Roki.
Sponsored Links
Closed Thread

Bookmarks

Tags
recursive copy random

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Recursive FTP -- here at last. Perderabo Shell Programming and Scripting 52 03-25-2009 12:15 PM
recursive copy of the directory deepthi.s Programming 7 08-23-2008 02:06 PM
recursive rcp Nicol Shell Programming and Scripting 6 11-06-2003 11:52 AM
recursive copy of hidden files usfrog UNIX for Advanced & Expert Users 2 02-19-2002 03:16 PM
Recursive FTP aslamg UNIX for Dummies Questions & Answers 1 03-08-2001 04:27 AM



All times are GMT -4. The time now is 11:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0