Copy range of files on Linux/Unix

Background

I have already thoroughly read through this question: Copy a range of fiels and tried most of the answers.

I exported data into a single .json then split the .json file into smaller serialized files with 50k lines in each.

$ls

smaller_aaaa  smaller_aaak  smaller_aaau  smaller_aabe  smaller_aabo  smaller_aaby  smaller_aaci  smaller_aacs  smaller_aadc  smaller_aadm
smaller_aaab  smaller_aaal  smaller_aaav  smaller_aabf  smaller_aabp  smaller_aabz  smaller_aacj  smaller_aact  smaller_aadd  smaller_aadn
smaller_aaac  smaller_aaam  smaller_aaaw  smaller_aabg  smaller_aabq  smaller_aaca  smaller_aack  smaller_aacu  smaller_aade  smaller_aado
smaller_aaad  smaller_aaan  smaller_aaax  smaller_aabh  smaller_aabr  smaller_aacb  smaller_aacl  smaller_aacv  smaller_aadf  smaller_aadp
smaller_aaae  smaller_aaao  smaller_aaay  smaller_aabi  smaller_aabs  smaller_aacc  smaller_aacm  smaller_aacw  smaller_aadg  smaller_aadq
smaller_aaaf  smaller_aaap  smaller_aaaz  smaller_aabj  smaller_aabt  smaller_aacd  smaller_aacn  smaller_aacx  smaller_aadh  smaller_aadr
smaller_aaag  smaller_aaaq  smaller_aaba  smaller_aabk  smaller_aabu  smaller_aace  smaller_aaco  smaller_aacy  smaller_aadi  smaller_aads
smaller_aaah  smaller_aaar  smaller_aabb  smaller_aabl  smaller_aabv  smaller_aacf  smaller_aacp  smaller_aacz  smaller_aadj  smaller_aadt
smaller_aaai  smaller_aaas  smaller_aabc  smaller_aabm  smaller_aabw  smaller_aacg  smaller_aacq  smaller_aada  smaller_aadk
smaller_aaaj  smaller_aaat  smaller_aabd  smaller_aabn  smaller_aabx  smaller_aach  smaller_aacr  smaller_aadb  smaller_aadl

Goal

I want to copy the files from smaller_aaau to smaller_aadd into a new directory in the current directory.

What I’ve tried:

variations of these as well

cp smaller_aa{au..dd} ./GlobalBuckets

I also tried using bash scripting:

#!/bin/bash
for file in {au..dd};do cp smaller_aa$file ~/Downloads/SPLIT/GlobalBuckets;done;
bash script

error for both methods:

cp: cannot stat 'smaller_aa{au..dd}': No such file or directory

Answer

I want to copy the files from smaller_aaau to smaller_aadd into a new directory in the current directory.

Do it in small incrementals, e.g.:

  • Copy smaller_aaau to smaller_aaaz first, then
  • Copy smaller_aada to smaller_aadd, then
  • Copy smaller_aaba to smaller_aacz

Should be something like:

cp smaller_aaa[u-z] smaller_aad[a-d] smaller_aa[b-c]* /path/to/destination

Square bracket globbing only support a range of integers ([107-203]) or a range of characters ([a-d], [A-Ca-c]).

Attribution
Source : Link , Question Author : Garrett , Answer Author : mforsetti

Leave a Comment