以下是我尝试将除.out
和.class
文件之外的所有文件复制到标题为 的子目录中homework21/
。 Notehomework21
是我正在其中工作的文件夹的子目录。
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
标志 incp
不是必需的,因为您只是复制文件而不是目录。我补充-v
说这cp
很冗长。