고유한 파일 이름을 얻기 위해 파일 이름을 생성 날짜와 해시 값 조합으로 바꾸는 방법은 무엇입니까?

고유한 파일 이름을 얻기 위해 파일 이름을 생성 날짜와 해시 값 조합으로 바꾸는 방법은 무엇입니까?

나는 그것들을 잔뜩 갖고 있고 .JPG, 내 것으로 만든 파일도 .NEF있다.MOV니콘 SLR 카메라DSC_0001.JPG, 이름 DSC_0002.JPG등 특정 숫자에 도달하면 새 디렉토리가 생성되고 계산이 다시 시작되므로 하나의 큰 디렉토리로 이동할 때 중복이 발생합니다.

bash루프를 사용하고 생성 날짜 뒤에 이름을 지정하는 방법을 알아냈습니다 .forexiftool

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

이 방법은 제가 너무 늦게 깨달았고 그 과정에서 약 100개의 파일을 잃어버렸다는 또 다른 문제를 야기했습니다. 때로는 1초에 두 장 이상의 사진이 찍히기도 하고 1초 미만의 단위를 결합하는 간단한 방법을 찾을 수 없었습니다. 읽을 수 있는 파일 이름.

그래서 저는 파일의 체크섬(예: 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

모든 파일을 고유한 이름을 가진 디렉터리에 저장하고 싶습니다. 개선 사항, 우아한 솔루션 또는 대안을 환영합니다!

답변1

이 방법은 crc32모든 파일에서 동시에 실행되어 모든 체크섬과 파일 이름이 포함된 문자열을 생성합니다. 이것은 당신이 불평하는 문자열입니다 mv.

따라서 crc32는 루프 내부에서 실행됩니다. 귀하의 파일이 현재 디렉터리( ./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, 1초 미만의 시간 동안 다른 변수를 추가하고 이를 newname형성 방법에 포함시킬 수 있습니다.

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

또는 그런 것. 파일의 출력을 확인하십시오.

스크립트가 제대로 작동하는 것으로 확인되면 echo에서 해당 스크립트를 제거하십시오.mv

답변2

내가 올바르게 이해했다면 적어도 내 테스트에서는 이것이 작동한다고 생각합니다.

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

따라서 카운터를 대상 디렉터리의 파일 수로 설정합니다. 비어 있다고 가정하면 숫자는 0이 되고 1이 추가됩니다. 이동할 디렉터리를 입력하면 루프를 통과할 때마다 1씩 증가하는 카운터에 따라 파일 이름이 변경됩니다. 그러면 예를 들어 다음과 같습니다.

1.JPG
2.JPG
3.JPG

다른 디렉터리에서 명령을 다시 실행하면 이제 카운터는 4가 되므로 결과는 다음과 같습니다.

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

관련 정보