How can I change the date modified/created of a file?











up vote
200
down vote

favorite
69












Is there a way to change the date when a file was modified/created (which is shown in Nautilus or with the ls -l command)? Ideally I am looking for a command which can change the date/time stamps of a whole bunch of files to a certain amount of time earlier or later (e.g. +8 hours or -4 days etc.).










share|improve this question




























    up vote
    200
    down vote

    favorite
    69












    Is there a way to change the date when a file was modified/created (which is shown in Nautilus or with the ls -l command)? Ideally I am looking for a command which can change the date/time stamps of a whole bunch of files to a certain amount of time earlier or later (e.g. +8 hours or -4 days etc.).










    share|improve this question


























      up vote
      200
      down vote

      favorite
      69









      up vote
      200
      down vote

      favorite
      69






      69





      Is there a way to change the date when a file was modified/created (which is shown in Nautilus or with the ls -l command)? Ideally I am looking for a command which can change the date/time stamps of a whole bunch of files to a certain amount of time earlier or later (e.g. +8 hours or -4 days etc.).










      share|improve this question















      Is there a way to change the date when a file was modified/created (which is shown in Nautilus or with the ls -l command)? Ideally I am looking for a command which can change the date/time stamps of a whole bunch of files to a certain amount of time earlier or later (e.g. +8 hours or -4 days etc.).







      file-properties timestamp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 7 '12 at 7:02









      david6

      13.6k43144




      13.6k43144










      asked Sep 22 '11 at 5:32









      snej

      1,001283




      1,001283






















          7 Answers
          7






          active

          oldest

          votes

















          up vote
          271
          down vote













          As long as you are the owner of the file (or root), you can change the modification time of a file using the touch command:



          touch filename


          By default this will set the file's modification time to the current time, but there are a number of flags, such as the -d flag to pick a particular date. So for example, to set a file as being modified two hours before the present, you could use the following:



          touch -d "2 hours ago" filename


          If you want to modify the file relative to its existing modification time instead, the following should do the trick:



          touch -d "$(date -R -r filename) - 2 hours" filename


          If you want to modify a large number of files, you could use the following:



          find DIRECTORY -print | while read filename; do
          # do whatever you want with the file
          touch -d "$(date -R -r "$filename") - 2 hours" "$filename"
          done


          You can change the arguments to find to select only the files you are interested in. If you only want to update the file modification times relative to the present time, you can simplify this to:



          find DIRECTORY -exec touch -d "2 hours ago" {} +


          This form isn't possible with the file time relative version because it uses the shell to form the arguments to touch.



          As far as the creation time goes, most Linux file systems do not keep track of this value. There is a ctime associated with files, but it tracks when the file metadata was last changed. If the file never has its permissions changed, it might happen to hold the creation time, but this is a coincidence. Explicitly changing the file modification time counts as a metadata change, so will also have the side effect of updating the ctime.






          share|improve this answer























          • To mention the simpler case when all files are in the same folder: touch -d "2 hours ago" /path/*.txt, for example.
            – enzotib
            Sep 22 '11 at 7:05






          • 1




            I'd also add that changing the ctime is not possible in any standard way.
            – arrange
            Sep 22 '11 at 7:40










          • Is this all POSIX ?
            – user1011471
            Sep 10 '15 at 16:42






          • 1




            The information about ctime as a metadata change time is from POSIX. I don't know if the shell fragments in my answer would work with strict POSIX shell utilities. But they definitely work on Ubuntu, which is the context for answers on this site.
            – James Henstridge
            Sep 15 '15 at 22:27






          • 1




            On OSX, you may want to use gtouch via brew install coreutils.
            – Nobu
            May 23 '16 at 22:50


















          up vote
          42
          down vote













          Thanks for the help.
          This worked for me:



          In the terminal go to the directory for date-edit.
          Then type:



          find -print | while read filename; do
          # do whatever you want with the file
          touch -t 201203101513 "$filename"
          done


          You wil see a ">" after you hit enter, exept for the last time -> "done".



          Note:
          You may want to change "201203101513"



          "201203101513" = is the date you want for all the files in this directory.



          See my webpage






          share|improve this answer























          • it doesn't work as expected if a file name contains blank spaces
            – Angel
            Aug 2 '16 at 7:56


















          up vote
          23
          down vote













          Easiest way - accessed and modified will be the same:



          touch -a -m -t 201512180130.09 fileName.ext


          Where:



          -a = accessed
          -m = modified
          -t = timestamp - use [[CC]YY]MMDDhhmm[.ss] time format


          If you wish to use NOW just drop the -t and the timestamp.



          To verify they are all the same:
          stat fileName.ext



          See: touch man






          share|improve this answer























          • I tried to verify it using stat, but neither of the touch flags lead to a correct result. Modification date is adjusted, but changed and accessed date are actually changed to NOW
            – Xerus
            Mar 19 at 20:51


















          up vote
          7
          down vote













          Touch can reference a file's date all by itself, no need to call date or use command substitution. Here's a bit from touch's info page:



          `-r FILE' `--reference=FILE'
          Use the times of the reference FILE instead of the current time.
          If this option is combined with the `--date=TIME' (`-d TIME')
          option, the reference FILE's time is the origin for any relative
          TIMEs given, but is otherwise ignored. For example, `-r foo -d
          '-5 seconds'' specifies a time stamp equal to five seconds before
          the corresponding time stamp for `foo'. If FILE is a symbolic
          link, the reference timestamp is taken from the target of the
          symlink, unless `-h' was also in effect.


          For example, to add 8 hours to a file's date (filename of file quoted just in case of spaces, etc):



          touch -r "file" -d '+8 hour' "file"


          Using a loop over all files in the current dir:



          for i in *; do touch -r "$i" -d '+8 hour' "$i"; done


          I've heard that using a * and letting for pick the filenames itself is safer, but using find -print0 | xargs -0 touch ... should handle most crazy characters like newlines, spaces, quotes, backslashes in a filename. (PS. try not to use crazy characters in filenames in the first place).



          For example, to find all files in thatdir whose filenames start with an s, and add one day to those file's modified timestamp, use:



          find thatdir -name "s*" -print0 | xargs -0 -I '{}' touch -r '{}' -d '+1 day' '{}'





          share|improve this answer




























            up vote
            2
            down vote













            This little script at least works for me



            #!/bin/bash

            # find specific files
            files=$(find . -type f -name '*.JPG')

            # use newline as file separator (handle spaces in filenames)
            IFS=$'n'

            for f in ${files}
            do
            # read file modification date using stat as seconds
            # adjust date backwards (1 month) using date and print in correct format
            # change file time using touch
            touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
            done





            share|improve this answer

















            • 2




              Adjusting the date of images based on meta info in the image would be pretty useful. ImageMagick's identify can be used. e.g. 'identify -verbose <image> |grep -i date', 'identify -format %[exif:DateTime] <image>' might show '2015:01:08 10:19:10' (not all images have exif data). This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
              – gaoithe
              May 24 '16 at 11:30




















            up vote
            1
            down vote













            It's been a long time since I wrote any kind of Unix program, but I accidentally set the year incorrectly on a bunch of Christmas photos, and I knew if I didn't change the date from 2015 to 2014 it would be a problem later on.



            Maybe, this is an easy task, but I didn't find any simple way to do it.



            I modified a script I found here, which originally was used to modify the date by minus one month.



            Here's the original script:



            #!/bin/bash

            # find specific files
            files=$(find . -type f -name '*.JPG')

            # use newline as file separator (handle spaces in filenames)
            IFS=$'n'

            for f in ${files}
            do
            # read file modification date using stat as seconds
            # adjust date backwards (1 month) using date and print in correct format
            # change file time using touch
            touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
            done


            Here's my modified script that forced the date to the year "2014":



            #!/bin/bash 

            # find specific files
            #files=$(find . -type f -name '*.JPG')

            # use newline as file separator (handle spaces in filenames)
            IFS=$'n'

            for f in $*
            do
            # read file modification date using stat as seconds
            # adjust date backwards (1 month) using date and print in correct format
            # change file time using touch
            touch -t $(date -v +1y -r $(stat -f %m "${f}") +2014%m%d%H%M.%S) "${f}"
            done


            I now realize I could have done a more generic version:



            #!/bin/bash 

            # find specific files
            #files=$(find . -type f -name '*.JPG')

            # use newline as file separator (handle spaces in filenames)
            IFS=$'n'

            for f in $*
            do
            # read file modification date using stat as seconds
            # adjust date backwards (1 month) using date and print in correct format
            # change file time using touch (+1y adds a year "-1y" subtracts a year)
            # Below line subtracts a year
            touch -t $(date -v -1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
            # Below line adds a year
            # touch -t $(date -v +1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
            done


            To use this file you would need to write it and



            chmod +x fn


            to execute:



            ./fn files-to-change


            fn=your-file-name-that-is-your-command



            Example



            ./fn *.JPG


            will change the date by minus one year in the directory where you are.






            share|improve this answer



















            • 1




              Same as above comment. Most .jpg files will have date embedded in meta data aded by camera. This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
              – gaoithe
              May 25 '16 at 9:49


















            up vote
            -6
            down vote













            just change date and time in settings. then save your file, it automatically changes






            share|improve this answer

















            • 3




              Snej is looking for a batch or command line solution that can be used to modify multiple files. Changing system time and date and the modify the files is probably not an ideal solution.
              – fabricator4
              Nov 28 '12 at 9:35










            • too much triiiiiiicky!!!
              – Philippe Gachoud
              Oct 8 '13 at 21:25












            • For those with other OS's brought here via web search, this answer is the simplest way to change the date of a file on Mac OSX ('touch -d' results in 'illegal option').
              – alanning
              Feb 18 '14 at 3:50










            • @alanning: OSX has BSD touch, not GNU touch. Use -t. developer.apple.com/library/mac/documentation/Darwin/Reference/…
              – Dominik R
              Mar 26 '16 at 18:25










            • That may have unforeseen consequences. In a modern OS, lots of files are getting modified behind the scenes all the time. While your date is changed, many other files could get wrong date stamps on them and anything can happen when something else in the system notices that a file is older than expected.
              – Joe
              Apr 9 '17 at 7:11











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f62492%2fhow-can-i-change-the-date-modified-created-of-a-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            7 Answers
            7






            active

            oldest

            votes








            7 Answers
            7






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            271
            down vote













            As long as you are the owner of the file (or root), you can change the modification time of a file using the touch command:



            touch filename


            By default this will set the file's modification time to the current time, but there are a number of flags, such as the -d flag to pick a particular date. So for example, to set a file as being modified two hours before the present, you could use the following:



            touch -d "2 hours ago" filename


            If you want to modify the file relative to its existing modification time instead, the following should do the trick:



            touch -d "$(date -R -r filename) - 2 hours" filename


            If you want to modify a large number of files, you could use the following:



            find DIRECTORY -print | while read filename; do
            # do whatever you want with the file
            touch -d "$(date -R -r "$filename") - 2 hours" "$filename"
            done


            You can change the arguments to find to select only the files you are interested in. If you only want to update the file modification times relative to the present time, you can simplify this to:



            find DIRECTORY -exec touch -d "2 hours ago" {} +


            This form isn't possible with the file time relative version because it uses the shell to form the arguments to touch.



            As far as the creation time goes, most Linux file systems do not keep track of this value. There is a ctime associated with files, but it tracks when the file metadata was last changed. If the file never has its permissions changed, it might happen to hold the creation time, but this is a coincidence. Explicitly changing the file modification time counts as a metadata change, so will also have the side effect of updating the ctime.






            share|improve this answer























            • To mention the simpler case when all files are in the same folder: touch -d "2 hours ago" /path/*.txt, for example.
              – enzotib
              Sep 22 '11 at 7:05






            • 1




              I'd also add that changing the ctime is not possible in any standard way.
              – arrange
              Sep 22 '11 at 7:40










            • Is this all POSIX ?
              – user1011471
              Sep 10 '15 at 16:42






            • 1




              The information about ctime as a metadata change time is from POSIX. I don't know if the shell fragments in my answer would work with strict POSIX shell utilities. But they definitely work on Ubuntu, which is the context for answers on this site.
              – James Henstridge
              Sep 15 '15 at 22:27






            • 1




              On OSX, you may want to use gtouch via brew install coreutils.
              – Nobu
              May 23 '16 at 22:50















            up vote
            271
            down vote













            As long as you are the owner of the file (or root), you can change the modification time of a file using the touch command:



            touch filename


            By default this will set the file's modification time to the current time, but there are a number of flags, such as the -d flag to pick a particular date. So for example, to set a file as being modified two hours before the present, you could use the following:



            touch -d "2 hours ago" filename


            If you want to modify the file relative to its existing modification time instead, the following should do the trick:



            touch -d "$(date -R -r filename) - 2 hours" filename


            If you want to modify a large number of files, you could use the following:



            find DIRECTORY -print | while read filename; do
            # do whatever you want with the file
            touch -d "$(date -R -r "$filename") - 2 hours" "$filename"
            done


            You can change the arguments to find to select only the files you are interested in. If you only want to update the file modification times relative to the present time, you can simplify this to:



            find DIRECTORY -exec touch -d "2 hours ago" {} +


            This form isn't possible with the file time relative version because it uses the shell to form the arguments to touch.



            As far as the creation time goes, most Linux file systems do not keep track of this value. There is a ctime associated with files, but it tracks when the file metadata was last changed. If the file never has its permissions changed, it might happen to hold the creation time, but this is a coincidence. Explicitly changing the file modification time counts as a metadata change, so will also have the side effect of updating the ctime.






            share|improve this answer























            • To mention the simpler case when all files are in the same folder: touch -d "2 hours ago" /path/*.txt, for example.
              – enzotib
              Sep 22 '11 at 7:05






            • 1




              I'd also add that changing the ctime is not possible in any standard way.
              – arrange
              Sep 22 '11 at 7:40










            • Is this all POSIX ?
              – user1011471
              Sep 10 '15 at 16:42






            • 1




              The information about ctime as a metadata change time is from POSIX. I don't know if the shell fragments in my answer would work with strict POSIX shell utilities. But they definitely work on Ubuntu, which is the context for answers on this site.
              – James Henstridge
              Sep 15 '15 at 22:27






            • 1




              On OSX, you may want to use gtouch via brew install coreutils.
              – Nobu
              May 23 '16 at 22:50













            up vote
            271
            down vote










            up vote
            271
            down vote









            As long as you are the owner of the file (or root), you can change the modification time of a file using the touch command:



            touch filename


            By default this will set the file's modification time to the current time, but there are a number of flags, such as the -d flag to pick a particular date. So for example, to set a file as being modified two hours before the present, you could use the following:



            touch -d "2 hours ago" filename


            If you want to modify the file relative to its existing modification time instead, the following should do the trick:



            touch -d "$(date -R -r filename) - 2 hours" filename


            If you want to modify a large number of files, you could use the following:



            find DIRECTORY -print | while read filename; do
            # do whatever you want with the file
            touch -d "$(date -R -r "$filename") - 2 hours" "$filename"
            done


            You can change the arguments to find to select only the files you are interested in. If you only want to update the file modification times relative to the present time, you can simplify this to:



            find DIRECTORY -exec touch -d "2 hours ago" {} +


            This form isn't possible with the file time relative version because it uses the shell to form the arguments to touch.



            As far as the creation time goes, most Linux file systems do not keep track of this value. There is a ctime associated with files, but it tracks when the file metadata was last changed. If the file never has its permissions changed, it might happen to hold the creation time, but this is a coincidence. Explicitly changing the file modification time counts as a metadata change, so will also have the side effect of updating the ctime.






            share|improve this answer














            As long as you are the owner of the file (or root), you can change the modification time of a file using the touch command:



            touch filename


            By default this will set the file's modification time to the current time, but there are a number of flags, such as the -d flag to pick a particular date. So for example, to set a file as being modified two hours before the present, you could use the following:



            touch -d "2 hours ago" filename


            If you want to modify the file relative to its existing modification time instead, the following should do the trick:



            touch -d "$(date -R -r filename) - 2 hours" filename


            If you want to modify a large number of files, you could use the following:



            find DIRECTORY -print | while read filename; do
            # do whatever you want with the file
            touch -d "$(date -R -r "$filename") - 2 hours" "$filename"
            done


            You can change the arguments to find to select only the files you are interested in. If you only want to update the file modification times relative to the present time, you can simplify this to:



            find DIRECTORY -exec touch -d "2 hours ago" {} +


            This form isn't possible with the file time relative version because it uses the shell to form the arguments to touch.



            As far as the creation time goes, most Linux file systems do not keep track of this value. There is a ctime associated with files, but it tracks when the file metadata was last changed. If the file never has its permissions changed, it might happen to hold the creation time, but this is a coincidence. Explicitly changing the file modification time counts as a metadata change, so will also have the side effect of updating the ctime.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 at 16:35









            user2979044

            1033




            1033










            answered Sep 22 '11 at 6:34









            James Henstridge

            30.8k79188




            30.8k79188












            • To mention the simpler case when all files are in the same folder: touch -d "2 hours ago" /path/*.txt, for example.
              – enzotib
              Sep 22 '11 at 7:05






            • 1




              I'd also add that changing the ctime is not possible in any standard way.
              – arrange
              Sep 22 '11 at 7:40










            • Is this all POSIX ?
              – user1011471
              Sep 10 '15 at 16:42






            • 1




              The information about ctime as a metadata change time is from POSIX. I don't know if the shell fragments in my answer would work with strict POSIX shell utilities. But they definitely work on Ubuntu, which is the context for answers on this site.
              – James Henstridge
              Sep 15 '15 at 22:27






            • 1




              On OSX, you may want to use gtouch via brew install coreutils.
              – Nobu
              May 23 '16 at 22:50


















            • To mention the simpler case when all files are in the same folder: touch -d "2 hours ago" /path/*.txt, for example.
              – enzotib
              Sep 22 '11 at 7:05






            • 1




              I'd also add that changing the ctime is not possible in any standard way.
              – arrange
              Sep 22 '11 at 7:40










            • Is this all POSIX ?
              – user1011471
              Sep 10 '15 at 16:42






            • 1




              The information about ctime as a metadata change time is from POSIX. I don't know if the shell fragments in my answer would work with strict POSIX shell utilities. But they definitely work on Ubuntu, which is the context for answers on this site.
              – James Henstridge
              Sep 15 '15 at 22:27






            • 1




              On OSX, you may want to use gtouch via brew install coreutils.
              – Nobu
              May 23 '16 at 22:50
















            To mention the simpler case when all files are in the same folder: touch -d "2 hours ago" /path/*.txt, for example.
            – enzotib
            Sep 22 '11 at 7:05




            To mention the simpler case when all files are in the same folder: touch -d "2 hours ago" /path/*.txt, for example.
            – enzotib
            Sep 22 '11 at 7:05




            1




            1




            I'd also add that changing the ctime is not possible in any standard way.
            – arrange
            Sep 22 '11 at 7:40




            I'd also add that changing the ctime is not possible in any standard way.
            – arrange
            Sep 22 '11 at 7:40












            Is this all POSIX ?
            – user1011471
            Sep 10 '15 at 16:42




            Is this all POSIX ?
            – user1011471
            Sep 10 '15 at 16:42




            1




            1




            The information about ctime as a metadata change time is from POSIX. I don't know if the shell fragments in my answer would work with strict POSIX shell utilities. But they definitely work on Ubuntu, which is the context for answers on this site.
            – James Henstridge
            Sep 15 '15 at 22:27




            The information about ctime as a metadata change time is from POSIX. I don't know if the shell fragments in my answer would work with strict POSIX shell utilities. But they definitely work on Ubuntu, which is the context for answers on this site.
            – James Henstridge
            Sep 15 '15 at 22:27




            1




            1




            On OSX, you may want to use gtouch via brew install coreutils.
            – Nobu
            May 23 '16 at 22:50




            On OSX, you may want to use gtouch via brew install coreutils.
            – Nobu
            May 23 '16 at 22:50












            up vote
            42
            down vote













            Thanks for the help.
            This worked for me:



            In the terminal go to the directory for date-edit.
            Then type:



            find -print | while read filename; do
            # do whatever you want with the file
            touch -t 201203101513 "$filename"
            done


            You wil see a ">" after you hit enter, exept for the last time -> "done".



            Note:
            You may want to change "201203101513"



            "201203101513" = is the date you want for all the files in this directory.



            See my webpage






            share|improve this answer























            • it doesn't work as expected if a file name contains blank spaces
              – Angel
              Aug 2 '16 at 7:56















            up vote
            42
            down vote













            Thanks for the help.
            This worked for me:



            In the terminal go to the directory for date-edit.
            Then type:



            find -print | while read filename; do
            # do whatever you want with the file
            touch -t 201203101513 "$filename"
            done


            You wil see a ">" after you hit enter, exept for the last time -> "done".



            Note:
            You may want to change "201203101513"



            "201203101513" = is the date you want for all the files in this directory.



            See my webpage






            share|improve this answer























            • it doesn't work as expected if a file name contains blank spaces
              – Angel
              Aug 2 '16 at 7:56













            up vote
            42
            down vote










            up vote
            42
            down vote









            Thanks for the help.
            This worked for me:



            In the terminal go to the directory for date-edit.
            Then type:



            find -print | while read filename; do
            # do whatever you want with the file
            touch -t 201203101513 "$filename"
            done


            You wil see a ">" after you hit enter, exept for the last time -> "done".



            Note:
            You may want to change "201203101513"



            "201203101513" = is the date you want for all the files in this directory.



            See my webpage






            share|improve this answer














            Thanks for the help.
            This worked for me:



            In the terminal go to the directory for date-edit.
            Then type:



            find -print | while read filename; do
            # do whatever you want with the file
            touch -t 201203101513 "$filename"
            done


            You wil see a ">" after you hit enter, exept for the last time -> "done".



            Note:
            You may want to change "201203101513"



            "201203101513" = is the date you want for all the files in this directory.



            See my webpage







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 10 '12 at 14:29









            hhlp

            32k1377131




            32k1377131










            answered Mar 10 '12 at 14:21









            EFL

            42143




            42143












            • it doesn't work as expected if a file name contains blank spaces
              – Angel
              Aug 2 '16 at 7:56


















            • it doesn't work as expected if a file name contains blank spaces
              – Angel
              Aug 2 '16 at 7:56
















            it doesn't work as expected if a file name contains blank spaces
            – Angel
            Aug 2 '16 at 7:56




            it doesn't work as expected if a file name contains blank spaces
            – Angel
            Aug 2 '16 at 7:56










            up vote
            23
            down vote













            Easiest way - accessed and modified will be the same:



            touch -a -m -t 201512180130.09 fileName.ext


            Where:



            -a = accessed
            -m = modified
            -t = timestamp - use [[CC]YY]MMDDhhmm[.ss] time format


            If you wish to use NOW just drop the -t and the timestamp.



            To verify they are all the same:
            stat fileName.ext



            See: touch man






            share|improve this answer























            • I tried to verify it using stat, but neither of the touch flags lead to a correct result. Modification date is adjusted, but changed and accessed date are actually changed to NOW
              – Xerus
              Mar 19 at 20:51















            up vote
            23
            down vote













            Easiest way - accessed and modified will be the same:



            touch -a -m -t 201512180130.09 fileName.ext


            Where:



            -a = accessed
            -m = modified
            -t = timestamp - use [[CC]YY]MMDDhhmm[.ss] time format


            If you wish to use NOW just drop the -t and the timestamp.



            To verify they are all the same:
            stat fileName.ext



            See: touch man






            share|improve this answer























            • I tried to verify it using stat, but neither of the touch flags lead to a correct result. Modification date is adjusted, but changed and accessed date are actually changed to NOW
              – Xerus
              Mar 19 at 20:51













            up vote
            23
            down vote










            up vote
            23
            down vote









            Easiest way - accessed and modified will be the same:



            touch -a -m -t 201512180130.09 fileName.ext


            Where:



            -a = accessed
            -m = modified
            -t = timestamp - use [[CC]YY]MMDDhhmm[.ss] time format


            If you wish to use NOW just drop the -t and the timestamp.



            To verify they are all the same:
            stat fileName.ext



            See: touch man






            share|improve this answer














            Easiest way - accessed and modified will be the same:



            touch -a -m -t 201512180130.09 fileName.ext


            Where:



            -a = accessed
            -m = modified
            -t = timestamp - use [[CC]YY]MMDDhhmm[.ss] time format


            If you wish to use NOW just drop the -t and the timestamp.



            To verify they are all the same:
            stat fileName.ext



            See: touch man







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 24 '16 at 0:24









            jkukul

            1134




            1134










            answered Dec 19 '15 at 14:58









            Jadeye

            35726




            35726












            • I tried to verify it using stat, but neither of the touch flags lead to a correct result. Modification date is adjusted, but changed and accessed date are actually changed to NOW
              – Xerus
              Mar 19 at 20:51


















            • I tried to verify it using stat, but neither of the touch flags lead to a correct result. Modification date is adjusted, but changed and accessed date are actually changed to NOW
              – Xerus
              Mar 19 at 20:51
















            I tried to verify it using stat, but neither of the touch flags lead to a correct result. Modification date is adjusted, but changed and accessed date are actually changed to NOW
            – Xerus
            Mar 19 at 20:51




            I tried to verify it using stat, but neither of the touch flags lead to a correct result. Modification date is adjusted, but changed and accessed date are actually changed to NOW
            – Xerus
            Mar 19 at 20:51










            up vote
            7
            down vote













            Touch can reference a file's date all by itself, no need to call date or use command substitution. Here's a bit from touch's info page:



            `-r FILE' `--reference=FILE'
            Use the times of the reference FILE instead of the current time.
            If this option is combined with the `--date=TIME' (`-d TIME')
            option, the reference FILE's time is the origin for any relative
            TIMEs given, but is otherwise ignored. For example, `-r foo -d
            '-5 seconds'' specifies a time stamp equal to five seconds before
            the corresponding time stamp for `foo'. If FILE is a symbolic
            link, the reference timestamp is taken from the target of the
            symlink, unless `-h' was also in effect.


            For example, to add 8 hours to a file's date (filename of file quoted just in case of spaces, etc):



            touch -r "file" -d '+8 hour' "file"


            Using a loop over all files in the current dir:



            for i in *; do touch -r "$i" -d '+8 hour' "$i"; done


            I've heard that using a * and letting for pick the filenames itself is safer, but using find -print0 | xargs -0 touch ... should handle most crazy characters like newlines, spaces, quotes, backslashes in a filename. (PS. try not to use crazy characters in filenames in the first place).



            For example, to find all files in thatdir whose filenames start with an s, and add one day to those file's modified timestamp, use:



            find thatdir -name "s*" -print0 | xargs -0 -I '{}' touch -r '{}' -d '+1 day' '{}'





            share|improve this answer

























              up vote
              7
              down vote













              Touch can reference a file's date all by itself, no need to call date or use command substitution. Here's a bit from touch's info page:



              `-r FILE' `--reference=FILE'
              Use the times of the reference FILE instead of the current time.
              If this option is combined with the `--date=TIME' (`-d TIME')
              option, the reference FILE's time is the origin for any relative
              TIMEs given, but is otherwise ignored. For example, `-r foo -d
              '-5 seconds'' specifies a time stamp equal to five seconds before
              the corresponding time stamp for `foo'. If FILE is a symbolic
              link, the reference timestamp is taken from the target of the
              symlink, unless `-h' was also in effect.


              For example, to add 8 hours to a file's date (filename of file quoted just in case of spaces, etc):



              touch -r "file" -d '+8 hour' "file"


              Using a loop over all files in the current dir:



              for i in *; do touch -r "$i" -d '+8 hour' "$i"; done


              I've heard that using a * and letting for pick the filenames itself is safer, but using find -print0 | xargs -0 touch ... should handle most crazy characters like newlines, spaces, quotes, backslashes in a filename. (PS. try not to use crazy characters in filenames in the first place).



              For example, to find all files in thatdir whose filenames start with an s, and add one day to those file's modified timestamp, use:



              find thatdir -name "s*" -print0 | xargs -0 -I '{}' touch -r '{}' -d '+1 day' '{}'





              share|improve this answer























                up vote
                7
                down vote










                up vote
                7
                down vote









                Touch can reference a file's date all by itself, no need to call date or use command substitution. Here's a bit from touch's info page:



                `-r FILE' `--reference=FILE'
                Use the times of the reference FILE instead of the current time.
                If this option is combined with the `--date=TIME' (`-d TIME')
                option, the reference FILE's time is the origin for any relative
                TIMEs given, but is otherwise ignored. For example, `-r foo -d
                '-5 seconds'' specifies a time stamp equal to five seconds before
                the corresponding time stamp for `foo'. If FILE is a symbolic
                link, the reference timestamp is taken from the target of the
                symlink, unless `-h' was also in effect.


                For example, to add 8 hours to a file's date (filename of file quoted just in case of spaces, etc):



                touch -r "file" -d '+8 hour' "file"


                Using a loop over all files in the current dir:



                for i in *; do touch -r "$i" -d '+8 hour' "$i"; done


                I've heard that using a * and letting for pick the filenames itself is safer, but using find -print0 | xargs -0 touch ... should handle most crazy characters like newlines, spaces, quotes, backslashes in a filename. (PS. try not to use crazy characters in filenames in the first place).



                For example, to find all files in thatdir whose filenames start with an s, and add one day to those file's modified timestamp, use:



                find thatdir -name "s*" -print0 | xargs -0 -I '{}' touch -r '{}' -d '+1 day' '{}'





                share|improve this answer












                Touch can reference a file's date all by itself, no need to call date or use command substitution. Here's a bit from touch's info page:



                `-r FILE' `--reference=FILE'
                Use the times of the reference FILE instead of the current time.
                If this option is combined with the `--date=TIME' (`-d TIME')
                option, the reference FILE's time is the origin for any relative
                TIMEs given, but is otherwise ignored. For example, `-r foo -d
                '-5 seconds'' specifies a time stamp equal to five seconds before
                the corresponding time stamp for `foo'. If FILE is a symbolic
                link, the reference timestamp is taken from the target of the
                symlink, unless `-h' was also in effect.


                For example, to add 8 hours to a file's date (filename of file quoted just in case of spaces, etc):



                touch -r "file" -d '+8 hour' "file"


                Using a loop over all files in the current dir:



                for i in *; do touch -r "$i" -d '+8 hour' "$i"; done


                I've heard that using a * and letting for pick the filenames itself is safer, but using find -print0 | xargs -0 touch ... should handle most crazy characters like newlines, spaces, quotes, backslashes in a filename. (PS. try not to use crazy characters in filenames in the first place).



                For example, to find all files in thatdir whose filenames start with an s, and add one day to those file's modified timestamp, use:



                find thatdir -name "s*" -print0 | xargs -0 -I '{}' touch -r '{}' -d '+1 day' '{}'






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 17 '16 at 14:52









                Xen2050

                6,64212142




                6,64212142






















                    up vote
                    2
                    down vote













                    This little script at least works for me



                    #!/bin/bash

                    # find specific files
                    files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in ${files}
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done





                    share|improve this answer

















                    • 2




                      Adjusting the date of images based on meta info in the image would be pretty useful. ImageMagick's identify can be used. e.g. 'identify -verbose <image> |grep -i date', 'identify -format %[exif:DateTime] <image>' might show '2015:01:08 10:19:10' (not all images have exif data). This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                      – gaoithe
                      May 24 '16 at 11:30

















                    up vote
                    2
                    down vote













                    This little script at least works for me



                    #!/bin/bash

                    # find specific files
                    files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in ${files}
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done





                    share|improve this answer

















                    • 2




                      Adjusting the date of images based on meta info in the image would be pretty useful. ImageMagick's identify can be used. e.g. 'identify -verbose <image> |grep -i date', 'identify -format %[exif:DateTime] <image>' might show '2015:01:08 10:19:10' (not all images have exif data). This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                      – gaoithe
                      May 24 '16 at 11:30















                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    This little script at least works for me



                    #!/bin/bash

                    # find specific files
                    files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in ${files}
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done





                    share|improve this answer












                    This little script at least works for me



                    #!/bin/bash

                    # find specific files
                    files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in ${files}
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 6 '13 at 19:40









                    joakim

                    211




                    211








                    • 2




                      Adjusting the date of images based on meta info in the image would be pretty useful. ImageMagick's identify can be used. e.g. 'identify -verbose <image> |grep -i date', 'identify -format %[exif:DateTime] <image>' might show '2015:01:08 10:19:10' (not all images have exif data). This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                      – gaoithe
                      May 24 '16 at 11:30
















                    • 2




                      Adjusting the date of images based on meta info in the image would be pretty useful. ImageMagick's identify can be used. e.g. 'identify -verbose <image> |grep -i date', 'identify -format %[exif:DateTime] <image>' might show '2015:01:08 10:19:10' (not all images have exif data). This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                      – gaoithe
                      May 24 '16 at 11:30










                    2




                    2




                    Adjusting the date of images based on meta info in the image would be pretty useful. ImageMagick's identify can be used. e.g. 'identify -verbose <image> |grep -i date', 'identify -format %[exif:DateTime] <image>' might show '2015:01:08 10:19:10' (not all images have exif data). This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                    – gaoithe
                    May 24 '16 at 11:30






                    Adjusting the date of images based on meta info in the image would be pretty useful. ImageMagick's identify can be used. e.g. 'identify -verbose <image> |grep -i date', 'identify -format %[exif:DateTime] <image>' might show '2015:01:08 10:19:10' (not all images have exif data). This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                    – gaoithe
                    May 24 '16 at 11:30












                    up vote
                    1
                    down vote













                    It's been a long time since I wrote any kind of Unix program, but I accidentally set the year incorrectly on a bunch of Christmas photos, and I knew if I didn't change the date from 2015 to 2014 it would be a problem later on.



                    Maybe, this is an easy task, but I didn't find any simple way to do it.



                    I modified a script I found here, which originally was used to modify the date by minus one month.



                    Here's the original script:



                    #!/bin/bash

                    # find specific files
                    files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in ${files}
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done


                    Here's my modified script that forced the date to the year "2014":



                    #!/bin/bash 

                    # find specific files
                    #files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in $*
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v +1y -r $(stat -f %m "${f}") +2014%m%d%H%M.%S) "${f}"
                    done


                    I now realize I could have done a more generic version:



                    #!/bin/bash 

                    # find specific files
                    #files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in $*
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch (+1y adds a year "-1y" subtracts a year)
                    # Below line subtracts a year
                    touch -t $(date -v -1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    # Below line adds a year
                    # touch -t $(date -v +1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done


                    To use this file you would need to write it and



                    chmod +x fn


                    to execute:



                    ./fn files-to-change


                    fn=your-file-name-that-is-your-command



                    Example



                    ./fn *.JPG


                    will change the date by minus one year in the directory where you are.






                    share|improve this answer



















                    • 1




                      Same as above comment. Most .jpg files will have date embedded in meta data aded by camera. This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                      – gaoithe
                      May 25 '16 at 9:49















                    up vote
                    1
                    down vote













                    It's been a long time since I wrote any kind of Unix program, but I accidentally set the year incorrectly on a bunch of Christmas photos, and I knew if I didn't change the date from 2015 to 2014 it would be a problem later on.



                    Maybe, this is an easy task, but I didn't find any simple way to do it.



                    I modified a script I found here, which originally was used to modify the date by minus one month.



                    Here's the original script:



                    #!/bin/bash

                    # find specific files
                    files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in ${files}
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done


                    Here's my modified script that forced the date to the year "2014":



                    #!/bin/bash 

                    # find specific files
                    #files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in $*
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v +1y -r $(stat -f %m "${f}") +2014%m%d%H%M.%S) "${f}"
                    done


                    I now realize I could have done a more generic version:



                    #!/bin/bash 

                    # find specific files
                    #files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in $*
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch (+1y adds a year "-1y" subtracts a year)
                    # Below line subtracts a year
                    touch -t $(date -v -1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    # Below line adds a year
                    # touch -t $(date -v +1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done


                    To use this file you would need to write it and



                    chmod +x fn


                    to execute:



                    ./fn files-to-change


                    fn=your-file-name-that-is-your-command



                    Example



                    ./fn *.JPG


                    will change the date by minus one year in the directory where you are.






                    share|improve this answer



















                    • 1




                      Same as above comment. Most .jpg files will have date embedded in meta data aded by camera. This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                      – gaoithe
                      May 25 '16 at 9:49













                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    It's been a long time since I wrote any kind of Unix program, but I accidentally set the year incorrectly on a bunch of Christmas photos, and I knew if I didn't change the date from 2015 to 2014 it would be a problem later on.



                    Maybe, this is an easy task, but I didn't find any simple way to do it.



                    I modified a script I found here, which originally was used to modify the date by minus one month.



                    Here's the original script:



                    #!/bin/bash

                    # find specific files
                    files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in ${files}
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done


                    Here's my modified script that forced the date to the year "2014":



                    #!/bin/bash 

                    # find specific files
                    #files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in $*
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v +1y -r $(stat -f %m "${f}") +2014%m%d%H%M.%S) "${f}"
                    done


                    I now realize I could have done a more generic version:



                    #!/bin/bash 

                    # find specific files
                    #files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in $*
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch (+1y adds a year "-1y" subtracts a year)
                    # Below line subtracts a year
                    touch -t $(date -v -1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    # Below line adds a year
                    # touch -t $(date -v +1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done


                    To use this file you would need to write it and



                    chmod +x fn


                    to execute:



                    ./fn files-to-change


                    fn=your-file-name-that-is-your-command



                    Example



                    ./fn *.JPG


                    will change the date by minus one year in the directory where you are.






                    share|improve this answer














                    It's been a long time since I wrote any kind of Unix program, but I accidentally set the year incorrectly on a bunch of Christmas photos, and I knew if I didn't change the date from 2015 to 2014 it would be a problem later on.



                    Maybe, this is an easy task, but I didn't find any simple way to do it.



                    I modified a script I found here, which originally was used to modify the date by minus one month.



                    Here's the original script:



                    #!/bin/bash

                    # find specific files
                    files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in ${files}
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v -1m -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done


                    Here's my modified script that forced the date to the year "2014":



                    #!/bin/bash 

                    # find specific files
                    #files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in $*
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch
                    touch -t $(date -v +1y -r $(stat -f %m "${f}") +2014%m%d%H%M.%S) "${f}"
                    done


                    I now realize I could have done a more generic version:



                    #!/bin/bash 

                    # find specific files
                    #files=$(find . -type f -name '*.JPG')

                    # use newline as file separator (handle spaces in filenames)
                    IFS=$'n'

                    for f in $*
                    do
                    # read file modification date using stat as seconds
                    # adjust date backwards (1 month) using date and print in correct format
                    # change file time using touch (+1y adds a year "-1y" subtracts a year)
                    # Below line subtracts a year
                    touch -t $(date -v -1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    # Below line adds a year
                    # touch -t $(date -v +1y -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
                    done


                    To use this file you would need to write it and



                    chmod +x fn


                    to execute:



                    ./fn files-to-change


                    fn=your-file-name-that-is-your-command



                    Example



                    ./fn *.JPG


                    will change the date by minus one year in the directory where you are.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 5 '15 at 0:05









                    Eric Carvalho

                    41k17112144




                    41k17112144










                    answered Jan 4 '15 at 23:28









                    RickK

                    112




                    112








                    • 1




                      Same as above comment. Most .jpg files will have date embedded in meta data aded by camera. This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                      – gaoithe
                      May 25 '16 at 9:49














                    • 1




                      Same as above comment. Most .jpg files will have date embedded in meta data aded by camera. This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                      – gaoithe
                      May 25 '16 at 9:49








                    1




                    1




                    Same as above comment. Most .jpg files will have date embedded in meta data aded by camera. This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                    – gaoithe
                    May 25 '16 at 9:49




                    Same as above comment. Most .jpg files will have date embedded in meta data aded by camera. This works(using sed to convert date to format touch can handle): 'touch -d $(identify -format %[exif:DateTime] $f|sed -r 's/:/-/;s/:/-/;') $f'
                    – gaoithe
                    May 25 '16 at 9:49










                    up vote
                    -6
                    down vote













                    just change date and time in settings. then save your file, it automatically changes






                    share|improve this answer

















                    • 3




                      Snej is looking for a batch or command line solution that can be used to modify multiple files. Changing system time and date and the modify the files is probably not an ideal solution.
                      – fabricator4
                      Nov 28 '12 at 9:35










                    • too much triiiiiiicky!!!
                      – Philippe Gachoud
                      Oct 8 '13 at 21:25












                    • For those with other OS's brought here via web search, this answer is the simplest way to change the date of a file on Mac OSX ('touch -d' results in 'illegal option').
                      – alanning
                      Feb 18 '14 at 3:50










                    • @alanning: OSX has BSD touch, not GNU touch. Use -t. developer.apple.com/library/mac/documentation/Darwin/Reference/…
                      – Dominik R
                      Mar 26 '16 at 18:25










                    • That may have unforeseen consequences. In a modern OS, lots of files are getting modified behind the scenes all the time. While your date is changed, many other files could get wrong date stamps on them and anything can happen when something else in the system notices that a file is older than expected.
                      – Joe
                      Apr 9 '17 at 7:11















                    up vote
                    -6
                    down vote













                    just change date and time in settings. then save your file, it automatically changes






                    share|improve this answer

















                    • 3




                      Snej is looking for a batch or command line solution that can be used to modify multiple files. Changing system time and date and the modify the files is probably not an ideal solution.
                      – fabricator4
                      Nov 28 '12 at 9:35










                    • too much triiiiiiicky!!!
                      – Philippe Gachoud
                      Oct 8 '13 at 21:25












                    • For those with other OS's brought here via web search, this answer is the simplest way to change the date of a file on Mac OSX ('touch -d' results in 'illegal option').
                      – alanning
                      Feb 18 '14 at 3:50










                    • @alanning: OSX has BSD touch, not GNU touch. Use -t. developer.apple.com/library/mac/documentation/Darwin/Reference/…
                      – Dominik R
                      Mar 26 '16 at 18:25










                    • That may have unforeseen consequences. In a modern OS, lots of files are getting modified behind the scenes all the time. While your date is changed, many other files could get wrong date stamps on them and anything can happen when something else in the system notices that a file is older than expected.
                      – Joe
                      Apr 9 '17 at 7:11













                    up vote
                    -6
                    down vote










                    up vote
                    -6
                    down vote









                    just change date and time in settings. then save your file, it automatically changes






                    share|improve this answer












                    just change date and time in settings. then save your file, it automatically changes







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 28 '12 at 8:37









                    vampiremac

                    13




                    13








                    • 3




                      Snej is looking for a batch or command line solution that can be used to modify multiple files. Changing system time and date and the modify the files is probably not an ideal solution.
                      – fabricator4
                      Nov 28 '12 at 9:35










                    • too much triiiiiiicky!!!
                      – Philippe Gachoud
                      Oct 8 '13 at 21:25












                    • For those with other OS's brought here via web search, this answer is the simplest way to change the date of a file on Mac OSX ('touch -d' results in 'illegal option').
                      – alanning
                      Feb 18 '14 at 3:50










                    • @alanning: OSX has BSD touch, not GNU touch. Use -t. developer.apple.com/library/mac/documentation/Darwin/Reference/…
                      – Dominik R
                      Mar 26 '16 at 18:25










                    • That may have unforeseen consequences. In a modern OS, lots of files are getting modified behind the scenes all the time. While your date is changed, many other files could get wrong date stamps on them and anything can happen when something else in the system notices that a file is older than expected.
                      – Joe
                      Apr 9 '17 at 7:11














                    • 3




                      Snej is looking for a batch or command line solution that can be used to modify multiple files. Changing system time and date and the modify the files is probably not an ideal solution.
                      – fabricator4
                      Nov 28 '12 at 9:35










                    • too much triiiiiiicky!!!
                      – Philippe Gachoud
                      Oct 8 '13 at 21:25












                    • For those with other OS's brought here via web search, this answer is the simplest way to change the date of a file on Mac OSX ('touch -d' results in 'illegal option').
                      – alanning
                      Feb 18 '14 at 3:50










                    • @alanning: OSX has BSD touch, not GNU touch. Use -t. developer.apple.com/library/mac/documentation/Darwin/Reference/…
                      – Dominik R
                      Mar 26 '16 at 18:25










                    • That may have unforeseen consequences. In a modern OS, lots of files are getting modified behind the scenes all the time. While your date is changed, many other files could get wrong date stamps on them and anything can happen when something else in the system notices that a file is older than expected.
                      – Joe
                      Apr 9 '17 at 7:11








                    3




                    3




                    Snej is looking for a batch or command line solution that can be used to modify multiple files. Changing system time and date and the modify the files is probably not an ideal solution.
                    – fabricator4
                    Nov 28 '12 at 9:35




                    Snej is looking for a batch or command line solution that can be used to modify multiple files. Changing system time and date and the modify the files is probably not an ideal solution.
                    – fabricator4
                    Nov 28 '12 at 9:35












                    too much triiiiiiicky!!!
                    – Philippe Gachoud
                    Oct 8 '13 at 21:25






                    too much triiiiiiicky!!!
                    – Philippe Gachoud
                    Oct 8 '13 at 21:25














                    For those with other OS's brought here via web search, this answer is the simplest way to change the date of a file on Mac OSX ('touch -d' results in 'illegal option').
                    – alanning
                    Feb 18 '14 at 3:50




                    For those with other OS's brought here via web search, this answer is the simplest way to change the date of a file on Mac OSX ('touch -d' results in 'illegal option').
                    – alanning
                    Feb 18 '14 at 3:50












                    @alanning: OSX has BSD touch, not GNU touch. Use -t. developer.apple.com/library/mac/documentation/Darwin/Reference/…
                    – Dominik R
                    Mar 26 '16 at 18:25




                    @alanning: OSX has BSD touch, not GNU touch. Use -t. developer.apple.com/library/mac/documentation/Darwin/Reference/…
                    – Dominik R
                    Mar 26 '16 at 18:25












                    That may have unforeseen consequences. In a modern OS, lots of files are getting modified behind the scenes all the time. While your date is changed, many other files could get wrong date stamps on them and anything can happen when something else in the system notices that a file is older than expected.
                    – Joe
                    Apr 9 '17 at 7:11




                    That may have unforeseen consequences. In a modern OS, lots of files are getting modified behind the scenes all the time. While your date is changed, many other files could get wrong date stamps on them and anything can happen when something else in the system notices that a file is older than expected.
                    – Joe
                    Apr 9 '17 at 7:11


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f62492%2fhow-can-i-change-the-date-modified-created-of-a-file%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Quarter-circle Tiles

                    build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                    Mont Emei