Search code examples
bashunixshbranchmv

Script for moving all *.512.png to a new folder


Can you make a script(bash) for moving all the files with the ending *.512.png to a new folder like res512(will be new branch) (keeping all the subfolders) for this repo I tried really long but I can't figure it out.


Solution

  • You're not very specific with what you're asking.

    If you want to move all files that have the suffix .512.png from within your current directory to a new directory, you can use the following

    mkdir res512
    cp -r *.512.png res512/
    

    If you want to move all files that have the suffix .512.png from within your directory and all child directories into a new directory, you can use

    mkdir res512
    for f in $(find -type f -name "*.512.png")
    do 
        cp $f res512/
    done
    

    If you want to move all files that have the suffix .512.png including their directory structure into a new directory, you can use

    find . -name '*.512.png' -exec cp --parents \{\} res512/ \;
    

    Replace cp with mv if you want to move the files instead of copy them.