You are not logged in.

#1 2014-01-23 19:19:49

XenoZergNid
Member
Registered: 2014-01-23
Posts: 4

[SOLVED]cp not overwrite but rename

so I'm creating some bash scripts for controlling my camera and it creates a file called Capture.jpg. because I need the files in a seperate folder and in order(so the can easily be compiled into my stopmotion) I would like to copy the file into the other folder as Capture1.jpg then Capture2.jpg then Capture3.jpg...
how would I do this?

Last edited by XenoZergNid (2014-01-24 21:34:06)

Offline

#2 2014-01-23 19:24:08

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED]cp not overwrite but rename

Post the script in question.
I guess you first create Capture.jpg and then rename it to Capture0000.jpg, next one will get renamed to Capture0001.jpg etc.

Offline

#3 2014-01-23 19:36:11

XenoZergNid
Member
Registered: 2014-01-23
Posts: 4

Re: [SOLVED]cp not overwrite but rename

well that will work, the only problem is that I don't know how to store the number it will be renamed too. heres the script:

#captures the image from the camera to the file
capture 'capture Capture.jpg'
#copy the file to the new file. how should I get the right number?
cp './Capture.jpg' './pictures/pic'1'.jpg'
#for onion skinning; isn't related to this problem
capture 'vfalign transparent ./Capture.jpg'
exit 0

Offline

#4 2014-01-23 19:43:50

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED]cp not overwrite but rename

man date

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2014-01-23 19:44:10

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED]cp not overwrite but rename

If you're going to call this script by hand only a few times, you can enter the number yourself.
Is it going to be called automatically e.g. every 5 seconds or ...?
You can simply use the date and time (with seconds) as the directory name.

Offline

#6 2014-01-23 20:12:57

XenoZergNid
Member
Registered: 2014-01-23
Posts: 4

Re: [SOLVED]cp not overwrite but rename

@Karol
The stopmotion will be 15 fps so a 30 second film will be 450 pictures.
@jasonwryan
how would I write that line?(I'm relativly new to bash script)
cp './Capture.jpg' './pictures/pic'     how do I write the output of date +"%d-%M-%S" here?       '.jpg'

Offline

#7 2014-01-23 20:18:02

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED]cp not overwrite but rename

$ touch capture.jpg
$ cp capture.jpg capture-$(date "+%s").jpg
$ cp capture.jpg capture-$(date "+%s").jpg
$ cp capture.jpg capture-$(date "+%s").jpg
$ ls
capture-1390508060.jpg	capture-1390508064.jpg	capture-1390508065.jpg	capture.jpg

Offline

#8 2014-01-23 20:20:46

XenoZergNid
Member
Registered: 2014-01-23
Posts: 4

Re: [SOLVED]cp not overwrite but rename

thank you very much! problem solved.

Offline

#9 2014-01-23 20:24:44

progandy
Member
Registered: 2012-05-17
Posts: 5,211

Re: [SOLVED]cp not overwrite but rename

In the unlikely case that you want to capture more than one iamge per second, use

date +%s.%N

| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#10 2014-01-23 20:48:41

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED]cp not overwrite but rename

Please remember to mark the thread as solved https://bbs.archlinux.org/viewtopic.php?id=130309

Offline

#11 2014-01-23 21:55:20

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,617
Website

Re: [SOLVED]cp not overwrite but rename

Also, why the middle man?

Why `capture Capture.jpg` then `cp Capture somefilename`.  Why not just `capture somefilename`?  Or more specifically

while true; do
   capture /path/to/images/img_$(date +%s).jpg
   sleep 1
done

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2014-01-23 21:58:40

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED]cp not overwrite but rename

OP mentions

capture 'vfalign transparent ./Capture.jpg'

No idea what id does, maybe he needs Capture.jpg for something.


I agree that if he wants to use bash all the way, Trilby's suggestion of continuous loop and sleep is perfect.

Offline

#13 2014-01-23 22:15:29

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,944
Website

Re: [SOLVED]cp not overwrite but rename

If you save the date output to a variable then the watermark could be added during the loop, or, if the processing delay would be too great, it could be done in bulk after the capture loop is completed.

Last edited by WorMzy (2014-01-23 22:15:46)


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Online

Board footer

Powered by FluxBB