BASH script, auto file naming

if'var' is a count, then to increment it and then use it as (part of) a file name (file1, file2 etc) # inc number, convert to 4 digits (i.e. add leading zeros) var =$( printf '%04d' $((var++)) ) nextname="file$var" $ means evaluate (so pre-fixes a variable name) - without the $ what follows is taken as constants (i.e. text charcaters) (( ..)) means evaluate numerically (and ++ just means increment)

Date amd time

$(date +"%Y-%m-%d_%H%M%S.%3N") The '%' prefix indicates a date/time value %Y is 4 digit year, %m 2 digit month, %d 2 digit day (if you want 3 character month (Jan, Feb etc), use %b instead of %m) %H is 2 digit (24Hr) Hours, %M is 2 digit mins, %S 2 digit seconds %N means time in nano seconds, %3N means to nearest 3 digits i.e. time in milli-sconds (for uS, use %6N). The '-', '_' and '.' are returned as embedded characters (at the positions) in the generated character string

Auto filenames with the Pi camera

Since max. speed burst mode shots using :- sudo raspistill -n -bm -o %04d.jpg -t 10000 -tl 0 -th 0:0:0 generates 4 digit file names (%04d) automatically, you might think that :- sudo raspistill -n -bm -o $(date +"%Y-%m-%d_%H%M%S.%3N").jpg -t 10000 -tl 0 -th 0:0:0 would generate data and time stamped files ? WRONG = the $(date +"%Y-%m-%d_%H%M%S.%3N") is evaluated ONCE (when the command line is 'read') - so all you get the last taken photo, timestamped (to the mS) prior to the start of the burst as 'sudo' will have over-written all intervening photos of same name :-) raspistill has a -dt option flag which will replace a '%d' serial number a 'date number', however this gets you MMDDHHMMSS as a simple 32bit number (i.e. as a 10 digit string) - so only 'works' for shots no faster than 1 a second (or it's back to later photos overwriting earlier ones again :-) ) To get multiple shots per second with date/time you have to use something like :- sudo raspistill -n -bm -o $(date +"%Y-%m-%d_%H%M%S-)%02d.jpg -t 10000 -tl 0 -th 0:0:0 This gives you a file name composed of the date and time (when the command was executed) plus a 2 digit sequential photo serial number. To get more accurate time-stamp, you can use the photo file creation date/time, or for the date time of the actual 'shot', use Image Annotations.