Moving random files using shuf and mv - Argument list too long
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have a directory containing nearly 250K files, which are lots of files, and I want to move x random files to another directory.
I searched and I got the solution of using the shuf
and mv
commands from here and here, so basically I am using this command
$ shuf -n 5533 -e trainB/* | xargs -i mv testB/
But I'm receiving this error:
bash: /usr/bin/shuf: Argument list too long
I believe because of the large number of files, so accordingly, the argument list is too long, is there another way to do this?
I'm running on SLES12 SP2.
bash mv arguments shuf
add a comment |Â
up vote
2
down vote
favorite
I have a directory containing nearly 250K files, which are lots of files, and I want to move x random files to another directory.
I searched and I got the solution of using the shuf
and mv
commands from here and here, so basically I am using this command
$ shuf -n 5533 -e trainB/* | xargs -i mv testB/
But I'm receiving this error:
bash: /usr/bin/shuf: Argument list too long
I believe because of the large number of files, so accordingly, the argument list is too long, is there another way to do this?
I'm running on SLES12 SP2.
bash mv arguments shuf
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a directory containing nearly 250K files, which are lots of files, and I want to move x random files to another directory.
I searched and I got the solution of using the shuf
and mv
commands from here and here, so basically I am using this command
$ shuf -n 5533 -e trainB/* | xargs -i mv testB/
But I'm receiving this error:
bash: /usr/bin/shuf: Argument list too long
I believe because of the large number of files, so accordingly, the argument list is too long, is there another way to do this?
I'm running on SLES12 SP2.
bash mv arguments shuf
I have a directory containing nearly 250K files, which are lots of files, and I want to move x random files to another directory.
I searched and I got the solution of using the shuf
and mv
commands from here and here, so basically I am using this command
$ shuf -n 5533 -e trainB/* | xargs -i mv testB/
But I'm receiving this error:
bash: /usr/bin/shuf: Argument list too long
I believe because of the large number of files, so accordingly, the argument list is too long, is there another way to do this?
I'm running on SLES12 SP2.
bash mv arguments shuf
bash mv arguments shuf
edited Sep 3 at 16:23
slmâ¦
239k65494665
239k65494665
asked Sep 3 at 16:07
Mostafa Hussein
615
615
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Since youâÂÂre using SLES, you can use GNU extensions to make this safer:
find trainB -mindepth 1 -maxdepth 1 ! -name '.*' -print0 |
shuf -n 5533 -z |
xargs -r0 mv -t testB
This uses find
to process file lists via pipes instead of command-line arguments, then shuffles them, limiting the output, and finally moves them to testB
. The -print0
, -z
, and -0
options ensure nul terminators are used instead of newlines.
Instead of find
, you can use:
printf '%s' trainB/*
printf
being built-in in bash
, it is not affected by that arg list too long limitation of the execve()
system call. That's potentially less efficient though as the shell needs to build the whole list and sort it while find
displays the file paths unsorted as they come.
anyway,shuf
is a GNU-only utility.
â Stéphane Chazelas
Sep 3 at 16:35
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Since youâÂÂre using SLES, you can use GNU extensions to make this safer:
find trainB -mindepth 1 -maxdepth 1 ! -name '.*' -print0 |
shuf -n 5533 -z |
xargs -r0 mv -t testB
This uses find
to process file lists via pipes instead of command-line arguments, then shuffles them, limiting the output, and finally moves them to testB
. The -print0
, -z
, and -0
options ensure nul terminators are used instead of newlines.
Instead of find
, you can use:
printf '%s' trainB/*
printf
being built-in in bash
, it is not affected by that arg list too long limitation of the execve()
system call. That's potentially less efficient though as the shell needs to build the whole list and sort it while find
displays the file paths unsorted as they come.
anyway,shuf
is a GNU-only utility.
â Stéphane Chazelas
Sep 3 at 16:35
add a comment |Â
up vote
2
down vote
accepted
Since youâÂÂre using SLES, you can use GNU extensions to make this safer:
find trainB -mindepth 1 -maxdepth 1 ! -name '.*' -print0 |
shuf -n 5533 -z |
xargs -r0 mv -t testB
This uses find
to process file lists via pipes instead of command-line arguments, then shuffles them, limiting the output, and finally moves them to testB
. The -print0
, -z
, and -0
options ensure nul terminators are used instead of newlines.
Instead of find
, you can use:
printf '%s' trainB/*
printf
being built-in in bash
, it is not affected by that arg list too long limitation of the execve()
system call. That's potentially less efficient though as the shell needs to build the whole list and sort it while find
displays the file paths unsorted as they come.
anyway,shuf
is a GNU-only utility.
â Stéphane Chazelas
Sep 3 at 16:35
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Since youâÂÂre using SLES, you can use GNU extensions to make this safer:
find trainB -mindepth 1 -maxdepth 1 ! -name '.*' -print0 |
shuf -n 5533 -z |
xargs -r0 mv -t testB
This uses find
to process file lists via pipes instead of command-line arguments, then shuffles them, limiting the output, and finally moves them to testB
. The -print0
, -z
, and -0
options ensure nul terminators are used instead of newlines.
Instead of find
, you can use:
printf '%s' trainB/*
printf
being built-in in bash
, it is not affected by that arg list too long limitation of the execve()
system call. That's potentially less efficient though as the shell needs to build the whole list and sort it while find
displays the file paths unsorted as they come.
Since youâÂÂre using SLES, you can use GNU extensions to make this safer:
find trainB -mindepth 1 -maxdepth 1 ! -name '.*' -print0 |
shuf -n 5533 -z |
xargs -r0 mv -t testB
This uses find
to process file lists via pipes instead of command-line arguments, then shuffles them, limiting the output, and finally moves them to testB
. The -print0
, -z
, and -0
options ensure nul terminators are used instead of newlines.
Instead of find
, you can use:
printf '%s' trainB/*
printf
being built-in in bash
, it is not affected by that arg list too long limitation of the execve()
system call. That's potentially less efficient though as the shell needs to build the whole list and sort it while find
displays the file paths unsorted as they come.
edited Sep 3 at 16:37
Stéphane Chazelas
286k53527866
286k53527866
answered Sep 3 at 16:10
Stephen Kitt
147k22321389
147k22321389
anyway,shuf
is a GNU-only utility.
â Stéphane Chazelas
Sep 3 at 16:35
add a comment |Â
anyway,shuf
is a GNU-only utility.
â Stéphane Chazelas
Sep 3 at 16:35
anyway,
shuf
is a GNU-only utility.â Stéphane Chazelas
Sep 3 at 16:35
anyway,
shuf
is a GNU-only utility.â Stéphane Chazelas
Sep 3 at 16:35
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466593%2fmoving-random-files-using-shuf-and-mv-argument-list-too-long%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password