Skip to main content
added 4 characters in body
Source Link
Edgar Magallon
  • 5.1k
  • 3
  • 15
  • 29

Update: If I am wrong with this answer please let me now.

I'm not sure if file system's modification date metadata is equivalent to exitf modification date metadata. I tested with exiftool and the dates are equivalent, so it makes me think is I can use touch for manipulating that metadata.

Solution:

First you should get the modification date of the file by using stat command:

filedate=$(stat -c '%y' "/path/to/file" | cut -d' ' -f1)

Now it will be replaced the month with another one. For that, you can use awk:

newDate=$(awk -v month="Jun" -F '-' '{print $1"-"month"-"$3}' <<< $filedate )

And with touch command you can change the creationmodification date:

touch -m -d $newDate /path/to/file
#-m argument is used to change modification time
#-d is used to specify the new date

Finally, if you want to change files recursively you can use find and the code provided before should be in a script file:

script.sh:

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="Dec" #here you specify the month 
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

And with find you can use:

find /path/to/your_directory -type f -exec ./script.sh {} \;

If you want to specify the month in the find command, you can pass it to the script.sh as parameter:

Therefore, the code would now became:

script.sh

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="$2"
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

find command

find . -type f -exec ./script {} "Nov" \;

Update: If I am wrong with this answer please let me now.

I'm not sure if file system's modification date metadata is equivalent to exitf modification date metadata. I tested with exiftool and the dates are equivalent, so it makes me think is I can use touch for manipulating that metadata.

Solution:

First you should get the modification date of the file by using stat command:

filedate=$(stat -c '%y' "/path/to/file" | cut -d' ' -f1)

Now it will be replaced the month with another one. For that, you can use awk:

newDate=$(awk -v month="Jun" -F '-' '{print $1"-"month"-"$3}' <<< $filedate )

And with touch command you can change the creation date:

touch -m -d $newDate /path/to/file
#-m argument is used to change modification time
#-d is used to specify the new date

Finally, if you want to change files recursively you can use find and the code provided before should be in a script file:

script.sh:

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="Dec" #here you specify the month 
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

And with find you can use:

find /path/to/your_directory -type f -exec ./script.sh {} \;

If you want to specify the month in the find command, you can pass it to the script.sh as parameter:

Therefore, the code would now became:

script.sh

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="$2"
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

find command

find . -type f -exec ./script {} "Nov" \;

Update: If I am wrong with this answer please let me now.

I'm not sure if file system's modification date metadata is equivalent to exitf modification date metadata. I tested with exiftool and the dates are equivalent, so it makes me think is I can use touch for manipulating that metadata.

Solution:

First you should get the modification date of the file by using stat command:

filedate=$(stat -c '%y' "/path/to/file" | cut -d' ' -f1)

Now it will be replaced the month with another one. For that, you can use awk:

newDate=$(awk -v month="Jun" -F '-' '{print $1"-"month"-"$3}' <<< $filedate )

And with touch command you can change the modification date:

touch -m -d $newDate /path/to/file
#-m argument is used to change modification time
#-d is used to specify the new date

Finally, if you want to change files recursively you can use find and the code provided before should be in a script file:

script.sh:

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="Dec" #here you specify the month 
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

And with find you can use:

find /path/to/your_directory -type f -exec ./script.sh {} \;

If you want to specify the month in the find command, you can pass it to the script.sh as parameter:

Therefore, the code would now became:

script.sh

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="$2"
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

find command

find . -type f -exec ./script {} "Nov" \;
added 327 characters in body
Source Link
Edgar Magallon
  • 5.1k
  • 3
  • 15
  • 29

Update: If I am wrong with this answer please let me now.

I'm not sure if file system's modification date metadata is equivalent to exitf modification date metadata. I tested with exiftool and the dates are equivalent, so it makes me think is I can use touch for manipulating that metadata.

Solution:

First you should get the modification date of the file by using stat command:

filedate=$(stat -c '%y' "/path/to/file" | cut -d' ' -f1)

Now it will be replaced the month with another one. For that, you can use awk:

