|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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 | Display Modes |
|
#1
|
|||
|
|||
|
how to copy files and record original file location?
:EDIT:
I think my post name should have been labeled: how to copy files and record original file location. not "retain". Hello, this is my first post! I searched the forums a lot before posting, but was unable to answer my question. Here's my problem: There are several hundred text files spread out in tons of different directories which I need to copy into one folder. I can easily find and copy all the files I need into one folder, but I would also like to retain the original path with each file, so I can go to the original location, if needed. Once I have all the files copied over into one folder, I can easily find "123.txt", but I have no idea where the original file is. I need to know that information. What is the best way to retain the original directory path with each file? Should I copy the directory path and append it to the beginning or end of each file? Is there a way to create an output list of all copied files which shows the original location from where each file was copied? Last edited by methyl; 04-17-2012 at 09:06 AM.. Reason: updated thread title |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
You could make symbolic links instead of copies. They'd act like files when used by programs, but would in fact be shortcuts to the originals. You can find their actual location just by doing ls -l on them. Code:
find /absolute/path/to/folder -type f -iname '*.txt' -exec ln -s '{}' /path/to/destfolder ';'In ls -l they'd look something like this: Code:
lrwxrwxrwx 1 root root 40 Nov 29 2010 file -> /absolute/path/to/file |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Corona, thanks for the help. Your suggestion would work, except for one problem. The reason I copied all the files into one location is because all the copied files are then moved over onto a Windows file system, and used in an Access database. I need the original file locations, so any database search results will show the original file path in Unix, so the user can switch systems and find the files needed. Our Unix systems are old and don't have database utilities like Access, so we have to do it through Windows...
If I created a symbolic link for each file copied, would it be possible to create a list of those symbolic links which shows the original path, all in one text file? |
|
#4
|
|||
|
|||
|
Just make a list of their locations then. Code:
find /absolute/path/to/folder -type f -iname '*.txt' -exec cp '{}' /path/to/destination -print | sed 's/$/\r/g' > list-of-locations.txtIt will copy the file, then print the name to stdout, where sed will add carriage returns so windows can read it the list and finally redirect that into list-of-locations.txt |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Yes, that worked! I was exploring the sed command, but was using it wrong. This helped a lot, thanks!
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to copy a file from one location to another location? | vel4ever | Shell Programming and Scripting | 1 | 01-12-2012 04:29 AM |
| Search Files from Array and link to original location in Perl | aarora1 | Shell Programming and Scripting | 3 | 06-20-2011 06:52 PM |
| Shell Script for Copy files from one location to another location | allways4u21 | Shell Programming and Scripting | 2 | 01-21-2010 03:26 PM |
| copy files from one location to similar location | pharos467 | UNIX for Advanced & Expert Users | 1 | 09-21-2008 12:21 PM |
| command to copy files with original ownership | need_help | UNIX for Advanced & Expert Users | 3 | 02-08-2008 06:46 PM |
|
|