Last active
December 12, 2021 15:05
Revisions
-
hobroker revised this gist
Dec 12, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,8 +12,8 @@ target="$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" # list files only, with the year # example: # 2020 image.jpg # 2021 some_filename with space.jpg files="$(ls -l --time-style=+%Y $target | grep '^-' | tr -s ' ' | cut -d " " -f 6- | awk NF)" while IFS= read -r line; do -
hobroker created this gist
Dec 12, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #!/usr/bin/env bash # # Usage: group.sh target_directory # Result: # target_directory/2020/...files from 2020 # target_directory/2021/...files from 2021 # set -e target="$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" # list files only, with the year # example: # 2020 image.jpg # 2021 some_filename with space.jpg files="$(ls -l --time-style=+%Y $target | grep '^-' | tr -s ' ' | cut -d " " -f 6- | awk NF)" while IFS= read -r line; do IFS=" " read year filename <<< "$line" dir="$target/$year" file="$target/$filename" printf "%s <- %s" $dir $file mkdir -p "$dir" mv "$file" "$dir" printf " $\n" done <<< "$files"