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

前端 未结 8 1677
夕颜
夕颜 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 11:47

    This isn't exactly what you asked for, but it might do the job:

    mv the-folder-you-want-to-exclude somewhere-outside-of-the-main-tree
    mv the-tree where-you-want-it
    mv the-excluded-folder original-location
    

    (Essentially, move the excluded folder out of the larger tree to be moved.)

    So, if I have a/ and I want to exclude a/b/c/*:

    mv a/b/c ../c
    mv a final_destination
    mkdir -p a/b
    mv ../c a/b/c
    

    Or something like that. Otherwise, you might be able to get find to help you.

提交回复
热议问题