Copie todos os arquivos que correspondem aos critérios no comando find com -exec

0

Abaixo estão minhas tentativas de copiar todos os arquivos, exceto os arquivos .out e .class , para um subdiretório denominado homework21/ . Nota homework21 é um subdiretório da pasta em que estou trabalhando.

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/'

Por que isso não está funcionando?

    
por phillipsk 02.10.2015 / 14:54

1 resposta

1

A sintaxe do comando cp é:

cp source target

Portanto, use este comando find :

find . -type f ! '(' -name '*.out' -o -name '*.class' ')' -exec cp -v {} homework21/ \;

Observe que o sinal -r em cp não é necessário, pois você só copia arquivos e não diretórios. Eu adicionei -v em vez disso cp é detalhado.

    
por 02.10.2015 / 14:59