Created
June 2, 2023 17:37
-
-
Save aaronshaf/de35e048b9b7e46b975a5ed397e3ac7a to your computer and use it in GitHub Desktop.
sift files into folders by year (or year and month)
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/bash | |
## this script moves all files (not folders) in ~/Documents into folder called ~/Documents/[year] | |
## where [year] is the year the file was created | |
# Find files with extensions and move them into appropriate year folders | |
find ~/Documents -maxdepth 1 ! -name ".*" -name "*.*" | while IFS= read -r file; do | |
# Extract the year from the file's creation timestamp | |
year=$(stat -f "%Sm" -t "%Y" "$file") | |
# Create the year folder if it doesn't exist | |
mkdir -p "$HOME/Documents/$year" | |
# Move the file into the year folder | |
mv "$file" "$HOME/Documents/$year/" | |
echo "Moved file: $file to $HOME/Documents/$year/" | |
done |
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/bash | |
# Find files with extensions and move them into appropriate year-month folders | |
find ~/Downloads -maxdepth 1 ! -name ".*" -name "*.*" | while IFS= read -r file; do | |
# Extract the year and month from the file's modification timestamp | |
year=$(stat -f "%Sm" -t "%Y" "$file") | |
month=$(stat -f "%Sm" -t "%m" "$file") | |
# Create the year-month folder if it doesn't exist | |
mkdir -p "$HOME/Downloads/$year-$month" | |
# Move the file into the year-month folder | |
mv "$file" "$HOME/Downloads/$year-$month/" | |
echo "Moved file: $file to $HOME/Downloads/$year-$month/" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment