Guarda la risposta di Stephane per il metodo migliore, dai un'occhiata alla mia risposta per motivi di non usare le soluzioni più ovvie (e motivi per cui non sono le più efficienti).
Puoi usare l' -Iopzione di xargs:
find /tmp/ -ctime -1 -name "x*" | xargs -I '{}' mv '{}' ~/play/
Che funziona in un meccanismo simile a finde {}. Vorrei anche citare il tuo -nameargomento (perché un file che inizia xnella presente directory verrebbe archiviato in un file e passato come argomento da trovare - il che non darà il comportamento previsto!).
Tuttavia, come sottolineato da manatwork, come dettagliato nella xargspagina man:
-I replace-str
Replace occurrences of replace-str in the initial-arguments with
names read from standard input. Also, unquoted blanks do not
terminate input items; instead the separator is the newline
character. Implies -x and -L 1.
La cosa importante da notare è che -L 1significa che verrà elaborata una sola riga di output findalla volta. Ciò significa che sintatticamente è lo stesso di:
find /tmp/ -ctime -1 -name "x*" -exec mv '{}' ~/play/
(che esegue una singola mvoperazione per ciascun file).
Anche usando l' -0argomento GNU xargs e l' find -print0argomento causa esattamente lo stesso comportamento di -I- questo è clone()un processo per ogni file mv:
find . -name "x*" -print0 | strace xargs -0 -I '{}' mv '{}' /tmp/other
.
.
read(0, "./foobar1/xorgslsala11\0./foobar1"..., 4096) = 870
mmap(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fbb82fad000
open("/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=26066, ...}) = 0
mmap(NULL, 26066, PROT_READ, MAP_SHARED, 3, 0) = 0x7fbb82fa6000
close(3) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fbb835af9d0) = 661
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 661
--- SIGCHLD (Child exited) @ 0 (0) ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fbb835af9d0) = 662
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 662
--- SIGCHLD (Child exited) @ 0 (0) ---
.
.
.
-I:find . | xargs -I'{}' mv '{}' ~/play/, ma come uomo dice, che “implica-xe-L 1”. Così nessun guadagno. Meglio tenerlo semplice e usarefind . -exec mv '{}' ~/play/ \;