With zsh and its glob qualifiers:
mv -- *(D.oN[1,5000]) ./subfolder1
To move up to 5000 regular files in the order they are in the directory.
For the first 5000 in the lexicographically sorted list:
mv -- *some_pattern*(D.[1,5000]) ./subfolder1
If you get an error about arg list too long. You can use zsh's buitin mv command by issuing:
zmodload zsh/files
first.
POSIXly:
set -- for f in .*some_pattern* *some_pattern*; do [ "$#" -lt 5000 ] || break [ -f "$f" ] || continue [ -L "$f" ] && continue set -- "$@" "$f" done [ "$#" -eq 0 ] || mv -- "$@" subfolder1/
On a GNU system, you could also do:
find . ! -name . -prune -name '*some_pattern*' -type f -print0 | head -zn 5000 | xargs -r0 mv -t ./subfolder1 --