0

images というディレクトリがあり、そこには多くの画像が含まれています。例えば:

images/
    imag001.png
    imag002.png
    imag003.png
    imag004.png

そして、別の場所にコピーしたいファイルを含むテキスト ファイルがあります。test.txt ファイルに

img001.png
img003.png

test.txt で指定されたファイルを images フォルダーから別の場所にコピーするにはどうすればよいですか?

4

5 に答える 5

1

imagesディレクトリの下でこのワンライナーを試してください:

awk '{print "cp "$0" /target/path"}' test.txt|sh
于 2013-08-14T23:27:43.307 に答える
0
 cat copylist.txt  | xargs -n1 -I %  echo cp   % destination/.
 # remove echo after testing
于 2013-08-14T23:32:34.217 に答える
0

私はあなたができるbashシェルだと思います:

for image in $(cat copylist.txt); do
    cp $image destination
done
于 2013-08-14T23:26:54.687 に答える
0

あなたは書ける:

while IFS= read -r image_filename ; do
    cp images/"$image_filename" some_other_place/
done < test.txt
于 2013-08-14T23:27:14.177 に答える
0

この問題にはおそらく多くの解決策があります。xargs を使用してそれを行います。

cd images/
cat path/to/test.txt | xargs -I FILES cp FILES path/to/dest/
于 2013-08-14T23:28:10.583 に答える