Bash
如何將文件重命名為其創建日期和雜湊值組合以實現唯一的文件名?
我有一堆用我的Nikon DSLR製作的文件,命名為
.JPG
,.NEF
等等。達到一定數量後,將創建新目錄並重新開始計數,當我將它們移動到一個大目錄時會導致重複。.MOV``DSC_0001.JPG``DSC_0002.JPG
我想出了,使用,如何使用循環和
bash
創建日期之後命名它們:for``exiftool
for i in *.JPG do mv -nv "$i" "$(exiftool -d "%Y%m%d-%H%M%S" -CreateDate "$i" | awk '{print $4".jpg"}') done
一種方法會產生另一個問題,我意識到為時已晚,並且在此過程中失去了大約 100 個文件 - 有時在一秒鐘內拍攝了不止一張照片,我找不到一種簡單的方法來附加小於一秒的單元,保持文件名可讀。
所以我想附加文件的校驗和,例如 CRC32,一些簡短且相當隨機的東西,並造成了這個怪物:
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
它與目錄中的一個文件一起使用,但在我擁有的所有照片的主目錄中應用時會產生這些錯誤消息:
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
我希望所有文件都儲存在一個具有唯一名稱的目錄中。歡迎任何改進、優雅的解決方案或替代方案!
你這樣做的方式同時
crc32
在所有文件上執行,產生一個包含所有校驗和和文件名的字元串。這就是您看到的mv
抱怨的字元串。因此,在循環內執行 crc32。假設您的文件位於目前目錄的子目錄中(so、
./dir0001/DCIM_0000.JPG
或./dir0002/DCIM_0123.JPG
類似的東西),並且您希望將它們放入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
這
**
是為整個目錄樹執行 glob 的非標準擴展。您也可以使用*/*.JPG
僅在直接子目錄中查找文件。與 類似
$date
,您可以為亞秒時間添加另一個變數,並將其包含在如何newname
形成中:subsec=$(exiftool -d "%Y%m%d-%H%M%S" -SubSecTimeDigitized "$file" | awk '{print $4}') newname="destination/$basename-$date-$subsec-$crc.jpg"
或類似的東西。檢查文件的輸出。
一旦您對腳本正常工作感到滿意,請
echo
從 中刪除。mv