2

I have bunch of .JPG, .NEF and .MOV files made with my Nikon DSLR, named as DSC_0001.JPG, DSC_0002.JPG and so on. After certain number is reached, new directory is made and number count restarted, which leads to duplicates when I move them into one big directory.

I figured out, using bash, how to name them after their date of creation using for loop and exiftool:

for i in *.JPG
do
  mv -nv "$i" "$(exiftool -d "%Y%m%d-%H%M%S" -CreateDate "$i" | awk '{print $4".jpg"}')
done

an approach that creates another problem that I became aware of too late and lost about 100 files in the process - sometimes more than one picture is taken in one second and I can't find an easy way to attach unit smaller that a second, keeping filename readable.

So I wanted to append file's checksum, for example CRC32, something short and fairly random and made this monstrosity:

sum="$(crc32 * | cut -d' ' -f1)"

for i in *.jpg
do

        mv -nv "$i" "$(exiftool -d %Y%m%d-%H%M%S" -CreateDate "$i" | awk '{print $4"-"}')$sum.jpg"

done

which worked with one file in directory but produced these kind of error messages when applied in main directory of all photos I have:

mv: failed to access '504a5b89'$'\t''DSC_0001.NEF'$'\n''629a031e'$'\t''DSC_0002.NEF'$'\n''1af2720c'$'\t''DSC_0003.NEF'$'\n''852f62de'$'\t''DSC_0004.NEF'$'\n''874bd1f0'$'\t''DSC_0005.NEF'$'\n''f3fceda8'$'\t''DSC_0006.NEF'$'\n''28207fa2'$'\t''DSC_0007.NEF'$'\n''046ca494'$'\t''DSC_0008.NEF'$'\n''abf11428'$'\t''DSC_0009.NEF'$'\n''479e728d'$'\t''DSC_0010.NEF'$'\n''8df21237'$'\t''DSC_0011.NEF'$'\n''77663953'$'\t''DSC_0012.NEF'$'\n''7d9871c7'$'\t''DSC_0013.NEF'$'\n''85608081'$'\t''DSC_0014.NEF'$'\n''49246d62'$'\t''DSC_0016.NEF'$'\n''a2f927bc'$'\t''DSC_0017.NEF'$'\n''33277700'$'\t''DSC_0018.NEF'$'\n''76410b41'$'\t''DSC_0019.NEF'$'\n''c30d7d1c'$'\t''DSC_0020.NEF'$'\n''de239afe'$'\t''DSC_0021.NEF'$'\n''c9a1999e'$'\t''DSC_0022.NEF'$'\n''5e124a8a'$'\t''DSC_0023.NEF'$'\n''8e5eb670'$'\t''DSC_0024.NEF'$'\n''a26eb4cb'$'\t''DSC_0025.NEF'$'\n''a0f0444e'$'\t''DSC_0026.NEF'$'\n''7b686084'$'\t''DSC_0027.NEF'$'\n''eff42939'$'\t''DSC_0028.NEF'$'\n''7ed21f22'$'\t''DSC_0029.NEF'$'\n''85f8f493'$'\t''DSC_0030.NEF'$'\n''97227a4f'$'\t''DSC_0031.NEF'$'\n''a0a96fb2'$'\t''DSC_0032.NEF'$'\n''e82c47e6'$'\t''DSC_0033.NEF'$'\n''55f5e030'$'\t''DSC_0034.NEF'$'\n''4fd188b4'$'\t''DSC_0035.NEF'$'\n''357d0757'$'\t''DSC_0036.NEF'$'\n''87cd39d6'$'\t''DSC_0037.NEF'$'\n''34b6fb45'$'\t''DSC_0038.NEF'$'\n''ef6f09f0'$'\t''DSC_0039.NEF'$'\n''b8d12e00'$'\t''DSC_0040.NEF'$'\n''bd2d4cae'$'\t''DSC_0041.NEF'$'\n''55dc67c0'$'\t''DSC_0042.NEF'$'\n''08ba39e4'$'\t''DSC_0043.NEF'$'\n''bcfefc4a'$'\t''DSC_0044.NEF'$'\n''ce69e1fd'$'\t''DSC_0045.NEF'$'\n''275af151'$'\t''DSC_0046.NEF'$'\n''6a30a875'$'\t''DSC_0047.NEF'$'\n''3aefb843'$'\t''DSC_0048.NEF'$'\n''674458fb'$'\t''DSC_0049.NEF'$'\n''aab60fc7'$'\t''DSC_0050.NEF'$'\n''13502f06'$'\t''DSC_0051.NEF'$'\n''ac3eba1e'$'\t''DSC_0052.NEF'$'\n''c5052ad9'$'\t''DSC_0053.NEF'$'\n''80c3ee64'$'\t''DSC_0054.NEF'$'\n''d17f3177'$'\t''DSC_0055.NEF'$'\n''53f51ccf'$'\t''DSC_0056.NEF'$'\n''f91427af'$'\t''DSC_0057.NEF'$'\n''0d596f23'$'\t''DSC_0058.NEF'$'\n''fc378e62'$'\t''DSC_0059.NEF'$'\n''c72be5b3'$'\t''DSC_0060.NEF'$'\n''8bf29954'$'\t''DSC_0061.NEF'$'\n''f1193bbf'$'\t''DSC_0062.NEF'$'\n''d4460f24'$'\t''DSC_0063.NEF'$'\n''1e7b1c07'$'\t''DSC_0064.NEF'$'\n''3cc1cbd2'$'\t''DSC_0065.NEF'$'\n''ae935236'$'\t''DSC_0066.NEF'$'\n''f0ff02c1'$'\t''DSC_0067.NEF'$'\n''a16c6e58'$'\t''DSC_0068.NEF'$'\n''57ae8019'$'\t''DSC_0069.NEF'$'\n''82fc94df'$'\t''DSC_0070.NEF'$'\n''2ac41f26'$'\t''DSC_0071.NEF'$'\n''76b0493a'$'\t''DSC_0072.NEF'$'\n''9791ccf7'$'\t''DSC_0073.NEF'$'\n''eac3e7aa'$'\t''DSC_0074.NEF'$'\n''14f7c55c'$'\t''DSC_0075.NEF'$'\n''86df85b0'$'\t''DSC_0076.NEF'$'mv: failed to access '504a5b89'$'\t''DSC_0001.NEF'$'\n''629a031e'$'\t''DSC_0002.NEF'$'\n''1af2720c'$'\t''DSC_0003.NEF'$'\n''852f62de'$'\t''DSC_0004.NEF'$'\n''874bd1f0'$'\t''DSC_0005.NEF'$'\n''f3fceda8'$'\t''DSC_0006.NEF'$'\n''28207fa2'$'\t''DSC_0007.NEF'$'\n''046ca494'$'\t''DSC_0008.NEF'$'\n''abf11428'$'\t''DSC_0009.NEF'$'\n''479e728d'$'\t''DSC_0010.NEF'$'\n''8df21237'$'\t''DSC_0011.NEF'$'\n''77663953'$'\t''DSC_0012.NEF'$'\n''7d9871c7'$'\t''DSC_0013.NEF'$'\n''85608081'$'\t''DSC_0014.NEF'$'\n''49246d62'$'\t''DSC_0016.NEF'$'\n''a2f927bc'$'\t''DSC_0017.NEF'$'\n''33277700'$'\t''DSC_0018.NEF'$'\n''76410b41'$'\t''DSC_0019.NEF'$'\n''c30d7d1c'$'\t''DSC_0020.NEF'$'\n''de239afe'$'\t''DSC_0021.NEF'$'\n''c9a1999e'$'\t''DSC_0022.NEF'$'\n''5e124a8a'$'\t''DSC_0023.NEF'$'\n''8e5eb670'$'\t''DSC_0024.NEF'$'\n''a26eb4cb'$'\t''DSC_0025.NEF'$'\n''a0f0444e'$'\t''DSC_0026.NEF'$'\n''7b686084'$'\t''DSC_0027.NEF'$'\n''eff42939'$'\t''DSC_0028.NEF'$'\n''7ed21f22'$'\t''DSC_0029.NEF'$'\n''85f8f493'$'\t''DSC_0030.NEF'$'\n''97227a4f'$'\t''DSC_0031.NEF'$'\n''a0a96fb2'$'\t''DSC_0032.NEF'$'\n''e82c47e6'$'\t''DSC_0033.NEF'$'\n''55f5e030'$'\t''DSC_0034.NEF'$'\n''4fd188b4'$'\t''DSC_0035.NEF'$'\n''357d0757'$'\t''DSC_0036.NEF'$'\n''87cd39d6'$'\t''DSC_0037.NEF'$'\n''34b6fb45'$'\t''DSC_0038.NEF'$'\n''ef6f09f0'$'\t''DSC_0039.NEF'$'\n''b8d12e00'$'\t''DSC_0040.NEF'$'\n''bd2d4cae'$'\t''DSC_0041.NEF'$'\n''55dc67c0'$'\t''DSC_0042.NEF'$'\n''08ba39e4'$'\t''DSC_0043.NEF'$'\n''bcfefc4a'$'\t''DSC_0044.NEF'$'\n''ce69e1fd'$'\t''DSC_0045.NEF'$'\n''275af151'$'\t''DSC_0046.NEF'$'\n''6a30a875'$'\t''DSC_0047.NEF'$'\n''3aefb843'$'\t''DSC_0048.NEF'$'\n''674458fb'$'\t''DSC_0049.NEF'$'\n''aab60fc7'$'\t''DSC_0050.NEF'$'\n''13502f06'$'\t''mv: failed to access '504a5b89'$'\t''DSC_0001.NEF'$'\n''629a031e'$'\t''DSC_0002.NEF'$'\n''1af2720c'$'\t''DSC_0003.NEF'$'\n''852f62de'$'\t''DSC_0004.NEF'$'\n''874bd1f0'$'\t''DSC_0005.NEF'$'\n''f3fceda8'$'\t''DSC_0006.NEF'$'\n''28207fa2'$'\t''DSC_0007.NEF'$'\n''046ca494'$'\t''DSC_0008.NEF'$'\n''abf11428'$'\t''DSC_0009.NEF'$'\n''479e728d'$'\t''DSC_0010.NEF'$'\n''8df21237'$'\t''DSC_0011.NEF'$'\n''77663953'$'\t''DSC_0012.NEF'$'\n''7d9871c7'$'\t''DSC_0013.NEF'$'\n''85608081'$'\t''DSC_0014.NEF'$'\n''49246d62'$'\t''DSC_0016.NEF'$'\n''a2f927bc'$'\t''DSC_0017.NEF'$'\n''33277700'$'\t''DSC_0018.NEF'$'\n''76410b41'$'\t''DSC_0019.NEF'$'\n''c30d7d1c'$'\t''DSC_0020.NEF'$'\n''de239afe'$'\t''DSC_0021.NEF'$'\n''c9a1999e'$'\t''DSC_0022.NEF'$'\n''5e124a8a'$'\t''DSC_0023.NEF'$'\n''8e5eb670'$'\t''DSC_0024.NEF'$'\n''a26eb4cb'$'\t''DSC_0025.NEF'$'\n''a0f0444e'$'\t''DSC_0026.NEF'$'\n''7b686084'$'\t''DSC_0027.NEF'$'\n''eff42939'$'\t''DSC_0028.NEF'$'\n''7ed21f22'$'\t''DSC_0029.NEF'$'\n''85f8f493'$'\t''DSC_0030.NEF'$'\n''97227a4f'$'\t''DSC_0031.NEF'$'\n''a0a96fb2'$'\t''DSC_0032.NEF'$'\n''e82c47e6'$'\t''DSC_0033.NEF'$'\n''55f5e030'$'\t''DSC_0034.NEF'$'\n''4fd188b4'$'\t''DSC_0035.NEF'$'\n''357d0757'$'\t''DSC_0036.NEF'$'\n''87cd39d6'$'\t''DSC_0037.NEF'$'\n''34b6fb45'$'\t''DSC_0038.NEF'$'\n''ef6f09f0'$'\t''DSC_0039.NEF'$'\n''b8d12e00'$'\t''DSC_0040.NEF'$'\n''bd2d4cae'$'\t''DSC_0041.NEF'$'\n''55dc67c0'$'\t''DSC_0042.NEF'$'\n''08ba39e4'$'\t''DSC_0043.NEF'$'\n''bcfefc4a'$'\t''DSC_0044.NEF'$'\n''ce69e1fd'$'\t''DSC_0045.NEF'$'\n''275af151'$'\t''DSC_0046.NEF'$'\n''6a30a875'$'\t''DSC_0047.NEF'$'\n''3aefb843'$'\t''DSC_0048.NEF'$'\n''674458fb'$'\t''DSC_0049.NEF'$'\n''aab60fc7'$'\t''DSC_0050.NEF'$'\n''13502f06'$'\t''DSC_0051.NEF'$'\n''ac3eba1e'$'\t''DSC_0052.NEF'$'\n''c5052ad9'$'\t''DSC_0053.NEF'$'\n''80c3ee64'$'\t''DSC_0054.NEF'$'\n''d17f3177'$'\t''DSC_0055.NEF'$'\n''53f51ccf'$'\t''DSC_0056.NEF'$'\n''f91427af'$'\t''DSC_0057.NEF'$'\n''0d596f23'$'\t''DSC_0058.NEF'$'\n''fc378e62'$'\t''DSC_0059.NEF'$'\n''c72be5b3'$'\t''DSC_0060.NEF'$'\n''8bf29954'$'\t''DSC_0061.NEF'$'\n''f1193bbf'$'\t''DSC_0062.NEF'$'\n''d4460f24'$'\t''DSC_0063.NEF'$'\n''1e7b1c07'$'\t''DSC_0064.NEF'$'\n''3cc1cbd2'$'\t''DSC_0065.NEF'$'\n''ae935236'$'\t''DSC_0066.NEF'$'\n''f0ff02c1'$'\t''DSC_0067.NEF'$'\n''a16c6e58'$'\t''DSC_0068.NEF'$'\n''57ae8019'$'\t''DSC_0069.NEF'$'\n''82fc94df'$'\t''DSC_0070.NEF'$'\n''2ac41f26'$'\t''DSC_0071.NEF'$'\n''76b0493a'$'\t''DSC_0072.NEF'$'\n''9791ccf7'$'\t''DSC_0073.NEF'$'\n''eac3e7aa'$'\t''DSC_0074.NEF'$'\n''14f7c55c'$'\t''DSC_0075.NEF'$'\n''86df85b0'$'\t''DSC_0076.NEF'$'\n''d23ebeb8'$'\t''DSC_0077.NEF'$'\n''b1f51ea1'$'\t''DSC_0078.NEF'$'\n''1fb307bc'$'\t''DSC_0079.NEF'$'\n''91c17294'$'\t''DSC_0080.NEF'$'\n''c590cfb0'$'\t''DSC_0081.NEF'$'\n''9fc1eaad'$'\t''DSC_0082.NEF'$'\n''31de2e7c'$'\t''DSC_0083.NEF'$'\n''b4858068'$'\t''DSC_0084.NEF'$'\n''04371839'$'\t''DSC_0085.NEF'$'\n''fc440b4a'$'\t''DSC_0086.NEF'$'\n''9de00d44'$'\t''DSC_0087.NEF'$'\n''b9ab2214'$'\t''DSC_0088.NEF'$'\n''4c6f37c8'$'\t''DSC_0089.NEF'$'\n''14de5216'$'\t''DSC_0090.NEF'$'\n''8a565c42'$'\t''DSC_0091.NEF'$'\n''d05282d6'$'\t''DSC_0092.NEF'$'\n''fc032016'$'\t''DSC_0093.NEF'$'\n''ada77bc0'$'\t''DSC_0094.NEF'$'\n''3e6e288c'$'\t''DSC_0095.NEF'$'\n''6bfdb74a'$'\t''DSC_0096.NEF'$'\n''f2529938'$'\t''DSC_0097.NEF'$'\n''8193fcd9'$'\t''DSC_0098.NEF'$'\n''7786e3e1'$'\t''DSC_0099.NEF'$'\n''f2c36981'$'\t''DSC_0100.NEF'$'\n''b0e548e9'$'\t''DSC_0101.NEF'$'\n''b222e465'$'\t''DSC_0102.NEF'$'\n''b32683ac'$'\t''DSC_0103.NEF'$'\n''8511325d'$'\t''DSC_0104.NEF'$'\n''6ae62bf8'$'\t''DSC_0105.NEF'$'\n''bc15a457'$'\t''DSC_0106.NEF'$'\n''31f00e91'$'\t''DSC_0107.NEF'$'\n''355b0664'$'\t''DSC_0108.NEF'$'\n''201e3b02'$'\t''DSC_0109.NEF'$'\n''09456d16'$'\t''DSC_0110.NEF'$'\n''1bfa57da'$'\t''DSC_0111.NEF'$'\n''7171b5b8'$'\t''DSC_0112.NEF'$'\n''6c29ae1a'$'\t''DSC_0113.NEF'$'\n''92861cfd'$'\t''DSC_0114.NEF'$'\n''ed24a0a5'$'\t''DSC_0115.NEF'$'\n''2583d832'$'\t''DSC_0116.NEF'$'\n''6a45e5c5'$'\t''DSC_0117.NEF.mov': File name too long
DSC_0051.NEF'$'\n''ac3eba1e'$'\t''DSC_0052.NEF'$'\n''c5052ad9'$'\t''DSC_0053.NEF'$'\n''80c3ee64'$'\t''DSC_0054.NEF'$'\n''d17f3177'$'\t''DSC_0055.NEF'$'\n''53f51ccf'$'\t''DSC_0056.NEF'$'\n''f91427af'$'\t''DSC_0057.NEF'$'\n''0d596f23'$'\t''DSC_0058.NEF'$'\n''fc378e62'$'\t''DSC_0059.NEF'$'\n''c72be5b3'$'\t''DSC_0060.NEF'$'\n''8bf29954'$'\t''DSC_0061.NEF'$'\n''f1193bbf'$'\t''DSC_0062.NEF'$'\n''d4460f24'$'\t''DSC_0063.NEF'$'\n''1e7b1c07'$'\t''DSC_0064.NEF'$'\n''3cc1cbd2'$'\t''DSC_0065.NEF'$'\n''ae935236'$'\t''DSC_0066.NEF'$'\n''f0ff02c1'$'\t''DSC_0067.NEF'$'\n''a16c6e58'$'\t''DSC_0068.NEF'$'\n''57ae8019'$'\t''DSC_0069.NEF'$'\n''82fc94df'$'\t''DSC_0070.NEF'$'\n''2ac41f26'$'\t''DSC_0071.NEF'$'\n''76b0493a'$'\t''DSC_0072.NEF'$'\n''9791ccf7'$'\t''DSC_0073.NEF'$'\n''eac3e7aa'$'\t''DSC_0074.NEF'$'\n''14f7c55c'$'\t''DSC_0075.NEF'$'\n''86df85b0'$'\t''DSC_0076.NEF'$'\n''d23ebeb8'$'\t''DSC_0077.NEF'$'\n''b1f51ea1'$'\t''DSC_0078.NEF'$'\n''1fb307bc'$'\t''DSC_0079.NEF'$'\n''91c17294'$'\t''DSC_0080.NEF'$'\n''c590cfb0'$'\t''DSC_0081.NEF'$'\n''9fc1eaad'$'\t''DSC_0082.NEF'$'\n''31de2e7c'$'\t''DSC_0083.NEF'$'\n''b4858068'$'\t''DSC_0084.NEF'$'\n''04371839'$'\t''DSC_0085.NEF'$'\n''fc440b4a'$'\t''DSC_0086.NEF'$'\n''9de00d44'$'\t''DSC_0087.NEF'$'\n''b9ab2214'$'\t''DSC_0088.NEF'$'\n''4c6f37c8'$'\t''DSC_0089.NEF'$'\n''14de5216'$'\t''DSC_0090.NEF'$'\n''8a565c42'$'\t''DSC_0091.NEF'$'\n''d05282d6'$'\t''DSC_0092.NEF'$'\n''fc032016'$'\t''DSC_0093.NEF'$'\n''ada77bc0'$'\t''DSC_0094.NEF'$'\n''3e6e288c'$'\t''DSC_0095.NEF'$'\n''6bfdb74a'$'\t''DSC_0096.NEF'$'\n''f2529938'$'\t''DSC_0097.NEF'$'\n''8193fcd9'$'\t''DSC_0098.NEF'$'\n''7786e3e1'$'\t''DSC_0099.NEF'$'\n''f2c36981'$'\t''DSC_0100.NEF'$'\n''b0e548e9'$'\t''DSC_0101.NEF'$'\n''b222e465'$'\t''DSC_0102.NEF'$'\n''b32683ac'$'\t''DSC_0103.NEF'$'\n''8511325d'$'\t''DSC_0104.NEF'$'\n''6ae62bf8'$'\t''DSC_0105.NEF'$'\n''bc15a457'$'\t''DSC_0106.NEF'$'\n''31f00e91'$'\t''DSC_0107.NEF'$'\n''355b0664'$'\t''DSC_0108.NEF'$'\n''201e3b02'$'\t''DSC_0109.NEF'$'\n''09456d16'$'\t''DSC_0110.NEF'$'\n''1bfa57da'$'\t''DSC_0111.NEF'$'\n''7171b5b8'$'\t''DSC_0112.NEF'$'\n''6c29ae1a'$'\t''DSC_0113.NEF'$'\n''92861cfd'$'\t''DSC_0114.NEF'$'\n''ed24a0a5'$'\t''DSC_0115.NEF'$'\n''2583d832'$'\t''DSC_0116.NEF'$'\n''6a45e5c5'$'\t''DSC_0117.NEF.mov': File name too long
\n''d23ebeb8'$'\t''DSC_0077.NEF'$'\n''b1f51ea1'$'\t''DSC_0078.NEF'$'\n''1fb307bc'$'\t''DSC_0079.NEF'$'\n''91c17294'$'\t''DSC_0080.NEF'$'\n''c590cfb0'$'\t''DSC_0081.NEF'$'\n''9fc1eaad'$'\t''DSC_0082.NEF'$'\n''31de2e7c'$'\t''DSC_0083.NEF'$'\n''b4858068'$'\t''DSC_0084.NEF'$'\n''04371839'$'\t''DSC_0085.NEF'$'\n''fc440b4a'$'\t''DSC_0086.NEF'$'\n''9de00d44'$'\t''DSC_0087.NEF'$'\n''b9ab2214'$'\t''DSC_0088.NEF'$'\n''4c6f37c8'$'\t''DSC_0089.NEF'$'\n''14de5216'$'\t''DSC_0090.NEF'$'\n''8a565c42'$'\t''DSC_0091.NEF'$'\n''d05282d6'$'\t''DSC_0092.NEF'$'\n''fc032016'$'\t''DSC_0093.NEF'$'\n''ada77bc0'$'\t''DSC_0094.NEF'$'\n''3e6e288c'$'\t''DSC_0095.NEF'$'\n''6bfdb74a'$'\t''DSC_0096.NEF'$'\n''f2529938'$'\t''DSC_0097.NEF'$'\n''8193fcd9'$'\t''DSC_0098.NEF'$'\n''7786e3e1'$'\t''DSC_0099.NEF'$'\n''f2c36981'$'\t''DSC_0100.NEF'$'\n''b0e548e9'$'\t''DSC_0101.NEF'$'\n''b222e465'$'\t''DSC_0102.NEF'$'\n''b32683ac'$'\t''DSC_0103.NEF'$'\n''8511325d'$'\t''DSC_0104.NEF'$'\n''6ae62bf8'$'\t''DSC_0105.NEF'$'\n''bc15a457'$'\t''DSC_0106.NEF'$'\n''31f00e91'$'\t''DSC_0107.NEF'$'\n''355b0664'$'\t''DSC_0108.NEF'$'\n''201e3b02'$'\t''DSC_0109.NEF'$'\n''09456d16'$'\t''DSC_0110.NEF'$'\n''1bfa57da'$'\t''DSC_0111.NEF'$'\n''7171b5b8'$'\t''DSC_0112.NEF'$'\n''6c29ae1a'$'\t''DSC_0113.NEF'$'\n''92861cfd'$'\t''DSC_0114.NEF'$'\n''ed24a0a5'$'\t''DSC_0115.NEF'$'\n''2583d832'$'\t''DSC_0116.NEF'$'\n''6a45e5c5'$'\t''DSC_0117.NEF.mov': File name too long

