.out
以下は、.class
ファイルを除くすべてのファイルをというサブディレクトリにコピーしようとしますhomework21/
。 Noteは、homework21
私が作業しているフォルダのサブディレクトリです。
me@ice4:~/pset2$ find . -type f ! '(' -name '*.out' -o -name '*.class' ')'
./PartB.txt
./DooBee.java
./Prob8.java
./Diamond.java
./Prob10.java
./Prob11.java
./Drawing.java
./typescript
me@ice4:~/pset2$ find . -type f ! '(' -name '*.out' -o -name '*.class' ')' -exec cp -r homework21/. {} \;
cp: cannot overwrite non-directory `./PartB.txt' with directory `homework21/.'
cp: cannot overwrite non-directory `./DooBee.java' with directory `homework21/.'
cp: cannot overwrite non-directory `./Prob8.java' with directory `homework21/.'
cp: cannot overwrite non-directory `./Diamond.java' with directory `homework21/.'
cp: cannot overwrite non-directory `./Prob10.java' with directory `homework21/.'
cp: cannot overwrite non-directory `./Prob11.java' with directory `homework21/.'
cp: cannot overwrite non-directory `./Drawing.java' with directory `homework21/.'
cp: cannot overwrite non-directory `./typescript' with directory `homework21/.'
me@ice4:~/pset2$ ls homework21/
me@ice4:~/pset2$ find . -type f ! '(' -name '*.out' -o -name '*.class' ')' -exec cp homework21/. {} \;
cp: omitting directory `homework21/.'
cp: omitting directory `homework21/.'
cp: omitting directory `homework21/.'
cp: omitting directory `homework21/.'
cp: omitting directory `homework21/.'
cp: omitting directory `homework21/.'
cp: omitting directory `homework21/.'
cp: omitting directory `homework21/.'
me@ice4:~/pset2$ ls homework21/
me@ice4:~/pset2$ find . -type f ! '(' -name '*.out' -o -name '*.class' ')' -exec cp homework21/ {} \;
cp: omitting directory `homework21/'
cp: omitting directory `homework21/'
cp: omitting directory `homework21/'
cp: omitting directory `homework21/'
cp: omitting directory `homework21/'
cp: omitting directory `homework21/'
cp: omitting directory `homework21/'
cp: omitting directory `homework21/'
me@ice4:~/pset2$ find . -type f ! '(' -name '*.out' -o -name '*.class' ')' -exec cp -r homework21/ {} \;
cp: cannot overwrite non-directory `./PartB.txt' with directory `homework21/'
cp: cannot overwrite non-directory `./DooBee.java' with directory `homework21/'
cp: cannot overwrite non-directory `./Prob8.java' with directory `homework21/'
cp: cannot overwrite non-directory `./Diamond.java' with directory `homework21/'
cp: cannot overwrite non-directory `./Prob10.java' with directory `homework21/'
cp: cannot overwrite non-directory `./Prob11.java' with directory `homework21/'
cp: cannot overwrite non-directory `./Drawing.java' with directory `homework21/'
cp: cannot overwrite non-directory `./typescript' with directory `homework21/'
なぜこれがうまくいかないのですか?
答え1
cp コマンドの構文は次のとおりです。
cp source target
したがって、次のfind
コマンドを使用します。
find . -type f ! '(' -name '*.out' -o -name '*.class' ')' -exec cp -v {} homework21/ \;
ディレクトリ以外のファイルだけをコピーするため、-r
inフラグは必要ありません。内容が長かったと付け加えcp
ました。-v
cp