How to use 'mv' command to move files except those in a specific directory?

前端 未结 8 1675
夕颜
夕颜 2020-12-23 11:35

I am wondering - how can I move all the files in a directory except those files in a specific directory (as \'mv\' does not have a \'--exclude\' option)?

8条回答
  •  温柔的废话
    2020-12-23 12:12

    First get the names of files and folders and exclude whichever you want:

    ls --ignore=file1 --ignore==folder1 --ignore==regular-expression1 ...
    

    Then pass filtered names to mv as the first parameter and the second parameter will be the destination:

    mv $(ls --ignore=file1 --ignore==folder1 --ignore==regular-expression1 ...) destination/
    

提交回复
热议问题