Use xargs to mv a directory to find results in another directory
source link: https://www.codesd.com/item/use-xargs-to-mv-a-directory-to-find-results-in-another-directory.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Use xargs to mv a directory to find results in another directory
I have the following command:
find . -type d -mtime 0 -exec mv {} /path/to/target-dir \;
This will move the directory founded to another directory. How can I use xargs
instead of exec
to do the same thing.
If you've got GNU mv
(and find
and xargs
), you can use the -t
option to mv
(and -print0
for find
and -0
for xargs
):
find . -type d -mtime -0 -print0 | xargs -0 mv -t /path/to/target-dir
Note that modern versions of find
(compatible with POSIX 2008) support +
in place of ;
and behave roughly the same as xargs
without using xargs
:
find . -type d -mtime -0 -exec mv -t /path/to/target-dir {} +
This makes find
group convenient numbers of file (directory) names into a single invocation of the program. You don't have the level of control over the numbers of arguments passed to mv
that xargs
provides, but you seldom actually need that anyway. This still hinges on the -t
option to GNU mv
.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK