Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to learn the find command, please help me with this warning:

ankit@battlestar:/home/mount_150/studies$ find -iname "*.pdf" -exec cp -ar {} lcommands/  \;
cp: `./lcommands/june.pdf' and `lcommands/june.pdf' are the same file
cp: `./lcommands/cde.pdf' and `lcommands/cde.pdf' are the same file
cp: `./lcommands/abc.pdf' and `lcommands/abc.pdf' are the same file
ankit@battlestar:/home/mount_150/studies$ ls -l lcommands/

Please see the screenshot of the procedure I followed, and the directory structure.

enter image description here

share|improve this question
2  
I think, it says, It has found another instance of the same file. Because, ./lcommands and lcommands are the same directory. The command executes in such a way that, it reads both ./lcommands and lcommands. –  Anwar Shah Aug 4 '12 at 9:34
    
but initially the destination folder is empty. –  Ankit Aug 4 '12 at 9:41
1  
Yes but if you have the same file in two different folders of your source, eg.source/bla/june.pdf and source/blubb/june.pdf and try to copy both to destination/, with cp -ar source/ destination/, cp will give you an error, when it gets to source/blubb/june.pfd, since destination/june.pdf will already exist then from when you copied source/bla/june.pdf to destination. –  con-f-use Aug 4 '12 at 9:46
    
it means that the find commands should also display all the files mentioned in the find pattern,but it is giving only the 3 files (1 copy each):- ankit@battlestar:/home/mount_150/studies$ find -iname "*.pdf" ./june.pdf ./cde.pdf ./abc.pdf –  Ankit Aug 4 '12 at 9:56
    
@Con-f-use, i'm sorry i got your point just today. Thanks. So the find command will also search in lcommands and while it is trying to copy it already finds a copy there.. thanks again > :) –  Ankit Aug 8 '12 at 0:14
add comment

2 Answers

It is an error (return code 1), from cp:

>>> cp foo foo
cp: `foo' and `foo' are the same file
<<< 11:33.40 Sat Aug 04 2012!~ 
1

Which means that cp did not do anything.

share|improve this answer
    
actually cp did copy the files to lcommand folder; as you could see in the screen shot. –  Ankit Aug 4 '12 at 9:37
add comment
up vote 0 down vote accepted

find command would also search in the lcommand directory for any instances of the pdf files. Since the files were copied the pdf files were copied to the directory; find came up with the warning.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.