11

Use xargs to mv a directory to find results in another directory

 3 years ago
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.
neoserver,ios ssh client

Use xargs to mv a directory to find results in another directory

advertisements

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK