Created
July 10, 2016 01:30
-
-
Save yuchunc/37dc055eea17d24cfefa539a88f1e8b1 to your computer and use it in GitHub Desktop.
Shell Script File Organization
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 characters
#!/bin/zsh | |
UNSORTED_DIR=./sample_files/* | |
MEMORIA_DIR=./memoria | |
OTHER_DIR=./other_files | |
image_formats="jpg|jpeg|jif|jfif|jp2|jpx|j2k|j2c|tif|gif|pfx|pcd|png" | |
video_formats="3g2|3gp|asf|avi|flv|m4v|mov|mp4|mpg|rm|srt|swf|vob|wmv" | |
for some_file in $UNSORTED_DIR | |
do | |
year=$(date -r "$some_file" +%Y) | |
date=$(date -r "$some_file" +%Y-%m-%d) | |
if file --mime-type "$some_file" | egrep -wi "$image_formats|$video_formats" | |
then | |
$dir_name="$MEMORIA_DIR/$year/$date" | |
else | |
$dir_name="$OTHER_DIR/$year/$date" | |
fi | |
mkdir -p $dir_name | |
cp -- "$some_file" "$dir_name/" | |
echo "$some_file" >> "$dir_name/file_list.txt" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment