Moving 1M of files on 5M












1















Is there a command line to move 1M of files from a directory with 5M of files?



I tried:



sudo mv `ls | head -1000000` <destination>


But I get this message: -bash: /usr/bin/sudo: Argument list too long



Thank you.










share|improve this question























  • rsync is not an option because the total is like 1To, and I do not have enough space to copy them...

    – Nico
    Oct 4 '18 at 17:59
















1















Is there a command line to move 1M of files from a directory with 5M of files?



I tried:



sudo mv `ls | head -1000000` <destination>


But I get this message: -bash: /usr/bin/sudo: Argument list too long



Thank you.










share|improve this question























  • rsync is not an option because the total is like 1To, and I do not have enough space to copy them...

    – Nico
    Oct 4 '18 at 17:59














1












1








1








Is there a command line to move 1M of files from a directory with 5M of files?



I tried:



sudo mv `ls | head -1000000` <destination>


But I get this message: -bash: /usr/bin/sudo: Argument list too long



Thank you.










share|improve this question














Is there a command line to move 1M of files from a directory with 5M of files?



I tried:



sudo mv `ls | head -1000000` <destination>


But I get this message: -bash: /usr/bin/sudo: Argument list too long



Thank you.







16.04 mv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 4 '18 at 17:54









NicoNico

206




206













  • rsync is not an option because the total is like 1To, and I do not have enough space to copy them...

    – Nico
    Oct 4 '18 at 17:59



















  • rsync is not an option because the total is like 1To, and I do not have enough space to copy them...

    – Nico
    Oct 4 '18 at 17:59

















rsync is not an option because the total is like 1To, and I do not have enough space to copy them...

– Nico
Oct 4 '18 at 17:59





rsync is not an option because the total is like 1To, and I do not have enough space to copy them...

– Nico
Oct 4 '18 at 17:59










1 Answer
1






active

oldest

votes


















1














You can create a shellscript file with a list of commands for single files. It will not be very fast, but this way you will avoid the problem with a too long argument list.




  • Try first with less than 1 million commands (for example 15), in order to check that it works correctly.

  • Modify /path/to/sourcedir and /path/to/targetdir to match your actual directories.




find /path/to/sourcedir -maxdepth 1 -type f -printf "mv "%p" /path/to/targetdirn" | head -n 15 > myscript


Make the script executable



chmod ugo+x myscript


Run the script



./myscript





share|improve this answer


























  • I like your idea @sudodus! I was trying to dev a script with a "while". It goal will be to move every files starting by 1 into a directory called 1 and etc...

    – Nico
    Oct 5 '18 at 11:55











  • @Nico, Please tell me, if you want more help (and in that case with what details).

    – sudodus
    Oct 5 '18 at 14:48











  • My script seems to work fine. It takes time, but should be ok :D Thanks again.

    – Nico
    Oct 5 '18 at 18:03











  • @Nico, You are welcome, I'm glad that your script is working well :-)

    – sudodus
    Oct 6 '18 at 8:28











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f1080959%2fmoving-1m-of-files-on-5m%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can create a shellscript file with a list of commands for single files. It will not be very fast, but this way you will avoid the problem with a too long argument list.




  • Try first with less than 1 million commands (for example 15), in order to check that it works correctly.

  • Modify /path/to/sourcedir and /path/to/targetdir to match your actual directories.




find /path/to/sourcedir -maxdepth 1 -type f -printf "mv "%p" /path/to/targetdirn" | head -n 15 > myscript


Make the script executable



chmod ugo+x myscript


Run the script



./myscript





share|improve this answer


























  • I like your idea @sudodus! I was trying to dev a script with a "while". It goal will be to move every files starting by 1 into a directory called 1 and etc...

    – Nico
    Oct 5 '18 at 11:55











  • @Nico, Please tell me, if you want more help (and in that case with what details).

    – sudodus
    Oct 5 '18 at 14:48











  • My script seems to work fine. It takes time, but should be ok :D Thanks again.

    – Nico
    Oct 5 '18 at 18:03











  • @Nico, You are welcome, I'm glad that your script is working well :-)

    – sudodus
    Oct 6 '18 at 8:28
















1














You can create a shellscript file with a list of commands for single files. It will not be very fast, but this way you will avoid the problem with a too long argument list.




  • Try first with less than 1 million commands (for example 15), in order to check that it works correctly.

  • Modify /path/to/sourcedir and /path/to/targetdir to match your actual directories.




