user1407875
user1407875

Reputation: 69

shell script to read a list of files and copy to a directory

I'm trying to figure out a script file that takes in a file containing list of files and then copy only these files to a different directory. Any help would be appreiated.

Upvotes: 1

Views: 18355

Answers (4)

Rob
Rob

Reputation: 171

I can't comment, therefore expanding slightly on fedorqui's answer, this adds quoting to handle filenames with spaces:

#!/bin/bash

destination="./output_files"

while read file
do
    echo $file
    cp "$file" $destination
done < input_files

Upvotes: 0

twalberg
twalberg

Reputation: 62519

cpio -pmu /new/directory < file

Assuming you have cpio installed, anyway...

Upvotes: 2

Mani
Mani

Reputation: 26

    file="/work/file.txt"

    for j in `cat $file`

    do

      cp ${j} /destination/direc

    done

Upvotes: 0

Vijay
Vijay

Reputation: 67319

for i in `cat file`
do
cp $i /other/
done

Upvotes: 2

Related Questions