How can I find files and then use xargs to move them?2019 Community Moderator ElectionHow to tell xargs which argument to choose ?How to use scp with xargs?Make xargs pass as first parameterfind and remove files bigger than a specific size and typeFind pattern and movelist all files newer than given timestamp and sort themFind pattern and moveUse xargs to move files from within a directoryMakes it a difference whether I use a different -n flag value for xargs in combination with find command ?copy files with md5-based target name using find and xargsFind all tar.gz files and move them to a one level down directoryFind fullpath and filename under a directory then pass to an executable file as argumentsHow to find all files of type and move them to a another_dir/dir_files_are_at/file?How to find specific file types and tar them?find files and move them to another folder with -exec

Accepted offer letter, position changed

Grey hair or white hair

Doesn't allowing a user mode program to access kernel space memory and execute the IN and OUT instructions defeat the purpose of having CPU modes?

Does "variables should live in the smallest scope as possible" include the case "variables should not exist if possible"?

Filtering SOQL results with optional conditionals

Signed and unsigned numbers

What's the "normal" opposite of flautando?

Latex does not go to next line

Is it necessary to separate DC power cables and data cables?

Recommendation letter by significant other if you worked with them professionally?

Why the color red for the Republican Party

Do f-stop and exposure time perfectly cancel?

Why was Goose renamed from Chewie for the Captain Marvel film?

Are tamper resistant receptacles really safer?

Does the nature of the Apocalypse in The Umbrella Academy change from the first to the last episode?

UART pins to unpowered MCU?

Reverse string, can I make it faster?

How to draw cubes in a 3 dimensional plane

Bash script should only kill those instances of another script's that it has launched

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

Should I tell my boss the work he did was worthless

Motivation for Zeta Function of an Algebraic Variety

Word for a person who has no opinion about whether god exists

Am I not good enough for you?



How can I find files and then use xargs to move them?



2019 Community Moderator ElectionHow to tell xargs which argument to choose ?How to use scp with xargs?Make xargs pass as first parameterfind and remove files bigger than a specific size and typeFind pattern and movelist all files newer than given timestamp and sort themFind pattern and moveUse xargs to move files from within a directoryMakes it a difference whether I use a different -n flag value for xargs in combination with find command ?copy files with md5-based target name using find and xargsFind all tar.gz files and move them to a one level down directoryFind fullpath and filename under a directory then pass to an executable file as argumentsHow to find all files of type and move them to a another_dir/dir_files_are_at/file?How to find specific file types and tar them?find files and move them to another folder with -exec










25















I want to find some files and then move them.



I can find the file with:



$ find /tmp/ -ctime -1 -name x*


I tried to move them to my ~/play directory with:



$ find /tmp/ -ctime -1 -name x* | xargs mv ~/play/


but that didn't work. Obviously mv needs two arguments.

Not sure if (or how) to reference the xargs 'current item' in the mv command?










share|improve this question

















  • 3





    Why? You can use placeholder with -I: find . | xargs -I'' mv '' ~/play/, but as man says, that “Implies -x and -L 1.” So no gain. Better keep it simple and use find . -exec mv '' ~/play/ ;

    – manatwork
    Sep 16 '13 at 14:17












  • Please post as answer to see votes if you wouldn't mind :)

    – Michael Durrant
    Sep 16 '13 at 14:21











  • Just asked for your reason, as I had the feeling I didn't got the point. If Drav Sloan adds the note on the implied options, his answer will be as good as the best I could write. So better go with that.

    – manatwork
    Sep 16 '13 at 14:28











  • possible duplicate of Find pattern and move

    – slm
    Sep 16 '13 at 14:39











  • @manatwork I've edited my answer to reflect those points duder :)

    – Drav Sloan
    Sep 16 '13 at 14:46















25















I want to find some files and then move them.



I can find the file with:



$ find /tmp/ -ctime -1 -name x*


I tried to move them to my ~/play directory with:



$ find /tmp/ -ctime -1 -name x* | xargs mv ~/play/


but that didn't work. Obviously mv needs two arguments.

Not sure if (or how) to reference the xargs 'current item' in the mv command?










