Cut file by name in bash [closed]












-1















I have a folder with thousand of images, and I need to cut all the images with a 'F' as a third letter in the filename in another folder. Is there a way to write a bash code to do that? Or how can I do?










share|improve this question













closed as too broad by F. Hauri, l'L'l, chepner, miken32, jww Nov 16 '18 at 1:15


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.























    -1















    I have a folder with thousand of images, and I need to cut all the images with a 'F' as a third letter in the filename in another folder. Is there a way to write a bash code to do that? Or how can I do?










    share|improve this question













    closed as too broad by F. Hauri, l'L'l, chepner, miken32, jww Nov 16 '18 at 1:15


    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.





















      -1












      -1








      -1








      I have a folder with thousand of images, and I need to cut all the images with a 'F' as a third letter in the filename in another folder. Is there a way to write a bash code to do that? Or how can I do?










      share|improve this question














      I have a folder with thousand of images, and I need to cut all the images with a 'F' as a third letter in the filename in another folder. Is there a way to write a bash code to do that? Or how can I do?







      linux bash shell folder cut






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 16:00









      user254087user254087

      274




      274




      closed as too broad by F. Hauri, l'L'l, chepner, miken32, jww Nov 16 '18 at 1:15


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









      closed as too broad by F. Hauri, l'L'l, chepner, miken32, jww Nov 16 '18 at 1:15


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


























          3 Answers
          3






          active

          oldest

          votes


















          2














          Isn't that simply a matter of using globs:



          mv source_folder/??F* destination_folder


          man bash:




          Pattern Matching



          Any character that appears in a pattern, other than the special pattern characters described below, matches itself. The NUL character may not occur in a pattern. A backslash escapes the following character; the escaping backslash is discarded when matching. The special pattern characters must be quoted if they are to be matched literally.



          The special pattern characters have the following meanings:



          *

          Matches any string, including the null string. When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /, two adjacent *s will match only directories and subdirectories.



          ?



          Matches any single character.







          share|improve this answer































            1














            If there are enough of them the command might overwhelm the interpreter, especially on older systems. I've had old ksh shells puke when a command went over 1kb. You might need to use a more complex construction.



            find source_folder -name '??F*' -maxdepth 1 | 
            xargs -IF mv F destination_folder


            Alternate syntax, probably a lot more efficient -



            find source_folder -name '??F*' -maxdepth 1 | 
            xargs mv -t destination_folder


            But if possible for you, simple is better. Try Sam's solution first.



            Good luck.






            share|improve this answer





















            • 1





              Good point. btw: The mv -t syntax comes in handy with xargs: xargs mv -t destination_folder

              – Samuel Kirschner
              Nov 15 '18 at 16:30











            • Excellent point!

              – Paul Hodges
              Nov 15 '18 at 16:39



















            0














            Create a .sh file (for example, script.sh) and put the code:



            #!/bin/bash
            letter_order=3 # Third
            search_letter="F" # Find the letter F

            for file in *; do
            if [ "${file:$letter_order-1:1}" == "$search_letter" ]; then
            mv ${file} myNewFolderName/
            printf '%sn' "${file}"
            fi
            done


            So, just run the script '$ ./script.sh'






            share|improve this answer






























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              Isn't that simply a matter of using globs:



              mv source_folder/??F* destination_folder


              man bash:




              Pattern Matching



              Any character that appears in a pattern, other than the special pattern characters described below, matches itself. The NUL character may not occur in a pattern. A backslash escapes the following character; the escaping backslash is discarded when matching. The special pattern characters must be quoted if they are to be matched literally.



              The special pattern characters have the following meanings:



              *

              Matches any string, including the null string. When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /, two adjacent *s will match only directories and subdirectories.



              ?



              Matches any single character.







              share|improve this answer




























                2














                Isn't that simply a matter of using globs:



                mv source_folder/??F* destination_folder


                man bash:




                Pattern Matching



                Any character that appears in a pattern, other than the special pattern characters described below, matches itself. The NUL character may not occur in a pattern. A backslash escapes the following character; the escaping backslash is discarded when matching. The special pattern characters must be quoted if they are to be matched literally.



                The special pattern characters have the following meanings:



                *

                Matches any string, including the null string. When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /, two adjacent *s will match only directories and subdirectories.



                ?



                Matches any single character.







                share|improve this answer


























                  2












                  2








                  2







                  Isn't that simply a matter of using globs:



                  mv source_folder/??F* destination_folder


                  man bash:




                  Pattern Matching



                  Any character that appears in a pattern, other than the special pattern characters described below, matches itself. The NUL character may not occur in a pattern. A backslash escapes the following character; the escaping backslash is discarded when matching. The special pattern characters must be quoted if they are to be matched literally.



                  The special pattern characters have the following meanings:



                  *

                  Matches any string, including the null string. When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /, two adjacent *s will match only directories and subdirectories.



                  ?



                  Matches any single character.







                  share|improve this answer













                  Isn't that simply a matter of using globs:



                  mv source_folder/??F* destination_folder


                  man bash:




                  Pattern Matching



                  Any character that appears in a pattern, other than the special pattern characters described below, matches itself. The NUL character may not occur in a pattern. A backslash escapes the following character; the escaping backslash is discarded when matching. The special pattern characters must be quoted if they are to be matched literally.



                  The special pattern characters have the following meanings:



                  *

                  Matches any string, including the null string. When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /, two adjacent *s will match only directories and subdirectories.



                  ?



                  Matches any single character.








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 16:07









                  Samuel KirschnerSamuel Kirschner

                  9351717




                  9351717

























                      1














                      If there are enough of them the command might overwhelm the interpreter, especially on older systems. I've had old ksh shells puke when a command went over 1kb. You might need to use a more complex construction.



                      find source_folder -name '??F*' -maxdepth 1 | 
                      xargs -IF mv F destination_folder


                      Alternate syntax, probably a lot more efficient -



                      find source_folder -name '??F*' -maxdepth 1 | 
                      xargs mv -t destination_folder


                      But if possible for you, simple is better. Try Sam's solution first.



                      Good luck.






                      share|improve this answer





















                      • 1





                        Good point. btw: The mv -t syntax comes in handy with xargs: xargs mv -t destination_folder

                        – Samuel Kirschner
                        Nov 15 '18 at 16:30











                      • Excellent point!

                        – Paul Hodges
                        Nov 15 '18 at 16:39
















                      1














                      If there are enough of them the command might overwhelm the interpreter, especially on older systems. I've had old ksh shells puke when a command went over 1kb. You might need to use a more complex construction.



                      find source_folder -name '??F*' -maxdepth 1 | 
                      xargs -IF mv F destination_folder


                      Alternate syntax, probably a lot more efficient -



                      find source_folder -name '??F*' -maxdepth 1 | 
                      xargs mv -t destination_folder


                      But if possible for you, simple is better. Try Sam's solution first.



                      Good luck.






                      share|improve this answer





















                      • 1





                        Good point. btw: The mv -t syntax comes in handy with xargs: xargs mv -t destination_folder

                        – Samuel Kirschner
                        Nov 15 '18 at 16:30











                      • Excellent point!

                        – Paul Hodges
                        Nov 15 '18 at 16:39














                      1












                      1








                      1







                      If there are enough of them the command might overwhelm the interpreter, especially on older systems. I've had old ksh shells puke when a command went over 1kb. You might need to use a more complex construction.



                      find source_folder -name '??F*' -maxdepth 1 | 
                      xargs -IF mv F destination_folder


                      Alternate syntax, probably a lot more efficient -



                      find source_folder -name '??F*' -maxdepth 1 | 
                      xargs mv -t destination_folder


                      But if possible for you, simple is better. Try Sam's solution first.



                      Good luck.






                      share|improve this answer















                      If there are enough of them the command might overwhelm the interpreter, especially on older systems. I've had old ksh shells puke when a command went over 1kb. You might need to use a more complex construction.



                      find source_folder -name '??F*' -maxdepth 1 | 
                      xargs -IF mv F destination_folder


                      Alternate syntax, probably a lot more efficient -



                      find source_folder -name '??F*' -maxdepth 1 | 
                      xargs mv -t destination_folder


                      But if possible for you, simple is better. Try Sam's solution first.



                      Good luck.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 15 '18 at 16:47

























                      answered Nov 15 '18 at 16:25









                      Paul HodgesPaul Hodges

                      3,5151423




                      3,5151423








                      • 1





                        Good point. btw: The mv -t syntax comes in handy with xargs: xargs mv -t destination_folder

                        – Samuel Kirschner
                        Nov 15 '18 at 16:30











                      • Excellent point!

                        – Paul Hodges
                        Nov 15 '18 at 16:39














                      • 1





                        Good point. btw: The mv -t syntax comes in handy with xargs: xargs mv -t destination_folder

                        – Samuel Kirschner
                        Nov 15 '18 at 16:30











                      • Excellent point!

                        – Paul Hodges
                        Nov 15 '18 at 16:39








                      1




                      1





                      Good point. btw: The mv -t syntax comes in handy with xargs: xargs mv -t destination_folder

                      – Samuel Kirschner
                      Nov 15 '18 at 16:30





                      Good point. btw: The mv -t syntax comes in handy with xargs: xargs mv -t destination_folder

                      – Samuel Kirschner
                      Nov 15 '18 at 16:30













                      Excellent point!

                      – Paul Hodges
                      Nov 15 '18 at 16:39





                      Excellent point!

                      – Paul Hodges
                      Nov 15 '18 at 16:39











                      0














                      Create a .sh file (for example, script.sh) and put the code:



                      #!/bin/bash
                      letter_order=3 # Third
                      search_letter="F" # Find the letter F

                      for file in *; do
                      if [ "${file:$letter_order-1:1}" == "$search_letter" ]; then
                      mv ${file} myNewFolderName/
                      printf '%sn' "${file}"
                      fi
                      done


                      So, just run the script '$ ./script.sh'






                      share|improve this answer




























                        0














                        Create a .sh file (for example, script.sh) and put the code:



                        #!/bin/bash
                        letter_order=3 # Third
                        search_letter="F" # Find the letter F

                        for file in *; do
                        if [ "${file:$letter_order-1:1}" == "$search_letter" ]; then
                        mv ${file} myNewFolderName/
                        printf '%sn' "${file}"
                        fi
                        done


                        So, just run the script '$ ./script.sh'






                        share|improve this answer


























                          0












                          0








                          0







                          Create a .sh file (for example, script.sh) and put the code:



                          #!/bin/bash
                          letter_order=3 # Third
                          search_letter="F" # Find the letter F

                          for file in *; do
                          if [ "${file:$letter_order-1:1}" == "$search_letter" ]; then
                          mv ${file} myNewFolderName/
                          printf '%sn' "${file}"
                          fi
                          done


                          So, just run the script '$ ./script.sh'






                          share|improve this answer













                          Create a .sh file (for example, script.sh) and put the code:



                          #!/bin/bash
                          letter_order=3 # Third
                          search_letter="F" # Find the letter F

                          for file in *; do
                          if [ "${file:$letter_order-1:1}" == "$search_letter" ]; then
                          mv ${file} myNewFolderName/
                          printf '%sn' "${file}"
                          fi
                          done


                          So, just run the script '$ ./script.sh'







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 15 '18 at 16:20









                          Renan PortoRenan Porto

                          318




                          318















                              Popular posts from this blog

                              Bressuire

                              Vorschmack

                              Quarantine