Last active
June 29, 2018 02:28
-
-
Save edpichler/5b0bff445512e46bbb79f281ee0d3634 to your computer and use it in GitHub Desktop.
Unix commands.
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
#Organize files by date: | |
for x in `find . -type f -name "*.*"` ; do | |
year=$(date -r "$x" +%Y) | |
monthyear=$(date -r "$x" +%m-%Y) | |
day=$(date -r "$x" +%Y-%m-%d) | |
foldername="$year/$monthyear/" | |
mkdir -p "$foldername" | |
mv -- "$x" "$foldername" | |
echo "Moving file $x to $foldername" #>> logs.txt | |
done | |
#Rename files using its date: | |
for x in `find . -type f -name "*.*"` ; do | |
append=$(date -r "$x" +"_Date_%d-%m-%Y_Time_%Hhs_%Mm") | |
filenameWithoutExtension="${x%.*}" | |
extension="${x##*.}" | |
newfilename="$filenameWithoutExtension$append.$extension" | |
echo "renaming file $x to $newfilename" #>> logs.txt | |
mv $x $newfilename | |
done | |
#Rename files to add parent dir as file prefix (bug) | |
for x in `find . -type f -name "*.*"` ; do | |
pathfolder=$(dirname "$x") | |
dir=$(basename "$pathfolder") | |
file=$(basename "$x") | |
newfilename="$pathfolder/$(basename "$pathfolder")_$(basename "$x")" | |
echo $newfilename | |
#mv $x $newfilename | |
done | |
#Rename all files in folders and subfolders and add a Prefix (bug, it move file location) | |
for x in `find . -type f -name "*.*"` ; do mv "$x" "WhatsApp_$(basename "$x")" ; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment