Copying files while referencing a text doc - Idiots guide please =]

Associate
Joined
4 Jan 2011
Posts
2,169
Hey guys,

Please forgive the n00bishness of the query, and don't slate me too much if you can restrain yourselves.

I have a list of files (one per line) in a text document, that I need to copy from a portable drive to our internal RAID.

I was told to use this command:

for i in `cat H_S_ALL_CLIPS`; do cp $i /path/to_destination/ ; done

My understanding of this would be that:

The H_S_ALL_CLIPS is the text file. Im ok with that part.

The /path/to/destination is "path to destination" i.e. where I want the files to go.

Now I've tried a couple of times to make this work, but the initial thought for me was that "path" was where the files are and "to_destination" is where I want them to go... I've looked around on a couple of forums but everyone seems to talk about this within the context of knowing what they are doing when it comes to this kind of thing...and I don't.

Anyway if someone could give me some assistance I'd appreciate it. I'm using Terminal in OSX if that makes a difference.

Cheers,

Dave.
 
Are all the files you want to move in one directory? If not, your text file needs to contain thei location. /home/user/file.txt instead of file.txt. You also need to 'cd' to a sensible directory, such as where the files are.

Next, path/to/directory is what it says. Something like /media/usb. It's where your files are going. Where they're coming from is described in the text file.

It would be worth finding a guide to 'bash' online, as that's (probably) your terminal program.
 
Perfect. I wondered if this was the case. The files are split pretty heftily actually, I think its 7 main folders, each with 50 folders, each with a file in. And the list I was give that was meant to work only has the file names in them.

I thought that if I moved the text file to the top of the folder tree and did it that the files would be picked up in some way - I also assumed the guy that gave me the info gave me ALL of the info I needed, seeing as I'm still trying to wrap my head around this kind of thing.

By the sounds of it the manual route is going to be quicker and safer for the time being, deadlines an all that jazz to deal with....

Thanks for clearing that up, as he had written it as path/to_directory it made it look like it was a from_X/to_destination_Y. Hence the initial confusion.

Cheers dude =]
 
If the file names are unique you could use find to get the full paths. Something like:

for i in `cat H_S_ALL_CLIPS`; do find / -name $i; done >filenames_fullpath.txt

Then do your original for loop against filenames_fullpath.txt. This is a big assumption though and you have probably done this manually already.

As suggested read up on bash as it is extremely powerful and once you get used to it you can do crazy things very quickly.

Cheers
 
I have done it manually, but appreciate the follow up anyway Illusion :)

All of the filenames are unique, as they are clips taken from a RED camera. I'll give this a go the next time that I have cause to do another transfer, and will indeed look into bash when I get the chance as well.

Cheers,

Dave.
 
If all the files are in one location, all you need to do is add the path prefix to the ${i} variable like so:

aidan@aidan-i7 ~ $ cat list
foo1
foo2
foo3
aidan@aidan-i7 ~ $ for i in `cat list`; do cp -v ~/dir1/${i} ~/dir2/; done
`dir1/foo1' -> `dir2/foo1'
`dir1/foo2' -> `dir2/foo2'
`dir1/foo3' -> `dir2/foo3'
aidan@aidan-i7 ~ $ ls dir2/
foo1 foo2 foo3

Just for future reference.
 
Back
Top Bottom