how to copy files and record original file location?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to copy files and record original file location?
# 1  
Old 04-16-2012
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 10:06 AM.. Reason: updated thread title
# 2  
Old 04-16-2012
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

# 3  
Old 04-16-2012
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  
Old 04-16-2012
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.txt

It 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
# 5  
Old 04-16-2012
Yes, that worked! I was exploring the sed command, but was using it wrong. This helped a lot, thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files based on specific word in a file name & its extension and putting it in required location

Hello All, Since i'm relatively new in shell script need your guidance. I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder. so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR... (13 Replies)
Discussion started by: prajaktaraut
13 Replies

2. Shell Programming and Scripting

Copy files from one location to another

I have below files in one location /test/files and also for each dates there are similar files A20130924.0000-0005_file1 A20130924.0000-0005_file2 A20130924.0005-0010_file1 A20130924.0005-0010_file2 . . . A20130924.2355-0000_file1 A20130924.2355-0000_file2 If i execute the script like... (4 Replies)
Discussion started by: Saidul
4 Replies

3. Shell Programming and Scripting

Restoring a file to its original location

Hello everyone, I am attempting to make a recycling bin type application in shell script (tcsh). I have the whole part of the application done where someone can recycle files from one location to the recycling bin (the lower half of the program), this is not a problem. However I wanted to make... (7 Replies)
Discussion started by: tastybrownies
7 Replies

4. UNIX for Advanced & Expert Users

copy original files from links

I have folder ABC and files in ABC are links. I want to create the same ABC folder in different path and copy the actual files from source ABC dir. Can anyone provide HP-UX command for this? note: cp -L is not working in HP-UX Thanks in advance. (1 Reply)
Discussion started by: venkatababu
1 Replies

5. Shell Programming and Scripting

command to copy original files from links in HP-UX

I have folder ABC and files in ABC are links. I want to create the same ABC folder in different path and copy the actual files from source ABC dir. Can anyone provide command for this? Thanks in advance. (2 Replies)
Discussion started by: venkatababu
2 Replies

6. Shell Programming and Scripting

How to copy a file from one location to another location?

I have file file1.txt in location 'loc1'. Now i want a copy of this file in location 'loc2' with a new file called test.txt. Please help me how to do this in shell script. (1 Reply)
Discussion started by: vel4ever
1 Replies

7. Shell Programming and Scripting

Search Files from Array and link to original location in Perl

Hello, Question is related to Perl: I need to search few of the files from the array of file names. And after grepping the file names from an array I need to link these files to original location. The original location in this case is ref_path as input from the user. ##$ref_path is... (3 Replies)
Discussion started by: aarora1
3 Replies

8. Shell Programming and Scripting

Shell Script for Copy files from one location to another location

Create a script that copies files from one specified directory to another specified directory, in the order they were created in the original directory between specified times. Copy the files at a specified interval. (2 Replies)
Discussion started by: allways4u21
2 Replies

9. UNIX for Advanced & Expert Users

copy files from one location to similar location

I need help in forming a script to copy files from one location which has a sub directory structure to another location with similar sub directory structure, say location 1, /home/rick/tmp_files/1-12/00-25/ here 1-12 are the number of sub directories under tmp_files and 00-25 are sub... (1 Reply)
Discussion started by: pharos467
1 Replies

10. UNIX for Advanced & Expert Users

command to copy files with original ownership

Hi, I need a command that to copy files from others and to keep files' ownership. Example: I copy file.txt from users "abc" to my local, and file.txt is own by user "abc" in local. Thanks in advance! (3 Replies)
Discussion started by: need_help
3 Replies
Login or Register to Ask a Question