Last active
May 11, 2017 03:40
-
-
Save southp/44ee63174b9a4e9debe3eac5fe2b2718 to your computer and use it in GitHub Desktop.
Group files under the target directory into yyyy-mm date directories.
This file contains 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 characters
#!/bin/sh | |
target_dir=$1 | |
if [ ! "$target_dir" ]; then | |
echo "Usage: $0 <target dir>" | |
exit 0 | |
fi | |
if [ ! -d "$target_dir" ]; then | |
echo "The target dir $target_dir does not exist." | |
exit 0 | |
fi | |
cd "$target_dir" | |
file_list=$(find "$PWD" -type f) | |
IFS=$'\n' | |
for file in $file_list; do | |
if [ "$file" == "$0" ]; then | |
continue | |
fi | |
date=$(stat -f "%Sm" -t "%Y-%m" "$file") | |
mkdir -p $date | |
cp -pv "$file" $date | |
rm "$file" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment