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

前端 未结 5 577
孤独总比滥情好
孤独总比滥情好 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条回答
  •  Happy的楠姐
    2020-12-23 21:28

    If you are not using GNU mv, you can use that command:

    find . -depth -type d -mtime 0 -exec bash -c 'declare -a array;j=1;for i; do array[$j]="$i"; j=$((j+1));done; mv "${array[*]}" /path/to/target-dir' arg0 {} +
    

    otherwise, here is a simpler solution that doesn't require xargs:

    find . -depth -type d -mtime 0 -exec mv -t /path/to/target-dir {} +
    

    Note that I added -depth otherwise you'll have errors when both a directory and one of its subdirectory is to be processed.

提交回复
热议问题