I want all files to be stored in one directory with a unique name. Any improvement, elegant solution or alternative is welcome!

6
  • Are the folders under the same directory? – schrodigerscatcuriosity Jan 10 at 21:51
  • @schrodigerscatcuriosity I am not sure what makes those two different. All files are in one place (directory) on my Linux machine after I move them from SD card. – Igor V. Jan 10 at 21:54
  • But how could you have duplicate names in the same directory, unless I'm not understanding you. – schrodigerscatcuriosity Jan 10 at 21:56
  • A quick web search tells that the EXIF data could contain a finer time than just seconds, there's SubSecTime, SubSecTimeOriginal, and SubSecTimeDigitized which should contain the fractional seconds of ModifyDate, DateTimeOriginal, and CreateDate, respectively. exiftool.org/TagNames/EXIF.html Can you check if your files have anything useful in those fields? – ilkkachu Jan 10 at 21:58
  • @schrodigerscatcuriosity Conflict emerges in the process of renaming and moving files. As I said in the question, exiftool names the file after the time and date of when the picture is taken, down to a second. But I can make many pictures in one second and then all of them will have the same name. That is why I tried to differentiate them by adding some kind of hash value, randomizing them in that way. – Igor V. Jan 10 at 21:59
2

The way you're doing it runs crc32 on all files at the same time, producing one string with all the checksums and filenames. That's the string you see that mv complains about.