share|improve this question

















  • 3





    Why? You can use placeholder with -I: find . | xargs -I'' mv '' ~/play/, but as man says, that “Implies -x and -L 1.” So no gain. Better keep it simple and use find . -exec mv '' ~/play/ ;

    – manatwork
    Sep 16 '13 at 14:17












  • Please post as answer to see votes if you wouldn't mind :)

    – Michael Durrant
    Sep 16 '13 at 14:21











  • Just asked for your reason, as I had the feeling I didn't got the point. If Drav Sloan adds the note on the implied options, his answer will be as good as the best I could write. So better go with that.

    – manatwork
    Sep 16 '13 at 14:28











  • possible duplicate of Find pattern and move

    – slm
    Sep 16 '13 at 14:39











  • @manatwork I've edited my answer to reflect those points duder :)

    – Drav Sloan
    Sep 16 '13 at 14:46













25












25








25


11






I want to find some files and then move them.



I can find the file with:



$ find /tmp/ -ctime -1 -name x*


I tried to move them to my ~/play directory with:



$ find /tmp/ -ctime -1 -name x* | xargs mv ~/play/


but that didn't work. Obviously mv needs two arguments.

Not sure if (or how) to reference the xargs 'current item' in the mv command?










share|improve this question














I want to find some files and then move them.



I can find the file with:



$ find /tmp/ -ctime -1 -name x*


I tried to move them to my ~/play directory with:



$ find /tmp/ -ctime -1 -name x* | xargs mv ~/play/


but that didn't work. Obviously mv needs two arguments.

Not sure if (or how) to reference the xargs 'current item' in the mv command?







find rename xargs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 16 '13 at 14:12









Michael DurrantMichael Durrant

16.3k44121184




16.3k44121184







  • 3





    Why? You can use placeholder with -I: find . | xargs -I'' mv '' ~/play/, but as man says, that “Implies -x and -L 1.” So no gain. Better keep it simple and use find . -exec mv '' ~/play/ ;

    – manatwork
    Sep 16 '13 at 14:17












  • Please post as answer to see votes if you wouldn't mind :)

    – Michael Durrant
    Sep 16 '13 at 14:21











  • Just asked for your reason, as I had the feeling I didn't got the point. If Drav Sloan adds the note on the implied options, his answer will be as good as the best I could write. So better go with that.

    – manatwork
    Sep 16 '13 at 14:28











  • possible duplicate of Find pattern and move

    – slm
    Sep 16 '13 at 14:39











  • @manatwork I've edited my answer to reflect those points duder :)

    – Drav Sloan
    Sep 16 '13 at 14:46












  • 3





    Why? You can use placeholder with -I: find . | xargs -I'' mv '' ~/play/, but as man says, that “Implies -x and -L 1.” So no gain. Better keep it simple and use find . -exec mv '' ~/play/ ;

    – manatwork
    Sep 16 '13 at 14:17












  • Please post as answer to see votes if you wouldn't mind :)

    – Michael Durrant
    Sep 16 '13 at 14:21











  • Just asked for your reason, as I had the feeling I didn't got the point. If Drav Sloan adds the note on the implied options, his answer will be as good as the best I could write. So better go with that.

    – manatwork
    Sep 16 '13 at 14:28











  • possible duplicate of Find pattern and move

    – slm
    Sep 16 '13 at 14:39











  • @manatwork I've edited my answer to reflect those points duder :)

    – Drav Sloan
    Sep 16 '13 at 14:46







3




3





Why? You can use placeholder with -I: find . | xargs -I'' mv '' ~/play/, but as man says, that “Implies -x and -L 1.” So no gain. Better keep it simple and use find . -exec mv '' ~/play/ ;

– manatwork
Sep 16 '13 at 14:17






Why? You can use placeholder with -I: find . | xargs -I'' mv '' ~/play/, but as man says, that “Implies -x and -L 1.” So no gain. Better keep it simple and use find . -exec mv '' ~/play/ ;

– manatwork
Sep 16 '13 at 14:17














Please post as answer to see votes if you wouldn't mind :)

– Michael Durrant
Sep 16 '13 at 14:21





Please post as answer to see votes if you wouldn't mind :)

– Michael Durrant
Sep 16 '13 at 14:21













Just asked for your reason, as I had the feeling I didn't got the point. If Drav Sloan adds the note on the implied options, his answer will be as good as the best I could write. So better go with that.

– manatwork
Sep 16 '13 at 14:28





Just asked for your reason, as I had the feeling I didn't got the point. If Drav Sloan adds the note on the implied options, his answer will be as good as the best I could write. So better go with that.

– manatwork
Sep 16 '13 at 14:28













possible duplicate of Find pattern and move

– slm
Sep 16 '13 at 14:39





possible duplicate of Find pattern and move

– slm
Sep 16 '13 at 14:39













