mv: cannot stat 'filename_1_2_3': No such file or directory

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












0















I wanted to move large amount of files from many directories which are under the parent directory in who I'm positioned.



I used following command with backticks:



mv -t directory1/directory2/directory3/ `ls -R | grep _2_3`


So I wanted to move the source of command in backticks to the destination directory which is 'directory3' which are find Recursively under my current directory ( parent one )



Is there any solution to do this with the current command? And what does this error mean exactly?










share|improve this question




























    0















    I wanted to move large amount of files from many directories which are under the parent directory in who I'm positioned.



    I used following command with backticks:



    mv -t directory1/directory2/directory3/ `ls -R | grep _2_3`


    So I wanted to move the source of command in backticks to the destination directory which is 'directory3' which are find Recursively under my current directory ( parent one )



    Is there any solution to do this with the current command? And what does this error mean exactly?










    share|improve this question


























      0












      0








      0








      I wanted to move large amount of files from many directories which are under the parent directory in who I'm positioned.



      I used following command with backticks:



      mv -t directory1/directory2/directory3/ `ls -R | grep _2_3`


      So I wanted to move the source of command in backticks to the destination directory which is 'directory3' which are find Recursively under my current directory ( parent one )



      Is there any solution to do this with the current command? And what does this error mean exactly?










      share|improve this question
















      I wanted to move large amount of files from many directories which are under the parent directory in who I'm positioned.



      I used following command with backticks:



      mv -t directory1/directory2/directory3/ `ls -R | grep _2_3`


      So I wanted to move the source of command in backticks to the destination directory which is 'directory3' which are find Recursively under my current directory ( parent one )



      Is there any solution to do this with the current command? And what does this error mean exactly?







      linux command-line terminal mv






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 24 at 20:30









      Rui F Ribeiro

      40.1k1479136




      40.1k1479136










      asked Jan 24 at 20:05









      Miloš StojanovićMiloš Stojanović

      155




      155




















          2 Answers
          2






          active

          oldest

          votes


















          2














          You will notice that ls -R outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3 in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R (on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.



          Instead, assuming you'd want to move files whose filenames end in _2_3 to a directory /directory1/directory2/directory3 (and that this directory is not a subdirectory of the current directory), then



          find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +


          would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3 anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3 with as many of these pathnames as possible in batches.



          In the bash shell, you could possibly also do



          shopt -s globstar
          mv -t /directory1/directory2/directory3 **/*_2_3


          unless the pattern expands to many thousands of names. The globstar shell option in bash enables the ** globbing pattern. It works like * but will match across / in pathnames. It would therefore find all names matching *_2_3 anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R approach do).



          In the zsh shell, you could be more precise with the matching:



          mv -t /directory1/directory2/directory3 **/*_2_3(.)


          The (.) modifies the behaviour of the preceding pattern to only match regular files. The ** pattern is enabled by default in zsh.



          If you wish to find files whose names contain _2_3, then simply change the *_2_3 bit of the filename pattern in the above commands to *_2_3*.






          share|improve this answer
































            0














            The important part of the message is: No such file or directory. ls -R doesn't include the filepath. So mv have just the filename but cannot find it, because the path to it is missing.



            Do this instead:



            $ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +





            share|improve this answer






















              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%2f496541%2fmv-cannot-stat-filename-1-2-3-no-such-file-or-directory%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              You will notice that ls -R outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3 in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R (on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.



              Instead, assuming you'd want to move files whose filenames end in _2_3 to a directory /directory1/directory2/directory3 (and that this directory is not a subdirectory of the current directory), then



              find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +


              would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3 anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3 with as many of these pathnames as possible in batches.



              In the bash shell, you could possibly also do



              shopt -s globstar
              mv -t /directory1/directory2/directory3 **/*_2_3


              unless the pattern expands to many thousands of names. The globstar shell option in bash enables the ** globbing pattern. It works like * but will match across / in pathnames. It would therefore find all names matching *_2_3 anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R approach do).



              In the zsh shell, you could be more precise with the matching:



              mv -t /directory1/directory2/directory3 **/*_2_3(.)


              The (.) modifies the behaviour of the preceding pattern to only match regular files. The ** pattern is enabled by default in zsh.



              If you wish to find files whose names contain _2_3, then simply change the *_2_3 bit of the filename pattern in the above commands to *_2_3*.






              share|improve this answer





























                2














                You will notice that ls -R outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3 in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R (on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.



                Instead, assuming you'd want to move files whose filenames end in _2_3 to a directory /directory1/directory2/directory3 (and that this directory is not a subdirectory of the current directory), then



                find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +


                would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3 anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3 with as many of these pathnames as possible in batches.



                In the bash shell, you could possibly also do



                shopt -s globstar
                mv -t /directory1/directory2/directory3 **/*_2_3


                unless the pattern expands to many thousands of names. The globstar shell option in bash enables the ** globbing pattern. It works like * but will match across / in pathnames. It would therefore find all names matching *_2_3 anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R approach do).



                In the zsh shell, you could be more precise with the matching:



                mv -t /directory1/directory2/directory3 **/*_2_3(.)


                The (.) modifies the behaviour of the preceding pattern to only match regular files. The ** pattern is enabled by default in zsh.



                If you wish to find files whose names contain _2_3, then simply change the *_2_3 bit of the filename pattern in the above commands to *_2_3*.






                share|improve this answer



























                  2












                  2








                  2







                  You will notice that ls -R outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3 in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R (on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.



                  Instead, assuming you'd want to move files whose filenames end in _2_3 to a directory /directory1/directory2/directory3 (and that this directory is not a subdirectory of the current directory), then



                  find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +


                  would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3 anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3 with as many of these pathnames as possible in batches.



                  In the bash shell, you could possibly also do



                  shopt -s globstar
                  mv -t /directory1/directory2/directory3 **/*_2_3


                  unless the pattern expands to many thousands of names. The globstar shell option in bash enables the ** globbing pattern. It works like * but will match across / in pathnames. It would therefore find all names matching *_2_3 anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R approach do).



                  In the zsh shell, you could be more precise with the matching:



                  mv -t /directory1/directory2/directory3 **/*_2_3(.)


                  The (.) modifies the behaviour of the preceding pattern to only match regular files. The ** pattern is enabled by default in zsh.



                  If you wish to find files whose names contain _2_3, then simply change the *_2_3 bit of the filename pattern in the above commands to *_2_3*.






                  share|improve this answer















                  You will notice that ls -R outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3 in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R (on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.



                  Instead, assuming you'd want to move files whose filenames end in _2_3 to a directory /directory1/directory2/directory3 (and that this directory is not a subdirectory of the current directory), then



                  find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +


                  would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3 anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3 with as many of these pathnames as possible in batches.



                  In the bash shell, you could possibly also do



                  shopt -s globstar
                  mv -t /directory1/directory2/directory3 **/*_2_3


                  unless the pattern expands to many thousands of names. The globstar shell option in bash enables the ** globbing pattern. It works like * but will match across / in pathnames. It would therefore find all names matching *_2_3 anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R approach do).



                  In the zsh shell, you could be more precise with the matching:



                  mv -t /directory1/directory2/directory3 **/*_2_3(.)


                  The (.) modifies the behaviour of the preceding pattern to only match regular files. The ** pattern is enabled by default in zsh.



                  If you wish to find files whose names contain _2_3, then simply change the *_2_3 bit of the filename pattern in the above commands to *_2_3*.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 24 at 20:51

























                  answered Jan 24 at 20:17









                  KusalanandaKusalananda

                  129k16245404




                  129k16245404























                      0














                      The important part of the message is: No such file or directory. ls -R doesn't include the filepath. So mv have just the filename but cannot find it, because the path to it is missing.



                      Do this instead:



                      $ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +





                      share|improve this answer



























                        0














                        The important part of the message is: No such file or directory. ls -R doesn't include the filepath. So mv have just the filename but cannot find it, because the path to it is missing.



                        Do this instead:



                        $ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +





                        share|improve this answer

























                          0












                          0








                          0







                          The important part of the message is: No such file or directory. ls -R doesn't include the filepath. So mv have just the filename but cannot find it, because the path to it is missing.



                          Do this instead:



                          $ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +





                          share|improve this answer













                          The important part of the message is: No such file or directory. ls -R doesn't include the filepath. So mv have just the filename but cannot find it, because the path to it is missing.



                          Do this instead:



                          $ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 24 at 20:19









                          finswimmerfinswimmer

                          52416




                          52416



























                              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%2f496541%2fmv-cannot-stat-filename-1-2-3-no-such-file-or-directory%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