Linuxで1つのファイルを複数のファイルにコピーするための1行のコマンド/スクリプトはありますか?
cp file1 file2 file3
最初の2つのファイルを3番目のファイルにコピーします。最初のファイルを残りのファイルにコピーする方法はありますか?
する
cp file1 file2 ; cp file1 file3
「1行のコマンド/スクリプト」として数えますか? どうですか
for file in file2 file3 ; do cp file1 "$file" ; done
?
または、「コピー」の少し緩い意味については、次のようにします。
tee <file1 file2 file3 >/dev/null
ファイルの大きなリストが必要な場合は、楽しみのために:
tee <sourcefile.jpg targetfiles{01-50}.jpg >/dev/null-ケルビン 2 月 12 日 19:52
でもちょっと誤字脱字。次のようにする必要があります。
tee <sourcefile.jpg targetfiles{01..50}.jpg >/dev/null
上で述べたように、それは権限をコピーしません。
for FILE in "file2" "file3"; do cp file1 $FILE; done
使用できますshift:
file=$1
shift
for dest in "$@" ; do
cp -r $file $dest
done
私が考えることができる最も簡単で迅速な解決策は、for ループです。
for target in file2 file3 do; cp file1 "$target"; done
汚いハックは次のようになります(私は強くお勧めしません。とにかくbashでしか機能しません):
eval 'cp file1 '{file2,file3}';'
代わりに、標準のスクリプト コマンドを使用できます。
バッシュ:
for i in file2 file3 ; do cp file1 $i ; done