@manatwork I've edited my answer to reflect those points duder :)

– Drav Sloan
Sep 16 '13 at 14:46





@manatwork I've edited my answer to reflect those points duder :)

– Drav Sloan
Sep 16 '13 at 14:46










3 Answers
3






active

oldest

votes


















38














Look at Stephane's answer for the best method, take a look at my answer for reasons not to use the more obvious solutions (and reasons why they are not the most efficient).



You can use the -I option of xargs:



find /tmp/ -ctime -1 -name "x*" | xargs -I '' mv '' ~/play/


Which works in a similar mechanism to find and . I would also quote your -name argument (because a file starting with x in the present directory would be file-globed and passed as an argument to find - which will not give the expected behavior!).



However, as pointed out by manatwork, as detailed in the xargs man page:



 -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.


The important thing to note is that -L 1 means that only one line of output from find will be processed at a time. This means that's syntactically the same as:



find /tmp/ -ctime -1 -name "x*" -exec mv '' ~/play/


(which executes a single mv operation for each file).



Even using the GNU -0 xargs argument and the find -print0 argument causes exactly the same behavior of -I - this is to clone() a process for each file mv:



find . -name "x*" -print0 | strace xargs -0 -I '' mv '' /tmp/other

.
.
read(0, "./foobar1/xorgslsala11./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, 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) ---
.
.
.





share|improve this answer

























  • That assumes file names don't contain newline, single quote, double quote or backslash characters.

    – Stéphane Chazelas
    Sep 16 '13 at 15:31


















15














With GNU tools:



find /tmp/ -ctime -1 -name 'x*' -print0 |
xargs -r0 mv -t ~/play/


The -t (--target) option is GNU specific. -print0, -r, -0, while non-standard and originating in GNU are also found in some other implementations like on some BSDs.



POSIXly:



find /tmp/ -ctime -1 -name 'x*' -exec sh -c '
exec mv "$@" ~/play/' sh +


Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.



Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.






share|improve this answer

























  • This solution is much better performing, since it calls mv once for all arguments (or for all of -L or -n, if supplied). Otherwise, calling mv for each file will get old (and slow) fast.

    – r2evans
    Feb 12 '18 at 21:25


















0














Perhaps this command is possible now and wasn't back in 2013, but this works perfectly for me:



ls pattern* | xargs mv -t DESTINATION/


The -t key puts the destination folder first, freeing up mv command to have all last arguments as just the files to be moved.






share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f90886%2fhow-can-i-find-files-and-then-use-xargs-to-move-them%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    38














    Look at Stephane's answer for the best method, take a look at my answer for reasons not to use the more obvious solutions (and reasons why they are not the most efficient).



    You can use the -I option of xargs:



    find /tmp/ -ctime -1 -name "x*" | xargs -I '' mv '' ~/play/


    Which works in a similar mechanism to find and . I would also quote your -name argument (because a file starting with x in the present directory would be file-globed and passed as an argument to find - which will not give the expected behavior!).



    However, as pointed out by manatwork, as detailed in the xargs man page:



     -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.


    The important thing to note is that -L 1 means that only one line of output from find will be processed at a time. This means that's syntactically the same as:



    find /tmp/ -ctime -1 -name "x*" -exec mv '' ~/play/


    (which executes a single mv operation for each file).



    Even using the GNU -0 xargs argument and the find -print0 argument causes exactly the same behavior of -I - this is to clone() a process for each file mv:



    find . -name "x*" -print0 | strace xargs -0 -I '' mv '' /tmp/other

    .
    .
    read(0, "./foobar1/xorgslsala11./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, 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) ---
    .
    .
    .





    share|improve this answer

























    • That assumes file names don't contain newline, single quote, double quote or backslash characters.

      – Stéphane Chazelas
      Sep 16 '13 at 15:31















    38














    Look at Stephane's answer for the best method, take a look at my answer for reasons not to use the more obvious solutions (and reasons why they are not the most efficient).



    You can use the -I option of xargs:



    find /tmp/ -ctime -1 -name "x*" | xargs -I '' mv '' ~/play/


    Which works in a similar mechanism to find and . I would also quote your -name argument (because a file starting with x in the present directory would be file-globed and passed as an argument to find - which will not give the expected behavior!).



    However, as pointed out by manatwork, as detailed in the xargs man page:



     -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.


    The important thing to note is that -L 1 means that only one line of output from find will be processed at a time. This means that's syntactically the same as:



    find /tmp/ -ctime -1 -name "x*" -exec mv '' ~/play/


    (which executes a single mv operation for each file).



    Even using the GNU -0 xargs argument and the find -print0 argument causes exactly the same behavior of -I - this is to clone() a process for each file mv:



    find . -name "x*" -print0 | strace xargs -0 -I '' mv '' /tmp/other

    .
    .
    read(0, "./foobar1/xorgslsala11./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, 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) ---
    .
    .
    .





    share|improve this answer

























    • That assumes file names don't contain newline, single quote, double quote or backslash characters.

      – Stéphane Chazelas
      Sep 16 '13 at 15:31













    38












    38








    38







    Look at Stephane's answer for the best method, take a look at my answer for reasons not to use the more obvious solutions (and reasons why they are not the most efficient).



    You can use the -I option of xargs:



    find /tmp/ -ctime -1 -name "x*" | xargs -I '' mv '' ~/play/


    Which works in a similar mechanism to find and . I would also quote your -name argument (because a file starting with x in the present directory would be file-globed and passed as an argument to find - which will not give the expected behavior!).



    However, as pointed out by manatwork, as detailed in the xargs man page:



     -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.


    The important thing to note is that -L 1 means that only one line of output from find will be processed at a time. This means that's syntactically the same as:



    find /tmp/ -ctime -1 -name "x*" -exec mv '' ~/play/


    (which executes a single mv operation for each file).



    Even using the GNU -0 xargs argument and the find -print0 argument causes exactly the same behavior of -I - this is to clone() a process for each file mv:



    find . -name "x*" -print0 | strace xargs -0 -I '' mv '' /tmp/other

    .
    .
    read(0, "./foobar1/xorgslsala11./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, 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) ---
    .
    .
    .





    share|improve this answer















    Look at Stephane's answer for the best method, take a look at my answer for reasons not to use the more obvious solutions (and reasons why they are not the most efficient).



    You can use the -I option of xargs:



    find /tmp/ -ctime -1 -name "x*" | xargs -I '' mv '' ~/play/


    Which works in a similar mechanism to find and . I would also quote your -name argument (because a file starting with x in the present directory would be file-globed and passed as an argument to find - which will not give the expected behavior!).



    However, as pointed out by manatwork, as detailed in the xargs man page:



     -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.


    The important thing to note is that -L 1 means that only one line of output from find will be processed at a time. This means that's syntactically the same as:



    find /tmp/ -ctime -1 -name "x*" -exec mv '' ~/play/


    (which executes a single mv operation for each file).



    Even using the GNU -0 xargs argument and the find -print0 argument causes exactly the same behavior of -I - this is to clone() a process for each file mv:



    find . -name "x*" -print0 | strace xargs -0 -I '' mv '' /tmp/other

    .
    .
    read(0, "./foobar1/xorgslsala11./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, 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) ---
    .
    .
    .






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 16 '13 at 17:59

























    answered Sep 16 '13 at 14:18









    Drav SloanDrav Sloan

    9,93323138




    9,93323138












    • That assumes file names don't contain newline, single quote, double quote or backslash characters.

      – Stéphane Chazelas
      Sep 16 '13 at 15:31

















    • That assumes file names don't contain newline, single quote, double quote or backslash characters.

      – Stéphane Chazelas
      Sep 16 '13 at 15:31
















    That assumes file names don't contain newline, single quote, double quote or backslash characters.

    – Stéphane Chazelas
    Sep 16 '13 at 15:31





    That assumes file names don't contain newline, single quote, double quote or backslash characters.

    – Stéphane Chazelas
    Sep 16 '13 at 15:31













    15














    With GNU tools:



    find /tmp/ -ctime -1 -name 'x*' -print0 |
    xargs -r0 mv -t ~/play/


    The -t (--target) option is GNU specific. -print0, -r, -0, while non-standard and originating in GNU are also found in some other implementations like on some BSDs.



    POSIXly:



    find /tmp/ -ctime -1 -name 'x*' -exec sh -c '
    exec mv "$@" ~/play/' sh +


    Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.



    Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.






    share|improve this answer

























    • This solution is much better performing, since it calls mv once for all arguments (or for all of -L or -n, if supplied). Otherwise, calling mv for each file will get old (and slow) fast.

      – r2evans
      Feb 12 '18 at 21:25















    15














    With GNU tools:



    find /tmp/ -ctime -1 -name 'x*' -print0 |
    xargs -r0 mv -t ~/play/


    The -t (--target) option is GNU specific. -print0, -r, -0, while non-standard and originating in GNU are also found in some other implementations like on some BSDs.



    POSIXly:



    find /tmp/ -ctime -1 -name 'x*' -exec sh -c '
    exec mv "$@" ~/play/' sh +


    Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.



    Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.






    share|improve this answer

























    • This solution is much better performing, since it calls mv once for all arguments (or for all of -L or -n, if supplied). Otherwise, calling mv for each file will get old (and slow) fast.

      – r2evans
      Feb 12 '18 at 21:25













    15












    15








    15







    With GNU tools:



    find /tmp/ -ctime -1 -name 'x*' -print0 |
    xargs -r0 mv -t ~/play/


    The -t (--target) option is GNU specific. -print0, -r, -0, while non-standard and originating in GNU are also found in some other implementations like on some BSDs.



    POSIXly:



    find /tmp/ -ctime -1 -name 'x*' -exec sh -c '
    exec mv "$@" ~/play/' sh +


    Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.



    Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.






    share|improve this answer















    With GNU tools:



    find /tmp/ -ctime -1 -name 'x*' -print0 |
    xargs -r0 mv -t ~/play/


    The -t (--target) option is GNU specific. -print0, -r, -0, while non-standard and originating in GNU are also found in some other implementations like on some BSDs.



    POSIXly:



    find /tmp/ -ctime -1 -name 'x*' -exec sh -c '
    exec mv "$@" ~/play/' sh +


    Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.



    Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 16 '13 at 19:48

























    answered Sep 16 '13 at 15:28









    Stéphane ChazelasStéphane Chazelas

    309k57582942




    309k57582942












    • This solution is much better performing, since it calls mv once for all arguments (or for all of -L or -n, if supplied). Otherwise, calling mv for each file will get old (and slow) fast.

      – r2evans
      Feb 12 '18 at 21:25

















    • This solution is much better performing, since it calls mv once for all arguments (or for all of -L or -n, if supplied). Otherwise, calling mv for each file will get old (and slow) fast.

      – r2evans
      Feb 12 '18 at 21:25
















    This solution is much better performing, since it calls mv once for all arguments (or for all of -L or -n, if supplied). Otherwise, calling mv for each file will get old (and slow) fast.

    – r2evans
    Feb 12 '18 at 21:25





    This solution is much better performing, since it calls mv once for all arguments (or for all of -L or -n, if supplied). Otherwise, calling mv for each file will get old (and slow) fast.

    – r2evans
    Feb 12 '18 at 21:25











    0














    Perhaps this command is possible now and wasn't back in 2013, but this works perfectly for me:



    ls pattern* | xargs mv -t DESTINATION/


    The -t key puts the destination folder first, freeing up mv command to have all last arguments as just the files to be moved.






    share|improve this answer



























      0














      Perhaps this command is possible now and wasn't back in 2013, but this works perfectly for me:



      ls pattern* | xargs mv -t DESTINATION/


      The -t key puts the destination folder first, freeing up mv command to have all last arguments as just the files to be moved.






      share|improve this answer

























        0












        0








        0







        Perhaps this command is possible now and wasn't back in 2013, but this works perfectly for me:



        ls pattern* | xargs mv -t DESTINATION/


        The -t key puts the destination folder first, freeing up mv command to have all last arguments as just the files to be moved.






        share|improve this answer













        Perhaps this command is possible now and wasn't back in 2013, but this works perfectly for me:



        ls pattern* | xargs mv -t DESTINATION/


        The -t key puts the destination folder first, freeing up mv command to have all last arguments as just the files to be moved.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        Nikhil VJNikhil VJ

        1012




        1012



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f90886%2fhow-can-i-find-files-and-then-use-xargs-to-move-them%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            -find, rename, xargs

            Popular posts from this blog

            Frič See also Navigation menuinternal link

            Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant

            fontconfig warning: “/etc/fonts/fonts.conf”, line 100: unknown “element blank” The 2019 Stack Overflow Developer Survey Results Are In“tar: unrecognized option --warning” during 'apt-get install'How to fix Fontconfig errorHow do I figure out which font file is chosen for a system generic font alias?Why are some apt-get-installed fonts being ignored by fc-list, xfontsel, etc?Reload settings in /etc/fonts/conf.dTaking 30 seconds longer to boot after upgrade from jessie to stretchHow to match multiple font names with a single <match> element?Adding a custom font to fontconfigRemoving fonts from fontconfig <match> resultsBroken fonts after upgrading Firefox ESR to latest Firefox