mv: 'path1/path2/filename1' and '/home/user1/dir1/path1/path2/filename1' are the same file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















After using command:



find path1/ -iname 'file*[1234]' -exec mv -t /home/user1/dir1/path1/path2 ;


I got an error that those files are the same. The command finished successfully. The parent directory from where the search started is path1/ and then as destination directory I put whole absolut path where I want the files moved. Why did this happen?










share|improve this question




























    0















    After using command:



    find path1/ -iname 'file*[1234]' -exec mv -t /home/user1/dir1/path1/path2 ;


    I got an error that those files are the same. The command finished successfully. The parent directory from where the search started is path1/ and then as destination directory I put whole absolut path where I want the files moved. Why did this happen?










    share|improve this question


























      0












      0








      0








      After using command:



      find path1/ -iname 'file*[1234]' -exec mv -t /home/user1/dir1/path1/path2 ;


      I got an error that those files are the same. The command finished successfully. The parent directory from where the search started is path1/ and then as destination directory I put whole absolut path where I want the files moved. Why did this happen?










      share|improve this question
















      After using command:



      find path1/ -iname 'file*[1234]' -exec mv -t /home/user1/dir1/path1/path2 ;


      I got an error that those files are the same. The command finished successfully. The parent directory from where the search started is path1/ and then as destination directory I put whole absolut path where I want the files moved. Why did this happen?







      linux find command mv






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 24 at 21:42









      Stefan Hamcke

      217312




      217312










      asked Jan 24 at 20:45









      Miloš StojanovićMiloš Stojanović

      155




      155




















          1 Answer
          1






          active

          oldest

          votes


















          1














          What mv is saying is that it makes no sense to move the particular file as moving it to the destination would write it back to itself.



          You'll get the same thing if you try



          mv file file


          for any file called file.



          As to why this happens:



          You run find on the path path1. I'm assuming that this is the same path1 as in the absolute path /home/user1/dir1/path1/path2.



          If you have files in /home/user1/dir1/path1/path2 whose names matches the pattern that you use (these may have been moved there by an earlier invocation of your find command, or even by the same find due to the order of directory traversals that find makes), then these would be found by find (since path2 is a subdirectory of path1). This would prompt find to try to execute an mv command that would move files from path2 into path2. This is what triggers the message (I'm hesitating to call it an actual "error").



          To avoid looking into path2 with find, you may do this:



          find path1 ( -type d -path 'path1/path2' -prune ) -o -iname 'file*[1234]' -exec mv -t /home/user1/dir1/path1/path2 +


          If the thing found is a directory (-type d) and if it's the pathname path1/path2, then prune it from the directory search tree that find builds while traversing the directories. Otherwise, continue as before (almost, I changed the final ; to + to make mv take as many pathnames as possible at once).






          share|improve this answer

























          • I think the problem here is that there is a file matching the pattern in .../path2/ because another such file was moved to that target directory during the find command and the target directory is traversed after the directory the file originated from. If you have Afolder/file but no Bfolder/file and you do find -name file -exec mv -t Bfolder ;, you get the error, but if you have a Bfolder/file and no Afolder/file, then you don't.

            – Stefan Hamcke
            Jan 24 at 21:22











          • @StefanHamcke The error indicates that you are moving a file to itself. Not just that you are moving a file to another with the same name. The actual inode is the same when this message is outputted. Also, I think you got your two examples mixed up.

            – Kusalananda
            Jan 24 at 21:36












          • I know. I'm referring to your sentence "If you have files in /home/user1/dir1/path1/path2 ...". I think the OP did not originally have such files in the target dir, but they were moved there due to the command. Let me explain my example: Say you are in a dir with only Afolder/ and Bfolder/ and also Afolder/file (regular file), but nothing else. Then you do not even need a Bfolder/file for the message to appear when you execute find -name file -exec mv -t Bfolder ;.

            – Stefan Hamcke
            Jan 24 at 21:52











          • @StefanHamcke Ah, yes. It may depend on the order of traversal as well. If the destination directory is late in that order, files may already have started to accumulate there.

            – Kusalananda
            Jan 24 at 21:55











          • The above command will first descent into Afolder/, find the file, and move it to Bfolder/. After that, it will look into Bfolder/ and stumble upon the file it did just move there.

            – Stefan Hamcke
            Jan 24 at 21:56










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496547%2fmv-path1-path2-filename1-and-home-user1-dir1-path1-path2-filename1-are-the%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          What mv is saying is that it makes no sense to move the particular file as moving it to the destination would write it back to itself.



          You'll get the same thing if you try



          mv file file


          for any file called file.



          As to why this happens:



          You run find on the path path1. I'm assuming that this is the same path1 as in the absolute path /home/user1/dir1/path1/path2.



          If you have files in /home/user1/dir1/path1/path2 whose names matches the pattern that you use (these may have been moved there by an earlier invocation of your find command, or even by the same find due to the order of directory traversals that find makes), then these would be found by find (since path2 is a subdirectory of path1). This would prompt find to try to execute an mv command that would move files from path2 into path2. This is what triggers the message (I'm hesitating to call it an actual "error").



          To avoid looking into path2 with find, you may do this:



          find path1 ( -type d -path 'path1/path2' -prune ) -o -iname 'file*[1234]' -exec mv -t /home/user1/dir1/path1/path2 +


          If the thing found is a directory (-type d) and if it's the pathname path1/path2, then prune it from the directory search tree that find builds while traversing the directories. Otherwise, continue as before (almost, I changed the final ; to + to make mv take as many pathnames as possible at once).






          share|improve this answer

























          • I think the problem here is that there is a file matching the pattern in .../path2/ because another such file was moved to that target directory during the find command and the target directory is traversed after the directory the file originated from. If you have Afolder/file but no Bfolder/file and you do find -name file -exec mv -t Bfolder ;, you get the error, but if you have a Bfolder/file and no Afolder/file, then you don't.

            – Stefan Hamcke
            Jan 24 at 21:22











          • @StefanHamcke The error indicates that you are moving a file to itself. Not just that you are moving a file to another with the same name. The actual inode is the same when this message is outputted. Also, I think you got your two examples mixed up.

            – Kusalananda
            Jan 24 at 21:36












          • I know. I'm referring to your sentence "If you have files in /home/user1/dir1/path1/path2 ...". I think the OP did not originally have such files in the target dir, but they were moved there due to the command. Let me explain my example: Say you are in a dir with only Afolder/ and Bfolder/ and also Afolder/file (regular file), but nothing else. Then you do not even need a Bfolder/file for the message to appear when you execute find -name file -exec mv -t Bfolder ;.

            – Stefan Hamcke
            Jan 24 at 21:52











          • @StefanHamcke Ah, yes. It may depend on the order of traversal as well. If the destination directory is late in that order, files may already have started to accumulate there.

            – Kusalananda
            Jan 24 at 21:55











          • The above command will first descent into Afolder/, find the file, and move it to Bfolder/. After that, it will look into Bfolder/ and stumble upon the file it did just move there.

            – Stefan Hamcke
            Jan 24 at 21:56















          1














          What mv is saying is that it makes no sense to move the particular file as moving it to the destination would write it back to itself.



          You'll get the same thing if you try



          mv file file


          for any file called file.



          As to why this happens:



          You run find on the path path1. I'm assuming that this is the same path1 as in the absolute path /home/user1/dir1/path1/path2.



          If you have files in /home/user1/dir1/path1/path2 whose names matches the pattern that you use (these may have been moved there by an earlier invocation of your find command, or even by the same find due to the order of directory traversals that find makes), then these would be found by find (since path2 is a subdirectory of path1). This would prompt find to try to execute an mv command that would move files from path2 into path2. This is what triggers the message (I'm hesitating to call it an actual "error").



          To avoid looking into path2 with find, you may do this:



          find path1 ( -type d -path 'path1/path2' -prune ) -o -iname 'file*[1234]' -exec mv -t /home/user1/dir1/path1/path2 +


          If the thing found is a directory (-type d) and if it's the pathname path1/path2, then prune it from the directory search tree that find builds while traversing the directories. Otherwise, continue as before (almost, I changed the final ; to + to make mv take as many pathnames as possible at once).






          share|improve this answer

























          • I think the problem here is that there is a file matching the pattern in .../path2/ because another such file was moved to that target directory during the find command and the target directory is traversed after the directory the file originated from. If you have Afolder/file but no Bfolder/file and you do find -name file -exec mv -t Bfolder ;, you get the error, but if you have a Bfolder/file and no Afolder/file, then you don't.

            – Stefan Hamcke
            Jan 24 at 21:22











          • @StefanHamcke The error indicates that you are moving a file to itself. Not just that you are moving a file to another with the same name. The actual inode is the same when this message is outputted. Also, I think you got your two examples mixed up.

            – Kusalananda
            Jan 24 at 21:36












          • I know. I'm referring to your sentence "If you have files in /home/user1/dir1/path1/path2 ...". I think the OP did not originally have such files in the target dir, but they were moved there due to the command. Let me explain my example: Say you are in a dir with only Afolder/ and Bfolder/ and also Afolder/file (regular file), but nothing else. Then you do not even need a Bfolder/file for the message to appear when you execute find -name file -exec mv -t Bfolder ;.

            – Stefan Hamcke
            Jan 24 at 21:52











          • @StefanHamcke Ah, yes. It may depend on the order of traversal as well. If the destination directory is late in that order, files may already have started to accumulate there.

            – Kusalananda
            Jan 24 at 21:55











          • The above command will first descent into Afolder/, find the file, and move it to Bfolder/. After that, it will look into Bfolder/ and stumble upon the file it did just move there.

            – Stefan Hamcke
            Jan 24 at 21:56













          1












          1








          1







          What mv is saying is that it makes no sense to move the particular file as moving it to the destination would write it back to itself.



          You'll get the same thing if you try



          mv file file


          for any file called file.



          As to why this happens:



          You run find on the path path1. I'm assuming that this is the same path1 as in the absolute path /home/user1/dir1/path1/path2.



          If you have files in /home/user1/dir1/path1/path2 whose names matches the pattern that you use (these may have been moved there by an earlier invocation of your find command, or even by the same find due to the order of directory traversals that find makes), then these would be found by find (since path2 is a subdirectory of path1). This would prompt find to try to execute an mv command that would move files from path2 into path2. This is what triggers the message (I'm hesitating to call it an actual "error").



          To avoid looking into path2 with find, you may do this:



          find path1 ( -type d -path 'path1/path2' -prune ) -o -iname 'file*[1234]' -exec mv -t /home/user1/dir1/path1/path2 +


          If the thing found is a directory (-type d) and if it's the pathname path1/path2, then prune it from the directory search tree that find builds while traversing the directories. Otherwise, continue as before (almost, I changed the final ; to + to make mv take as many pathnames as possible at once).






          share|improve this answer















          What mv is saying is that it makes no sense to move the particular file as moving it to the destination would write it back to itself.



          You'll get the same thing if you try



          mv file file


          for any file called file.



          As to why this happens:



          You run find on the path path1. I'm assuming that this is the same path1 as in the absolute path /home/user1/dir1/path1/path2.



          If you have files in /home/user1/dir1/path1/path2 whose names matches the pattern that you use (these may have been moved there by an earlier invocation of your find command, or even by the same find due to the order of directory traversals that find makes), then these would be found by find (since path2 is a subdirectory of path1). This would prompt find to try to execute an mv command that would move files from path2 into path2. This is what triggers the message (I'm hesitating to call it an actual "error").



          To avoid looking into path2 with find, you may do this:



          find path1 ( -type d -path 'path1/path2' -prune ) -o -iname 'file*[1234]' -exec mv -t /home/user1/dir1/path1/path2 +


          If the thing found is a directory (-type d) and if it's the pathname path1/path2, then prune it from the directory search tree that find builds while traversing the directories. Otherwise, continue as before (almost, I changed the final ; to + to make mv take as many pathnames as possible at once).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 24 at 21:56

























          answered Jan 24 at 20:57









          KusalanandaKusalananda

          129k16245404




          129k16245404












          • I think the problem here is that there is a file matching the pattern in .../path2/ because another such file was moved to that target directory during the find command and the target directory is traversed after the directory the file originated from. If you have Afolder/file but no Bfolder/file and you do find -name file -exec mv -t Bfolder ;, you get the error, but if you have a Bfolder/file and no Afolder/file, then you don't.

            – Stefan Hamcke
            Jan 24 at 21:22











          • @StefanHamcke The error indicates that you are moving a file to itself. Not just that you are moving a file to another with the same name. The actual inode is the same when this message is outputted. Also, I think you got your two examples mixed up.

            – Kusalananda
            Jan 24 at 21:36












          • I know. I'm referring to your sentence "If you have files in /home/user1/dir1/path1/path2 ...". I think the OP did not originally have such files in the target dir, but they were moved there due to the command. Let me explain my example: Say you are in a dir with only Afolder/ and Bfolder/ and also Afolder/file (regular file), but nothing else. Then you do not even need a Bfolder/file for the message to appear when you execute find -name file -exec mv -t Bfolder ;.

            – Stefan Hamcke
            Jan 24 at 21:52











          • @StefanHamcke Ah, yes. It may depend on the order of traversal as well. If the destination directory is late in that order, files may already have started to accumulate there.

            – Kusalananda
            Jan 24 at 21:55











          • The above command will first descent into Afolder/, find the file, and move it to Bfolder/. After that, it will look into Bfolder/ and stumble upon the file it did just move there.

            – Stefan Hamcke
            Jan 24 at 21:56

















          • I think the problem here is that there is a file matching the pattern in .../path2/ because another such file was moved to that target directory during the find command and the target directory is traversed after the directory the file originated from. If you have Afolder/file but no Bfolder/file and you do find -name file -exec mv -t Bfolder ;, you get the error, but if you have a Bfolder/file and no Afolder/file, then you don't.

            – Stefan Hamcke
            Jan 24 at 21:22











          • @StefanHamcke The error indicates that you are moving a file to itself. Not just that you are moving a file to another with the same name. The actual inode is the same when this message is outputted. Also, I think you got your two examples mixed up.

            – Kusalananda
            Jan 24 at 21:36












          • I know. I'm referring to your sentence "If you have files in /home/user1/dir1/path1/path2 ...". I think the OP did not originally have such files in the target dir, but they were moved there due to the command. Let me explain my example: Say you are in a dir with only Afolder/ and Bfolder/ and also Afolder/file (regular file), but nothing else. Then you do not even need a Bfolder/file for the message to appear when you execute find -name file -exec mv -t Bfolder ;.

            – Stefan Hamcke
            Jan 24 at 21:52











          • @StefanHamcke Ah, yes. It may depend on the order of traversal as well. If the destination directory is late in that order, files may already have started to accumulate there.

            – Kusalananda
            Jan 24 at 21:55











          • The above command will first descent into Afolder/, find the file, and move it to Bfolder/. After that, it will look into Bfolder/ and stumble upon the file it did just move there.

            – Stefan Hamcke
            Jan 24 at 21:56
















          I think the problem here is that there is a file matching the pattern in .../path2/ because another such file was moved to that target directory during the find command and the target directory is traversed after the directory the file originated from. If you have Afolder/file but no Bfolder/file and you do find -name file -exec mv -t Bfolder ;, you get the error, but if you have a Bfolder/file and no Afolder/file, then you don't.

          – Stefan Hamcke
          Jan 24 at 21:22





          I think the problem here is that there is a file matching the pattern in .../path2/ because another such file was moved to that target directory during the find command and the target directory is traversed after the directory the file originated from. If you have Afolder/file but no Bfolder/file and you do find -name file -exec mv -t Bfolder ;, you get the error, but if you have a Bfolder/file and no Afolder/file, then you don't.

          – Stefan Hamcke
          Jan 24 at 21:22













          @StefanHamcke The error indicates that you are moving a file to itself. Not just that you are moving a file to another with the same name. The actual inode is the same when this message is outputted. Also, I think you got your two examples mixed up.

          – Kusalananda
          Jan 24 at 21:36






          @StefanHamcke The error indicates that you are moving a file to itself. Not just that you are moving a file to another with the same name. The actual inode is the same when this message is outputted. Also, I think you got your two examples mixed up.

          – Kusalananda
          Jan 24 at 21:36














          I know. I'm referring to your sentence "If you have files in /home/user1/dir1/path1/path2 ...". I think the OP did not originally have such files in the target dir, but they were moved there due to the command. Let me explain my example: Say you are in a dir with only Afolder/ and Bfolder/ and also Afolder/file (regular file), but nothing else. Then you do not even need a Bfolder/file for the message to appear when you execute find -name file -exec mv -t Bfolder ;.

          – Stefan Hamcke
          Jan 24 at 21:52





          I know. I'm referring to your sentence "If you have files in /home/user1/dir1/path1/path2 ...". I think the OP did not originally have such files in the target dir, but they were moved there due to the command. Let me explain my example: Say you are in a dir with only Afolder/ and Bfolder/ and also Afolder/file (regular file), but nothing else. Then you do not even need a Bfolder/file for the message to appear when you execute find -name file -exec mv -t Bfolder ;.

          – Stefan Hamcke
          Jan 24 at 21:52













          @StefanHamcke Ah, yes. It may depend on the order of traversal as well. If the destination directory is late in that order, files may already have started to accumulate there.

          – Kusalananda
          Jan 24 at 21:55





          @StefanHamcke Ah, yes. It may depend on the order of traversal as well. If the destination directory is late in that order, files may already have started to accumulate there.

          – Kusalananda
          Jan 24 at 21:55













          The above command will first descent into Afolder/, find the file, and move it to Bfolder/. After that, it will look into Bfolder/ and stumble upon the file it did just move there.

          – Stefan Hamcke
          Jan 24 at 21:56





          The above command will first descent into Afolder/, find the file, and move it to Bfolder/. After that, it will look into Bfolder/ and stumble upon the file it did just move there.

          – Stefan Hamcke
          Jan 24 at 21:56

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496547%2fmv-path1-path2-filename1-and-home-user1-dir1-path1-path2-filename1-are-the%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay