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

前端 未结 8 1681
夕颜
夕颜 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

    Since find does have an exclude option, use find + xargs + mv:

    find /source/directory -name ignore-directory-name -prune -print0 | xargs -0 mv --target-directory=/target/directory
    

    Note that this is almost copied from the find man page (I think using mv --target-directory is better than cpio).

提交回复
热议问题