Moving files to a directory

前端 未结 6 2086
长发绾君心
长发绾君心 2020-12-16 20:13

I want to move all files matching a certain pattern in the current directory to another directory.

For example, how would I move all the files starting with

相关标签:
6条回答
  • 2020-12-16 20:53

    mv nz* foobar/

    • mv - will move or rename file
    • nz - will get all the items that start with the "nz"
    • foobar/ - is the directory where all items will go into
    0 讨论(0)
  • 2020-12-16 20:57

    This will do it, though if you have any directories beginning with nz it will move those too.

    for files in nz*
    do
    mv $files foobar
    done
    

    Edit: As shown above this totally over the top. However, for more complex pattern matches you might do something like:

    for files in `ls | grep [regexp]`
    do
    mv $files foobar
    done
    
    0 讨论(0)
  • 2020-12-16 21:01

    mv nz* foobar should do it.

    0 讨论(0)
  • 2020-12-16 21:06

    mv nz* foobar/

    0 讨论(0)
  • 2020-12-16 21:12

    Try to use "mmv", which is installed on most Linux distros.

    0 讨论(0)
  • 2020-12-16 21:19
    find . | grep "your_pattern" | xargs mv destination_directory
    

    Does the following:

    • Finds all files in the current directory
    • Filters them according to your pattern
    • Moves all resulting files to the destination directory
    0 讨论(0)
提交回复
热议问题