I got a directory which contains approx 9000 files, the file names are in ascending number (however not necessarily consecutive).
Now I need to copy/move ~3000 files from number xxxx to number yyyy to another direcotory. How can I use cp or mv command for that purpose?
You can use the
sequtility to generate numbers for this kind of operation:On the downside, this will execute
cpa lot more often than QuantumMechanic’s solution; but QuantumMechanic’s solution may not execute if the total length of all the filenames is greater than the kernel’sargvsize limitation (which could be between 128K and 2048K, depending upon your kernel version and stack-size rlimits; seeexecve(2)for details).If the range you want spans orders of magnitudes (e.g., between
900and1010) then theseq -woption may be useful, it zero-pads the output numbers.