I have a sequence of timelapse files on my Raspberry Pi that I am trying to copy across to a memory card. I have to split the move into two batches (source folder is twice the size of the destination folder). Here is the script that I have been working (all day!). I still can't get it to run.

cp -v /home/pi/timelapse   "201712140[20331-45246] {} /media/pi/FC33-7BFB1/timelapse

The source folder files sequence at 15sec increments from 20171214020331 - 20171214045246.

closed as unclear what you're asking by Eric Carvalho, Wayne_Yux, MadMike, Zanna, waltinator Dec 29 '17 at 18:05

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Split it into batches how? – muru Dec 18 '17 at 2:57
  • 1
    That command has a dangling quote. – wjandrea Dec 18 '17 at 2:59
  • 2
    It looks like you're trying to match a range of numbers, from 20331 to 45246, but the square bracket glob syntax is for a char set, not a range. – wjandrea Dec 18 '17 at 3:02
  • 2
    You seem to be asking a "Give me a fish question". Both you and those who find your question later would be best served by a "How to Fish answer", this is why you have not had your code written for you. A useful set of search terms is bash brace expansion – J. Starnes Dec 18 '17 at 3:48
  • 1
    If it's a one-off task, use a file manager such as Midnight Commander. Highlight the files by tapping on Insert, and copy with F5. – egmont Dec 18 '17 at 8:54

The cp command takes one or more source files followed by a destination. If there are multiple source files (as in your case) the destination must be a directory (where the files will all be copied to). As per the comment, you are misusing the square brackets. I don't know what the curly braces will do, but highly likely not what you want. Assuming your first source file is /home/pi/timelapse/20171214020331, that the filenames don't contain spaces, and that the destination directory /media/pi/FC33-7BFB1/timelapse already exists, try

cp /home/pi/timelapse/201712140[23]* /media/pi/FC33-7BFB1/timelapse/

If that copies all files starting 2017121402 and 2017121403 you can move the next set using [45] etc. That's a bit cumbersome, but will get you started on your voyage of discovery...


You can try this to copy file, finding by regex in a range

for file in 201712140*
    matched="$(echo "$file" | grep -oP '(?<=201712140)([^.]+)')"
    if [[ $matched -ge 20331 && $matched -le 45246 ]]; then
        cp -v $file /your/location

Just run this script in your source directory. Save it in a file xyz.sh and run bash xyz.sh

Not the answer you're looking for? Browse other questions tagged or ask your own question.