Skip to main content
added 39 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

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 -0r0 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\0' 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 -print0 | shuf -n 5533 -z | xargs -0 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.

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\0' 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.

Source Link
Stephen Kitt
  • 481.4k
  • 60
  • 1.2k
  • 1.4k

Since you’re using SLES, you can use GNU extensions to make this safer:

find trainB -print0 | shuf -n 5533 -z | xargs -0 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.