1

I have files: x0001_test.xml z0054_test.xml k5487_test.xml....

I would like to save them doing something like: cp *_test.xml ${BEGINNING}_test.xml.SAVE.

Is there a way in bash script to store the content of * for each file in order to re-inject it after? Or should I use a loop?

4

2 に答える 2

1

これを行うためのループはおそらく簡単で、別の 1 行のコマンドは必要ありません。全体に追加するだけなので、ファイル名の一部を保存する必要はありません。.SAVE

for fspec in *_test.xml; do
    cp "${fspec}" "${fspec}.SAVE"
done

いずれにせよ、本当に必要な場合は、1 行で実行できます。

for fspec in *_test.xml; do cp "${fspec}" "${fspec}.SAVE" ; done
于 2012-10-30T09:09:12.167 に答える
0

@paxdiablo が最も率直な答えをくれました。別のオプションのカップル

printf "%s\0" *_test.xml | xargs -0 -L1 -I{}  cp {} {}.SAVE
find . -name \*_test.xml -exec  cp {} {}.SAVE \;

これは、GNU xargs があることを前提としており、find コマンドはサブディレクトリで一致するファイルを見つけることができます。

于 2012-10-30T14:43:29.540 に答える