newDate=$(awk -v month="Jun" -F '-' '{print $1"-"month"-"$3}' <<< $filedate )

And with touch command you can change the creation date:

touch -m -d $newDate /path/to/file
#-m argument is used to change modification time
#-d is used to specify the new date

Finally, if you want to change files recursively you can use find and the code provided before should be in a script file:

script.sh:

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="Dec" #here you specify the month 
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

And with find you can use:

find /path/to/your_directory -type f -exec ./script.sh {} \;

If you want to specify the month in the find command, you can pass it to the script.sh as parameter:

Therefore, the code would now became:

script.sh

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="$2"
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

find command

find . -type f -exec ./script {} "Nov" \;

First you should get the modification date of the file by using stat command:

filedate=$(stat -c '%y' "/path/to/file" | cut -d' ' -f1)

Now it will be replaced the month with another one. For that, you can use awk:

newDate=$(awk -v month="Jun" -F '-' '{print $1"-"month"-"$3}' <<< $filedate )

And with touch command you can change the creation date:

touch -m -d $newDate /path/to/file
#-m argument is used to change modification time
#-d is used to specify the new date

Finally, if you want to change files recursively you can use find and the code provided before should be in a script file:

script.sh:

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="Dec" #here you specify the month 
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

And with find you can use:

find /path/to/your_directory -type f -exec ./script.sh {} \;

If you want to specify the month in the find command, you can pass it to the script.sh as parameter:

Therefore, the code would now became:

script.sh

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="$2"
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

find command

find . -type f -exec ./script {} "Nov" \;

Update: If I am wrong with this answer please let me now.

I'm not sure if file system's modification date metadata is equivalent to exitf modification date metadata. I tested with exiftool and the dates are equivalent, so it makes me think is I can use touch for manipulating that metadata.

Solution:

First you should get the modification date of the file by using stat command:

filedate=$(stat -c '%y' "/path/to/file" | cut -d' ' -f1)

Now it will be replaced the month with another one. For that, you can use awk:

newDate=$(awk -v month="Jun" -F '-' '{print $1"-"month"-"$3}' <<< $filedate )

And with touch command you can change the creation date:

touch -m -d $newDate /path/to/file
#-m argument is used to change modification time
#-d is used to specify the new date

Finally, if you want to change files recursively you can use find and the code provided before should be in a script file:

script.sh:

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="Dec" #here you specify the month 
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

And with find you can use:

find /path/to/your_directory -type f -exec ./script.sh {} \;

If you want to specify the month in the find command, you can pass it to the script.sh as parameter:

Therefore, the code would now became:

script.sh

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="$2"
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

find command

find . -type f -exec ./script {} "Nov" \;
Post Undeleted by Edgar Magallon
Post Deleted by Edgar Magallon
Post Undeleted by Edgar Magallon
Post Deleted by Edgar Magallon
Source Link
Edgar Magallon
  • 5.1k
  • 3
  • 15
  • 29

First you should get the modification date of the file by using stat command:

filedate=$(stat -c '%y' "/path/to/file" | cut -d' ' -f1)

Now it will be replaced the month with another one. For that, you can use awk:

newDate=$(awk -v month="Jun" -F '-' '{print $1"-"month"-"$3}' <<< $filedate )

And with touch command you can change the creation date:

touch -m -d $newDate /path/to/file
#-m argument is used to change modification time
#-d is used to specify the new date

Finally, if you want to change files recursively you can use find and the code provided before should be in a script file:

script.sh:

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="Dec" #here you specify the month 
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

And with find you can use:

find /path/to/your_directory -type f -exec ./script.sh {} \;

If you want to specify the month in the find command, you can pass it to the script.sh as parameter:

Therefore, the code would now became:

script.sh

#! /usr/bin/env bash

filedate=$(stat -c '%y' "$1" | cut -d' ' -f1)

newMonth="$2"
newDate=$(awk -v month=$newMonth -F '-' '{print $3"-"month"-"$1}' <<< $filedate )

touch -m -d $newDate $1

find command

find . -type f -exec ./script {} "Nov" \;