|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 | ||
|
|
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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 |
|
|
![]() |
| Bookmarks |
| Tags |
| recursive copy random |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |