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

前端 未结 5 581
孤独总比滥情好
孤独总比滥情好 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 21:15

    With BSD xargs (for OS X and FreeBSD), you can use -J which was built for this:

    find . -name some_pattern -print0 | xargs -0 -J % mv % target_location
    

    That would move anything matching some_pattern in . to target_location

    With GNU xargs (for Linux and Cygwin), use -I instead:

    find . -name some_pattern -print0 | xargs -0 -I % mv % target_location
    

    The deprecated -i option of GNU xargs implies -I{} and can be used as follows:

    find . -name some_pattern -print0 | xargs -0 -i mv {} target_location
    

    Note that BSD xargs also has a -I option, but that does something else.

提交回复
热议问题