0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

一眼レフで撮った写真をbashで整理する

Last updated at Posted at 2023-07-19

初投稿です。

目標 

撮影日ごとにファイル分け

SDカードに記録されたファイル構造

./100CANON/IMG_0001.JPG IMG_0002.JPG ...

それぞれの写真に日付と時刻を挿入

changename.sh
#!/bin/bash
path="./100CANON/"
ls -1  $path> list1.txt
while read fn; do
#set date
tmp1=$(stat -c%z $path$fn |awk '{print $1}'|tr -d '-') 
#set time
tmp2=$(stat -c%z $path$fn |awk '{print $2}'|awk -F'[.]' '{print $1}'|tr -d ':')

echo $tmp1"_"$tmp2"_"$fn  #for check
mv $path$fn $path$tmp1"_"$tmp2"_"$fn

done < list1.txt
rm list1.txt

stat -c%z でファイルの最終修正日時を取得
%ZはEpoch(1970年1月1日0時0分0秒)からの秒数

日付ごとのフォルダに写真の移動

move.sh
#!/bin/bash
path="./100CANON/"
path_new="./CANON_moved/"    #set new file name
mkdir $path_new
ls -1  $path> list1.txt
while read fn; do
tmp1=$(echo $fn | head -c 8)
mkdir $path_new$tmp1            #Create files by date
mv $path$fn $path_new$tmp1

done < list1.txt
rm list1.txt
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?