I'm moving png files from source/ to dest/ with this:
mv /source/*.png /dest/
How can I change that command so I only move 10 png files?
I'm moving png files from source/ to dest/ with this:
mv /source/*.png /dest/
How can I change that command so I only move 10 png files?
You can do this in Zsh with a glob qualifier:
mv /source/*.png([1,10]) /dest/
Moves the first 10 ones in alphabetic order. You can pick a different order using the o/O/n qualifiers. For instance:
mv /source/*.png(OL[1,10]) /dest/
Would move the 10 largest ones.
An optimised version that selects the first 10 matches without bothering to sort can be done with the Y qualifier:
mv /source/*.png(Y10) /dest/
POSIXly, that could be done with:
set -- /source/*.png
[ "$#" -le 10 ] || shift "$(( $# - 10 ))"
mv -- "$@" /dest/
Which would move the 10 last ones in alphabetic order.
Note that it excludes hidden ones and if there's no match, it would attempt to move a file called /source/*.png and likely fail.
ls /source/*.png | head -n10 | xargs -I{} mv {} /dest/