find /path/to/sourcedir -maxdepth 1 -type f -printf "mv "%p" /path/to/targetdirn" | head -n 15 > myscript


Make the script executable



chmod ugo+x myscript


Run the script



./myscript





share|improve this answer


























  • I like your idea @sudodus! I was trying to dev a script with a "while". It goal will be to move every files starting by 1 into a directory called 1 and etc...

    – Nico
    Oct 5 '18 at 11:55











  • @Nico, Please tell me, if you want more help (and in that case with what details).

    – sudodus
    Oct 5 '18 at 14:48











  • My script seems to work fine. It takes time, but should be ok :D Thanks again.

    – Nico
    Oct 5 '18 at 18:03











  • @Nico, You are welcome, I'm glad that your script is working well :-)

    – sudodus
    Oct 6 '18 at 8:28














1












1








1







You can create a shellscript file with a list of commands for single files. It will not be very fast, but this way you will avoid the problem with a too long argument list.




  • Try first with less than 1 million commands (for example 15), in order to check that it works correctly.

  • Modify /path/to/sourcedir and /path/to/targetdir to match your actual directories.




find /path/to/sourcedir -maxdepth 1 -type f -printf "mv "%p" /path/to/targetdirn" | head -n 15 > myscript


Make the script executable



chmod ugo+x myscript


Run the script



./myscript





share|improve this answer















You can create a shellscript file with a list of commands for single files. It will not be very fast, but this way you will avoid the problem with a too long argument list.




  • Try first with less than 1 million commands (for example 15), in order to check that it works correctly.

  • Modify /path/to/sourcedir and /path/to/targetdir to match your actual directories.




find /path/to/sourcedir -maxdepth 1 -type f -printf "mv "%p" /path/to/targetdirn" | head -n 15 > myscript


Make the script executable



chmod ugo+x myscript


Run the script



./myscript






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 4 at 7:38

























answered Oct 4 '18 at 19:43









sudodussudodus

23.5k32874




23.5k32874













  • I like your idea @sudodus! I was trying to dev a script with a "while". It goal will be to move every files starting by 1 into a directory called 1 and etc...

    – Nico
    Oct 5 '18 at 11:55











  • @Nico, Please tell me, if you want more help (and in that case with what details).

    – sudodus
    Oct 5 '18 at 14:48











  • My script seems to work fine. It takes time, but should be ok :D Thanks again.

    – Nico
    Oct 5 '18 at 18:03











  • @Nico, You are welcome, I'm glad that your script is working well :-)

    – sudodus
    Oct 6 '18 at 8:28



















  • I like your idea @sudodus! I was trying to dev a script with a "while". It goal will be to move every files starting by 1 into a directory called 1 and etc...

    – Nico
    Oct 5 '18 at 11:55











  • @Nico, Please tell me, if you want more help (and in that case with what details).

    – sudodus
    Oct 5 '18 at 14:48











  • My script seems to work fine. It takes time, but should be ok :D Thanks again.

    – Nico
    Oct 5 '18 at 18:03











  • @Nico, You are welcome, I'm glad that your script is working well :-)

    – sudodus
    Oct 6 '18 at 8:28

















I like your idea @sudodus! I was trying to dev a script with a "while". It goal will be to move every files starting by 1 into a directory called 1 and etc...

– Nico
Oct 5 '18 at 11:55





I like your idea @sudodus! I was trying to dev a script with a "while". It goal will be to move every files starting by 1 into a directory called 1 and etc...

– Nico
Oct 5 '18 at 11:55













@Nico, Please tell me, if you want more help (and in that case with what details).

– sudodus
Oct 5 '18 at 14:48





@Nico, Please tell me, if you want more help (and in that case with what details).

– sudodus
Oct 5 '18 at 14:48













My script seems to work fine. It takes time, but should be ok :D Thanks again.

– Nico
Oct 5 '18 at 18:03





My script seems to work fine. It takes time, but should be ok :D Thanks again.

– Nico
Oct 5 '18 at 18:03













@Nico, You are welcome, I'm glad that your script is working well :-)

– sudodus
Oct 6 '18 at 8:28





@Nico, You are welcome, I'm glad that your script is working well :-)

– sudodus
Oct 6 '18 at 8:28


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • 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%2faskubuntu.com%2fquestions%2f1080959%2fmoving-1m-of-files-on-5m%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







Popular posts from this blog

Ellipse (mathématiques)

Quarter-circle Tiles

Mont Emei