Use xargs to mv a directory from find results into another directory

前端 未结 5 588
孤独总比滥情好
孤独总比滥情好 2020-12-23 20:54

I have the following command:

find . -type d -mtime 0 -exec mv {} /path/to/target-dir \\;

This will move the directory founded to another

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 21:21

    find is not really a good tool for this. I imagine you want to move all subdirectories into another directory. find will output things like

    ./a
    ./a/b
    ./a/b/c
    ./a/b/c/d
    

    After ./a gets moved first, you'll just get errors about 'no such file or directory' all the subdirs.

    You should just use mv */ /another/place -- the trailing slash on the wildcard restricts the expansion to only dirs.

提交回复
热议问题