This is my current code:
Base_DIR=/file/path
other= /folder/path
find "Base_DIR" -type f -name "*.txt"
while IFS= read -r file; do
year="$(date -d "$(stat -c %y "$file")" +%Y
month="$(date -d "$(stat -c %y "$file")" +%m
day="$(date -d "$(stat -c %y "$file")" +%d
[[ ! -d "$other/$year/$month/$day" ]] && mkdir -p "$other/$year/$month/$day";
mv "$file" "$other/$year/$month/$day`
So it basically finds the files from different sub-directories and moves the file into a different folder while creating a folder depending on the year, month and day of when the file was last modified.
My question is how can i add to this so when i move files with the same name it will automatically rename the file to, for example file(1).txt. Right now the code only copies 1 of the files and not both.
Thank you.
=and nodoneat the end of the loop. You're presumably wanting to pipe the result of thefindcommand into the loop, right? You also seem to miss$on$Base_DIR.shellcheck.