So, run crc32 inside the loop. Assuming your files are in subdirectories of the current directory (so, ./dir0001/DCIM_0000.JPG, ./dir0002/DCIM_0123.JPG or something like that) and you want to put them in destdir/:

#!/bin/bash
shopt -s globstar
for file in **/*.JPG; do
    crc=$(crc32 "$file")
    date=$(exiftool -d "%Y%m%d-%H%M%S" -CreateDate "$file" | awk '{print $4}')
    basename=$(basename "$file" .JPG)            # remove directory and extension
    newname="destdir/$basename-$date-$crc.jpg"   # piece together a new name
    echo mv -nv "$file" "$newname"
done

The ** is a nonstandard extension that runs the glob for the whole directory tree. You could also use */*.JPG to just look for files in the immediate subdirectories.

Similarly to $date, you could add another variable for the subsecond times and include that in how newname is formed:

subsec=$(exiftool -d "%Y%m%d-%H%M%S" -SubSecTimeDigitized "$file" | awk '{print $4}')
newname="destination/$basename-$date-$subsec-$crc.jpg"

Or something like that. Check the output for your files.

Remove the echo from the mv once you're satisfied that the script works correctly.

0

I think this could work, at least in my tests, if I understand correctly:

c=$(($(ls /target/dir | wc -l)+1))
for i in *.JPG; do 
  mv "$i" "/target/dir/$c.JPG"
  ((++c))
done

So you set the counter to the number of files in the target directory. Say at first is empty, the number would be 0, and add 1. You enter the directory from wich you want to move, and rename the files according to the counter that adds 1 in each loop. Then you would have for example:

1.JPG
2.JPG
3.JPG

Run the command again from another directory, now the counter would be 4, so the result would be:

1.JPG
2.JPG
3.JPG
4.JPG
5.JPG
6.JPG
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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