ramjamman:
If you're on a *NIX box and have a text file containing a list of files to copy to a new location, you don't even need to use perl to do the copy. Instead, you can use xargs and tar to do the job. As an example, here's a text file with a list of files to copy:
$ cat mylist.txt
foo
bar
bim/bam
And in our source directory, we have the specified files, along with a file we want to ignore:
$ ls -alR source
source:
total 3.0K
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:51 ./
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:49 ../
-rw-r--r-- 1 Roboticus None 4 Jul 21 00:47 bar
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:48 bim/
-rw-r--r-- 1 Roboticus None 8 Jul 21 00:47 foo
-rw-r--r-- 1 Roboticus None 7 Jul 21 00:51 ignore
source/bim:
total 1.0K
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:48 ./
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:51 ../
-rw-r--r-- 1 Roboticus None 13 Jul 21 00:48 bam
At this time, our dest directory doesn't have anything interesting in it:
$ ls -alR dest
dest:
total 0
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:51 ./
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:49 ../
So all we need to do is to start a process, change to the source directory and then use xargs to tell tar which files to copy into an archive. Then we'll pipe that archive to another process wherein we change to the destination directory and extract all the files, like this:
$ (cd source; xargs <../mylist.txt tar cf -) | (cd dest; tar xf -)
After running that, the files we wanted to copy to dest are there:
$ ls -alR dest
dest:
total 2.0K
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:52 ./
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:49 ../
-rw-r--r-- 1 Roboticus None 4 Jul 21 00:47 bar
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:52 bim/
-rw-r--r-- 1 Roboticus None 8 Jul 21 00:47 foo
dest/bim:
total 1.0K
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:52 ./
drwxr-xr-x+ 1 Roboticus None 0 Jul 21 00:52 ../
-rw-r--r-- 1 Roboticus None 13 Jul 21 00:48 bam
...roboticus
When your only tool is a hammer, all problems look like your thumb. |