How can I change the creation time of all a folder's files to the current time?

2

Under a Linux shell, how can I change the creation time of all a folder's files to the current time?

tomy

Posted 2011-06-19T00:40:01.870

Reputation: 21

@boehj Thanks for pointing out that files don't have a creation time – Meredith – 2014-08-28T02:21:18.333

2The files don't have a 'create time' but they do have a 'modification time'. To change the modification time of a file you use the touch command, e.g. $ touch file1 file2 file3 – boehj – 2011-06-19T00:46:49.883

1Were these answers helpful to you @tomy? – boehj – 2011-06-27T06:45:29.973

Answers

3

Navigate to the folder in question, let's say, ~/Documents/myfiles.

$ cd ~/Documents/myfiles

Then do:

$ touch *

This will change the modification time to whenever you executed that command.

Obviously you can make this more specific depending on your use case, e.g.

$ touch *.doc

will only alter the modification time for files with the string '.doc' in their name.

boehj

Posted 2011-06-19T00:40:01.870

Reputation: 1 042

3

The OP asked for the creation time, but Ian Yang and boehj answers are based on command touch setting the modification, access and change times to current time.

As boehj said (in his comment) there is no creation time of a file... This is true for most of the filesystems, but on some modern filesystems (as ext4) the creation (or birth) time of a file is stored within the inode.

Therefore we can give a more correct answer scrupulously respecting the question title:

cp -a  your-folder tmp-folder
rm -rf your-folder
mv tmp-folder your-folder

This will change the creation time (birth time) to the current time. This also updates the change time but keep unchanged the modification and access times.

For information, the change time is sometimes abbreviated as ctime and can be confused with the creation time (crtime or btime). In fact, the change time of a file is the modification time of its corresponding inode. Therefore commands modifying inode content as chmod or chattr also set the change time to current time.

olibre

Posted 2011-06-19T00:40:01.870

Reputation: 1 533

As far as I know, most if not all Linux filesystems do not save a creation time. – terdon – 2013-08-26T17:03:21.250

Thank you @terdon for your comment, I have updated my answer (change comment is "creation time available on some modern filesystems only as stated by terdon"). Cheers ;-) – olibre – 2013-08-26T17:22:40.633

2

In Linux, if you want to do some thing recursively in directory, or you want to apply some actions on files meeting some criterions,you should try find and xargs

Touch all files in ~/Documents/myfiles (including files in sub directory)

find ~/Documents/myfiles -type f -print0 | xargs -0 touch

Ian Yang

Posted 2011-06-19T00:40:01.870

Reputation: 129

2Without xargs: find dir -type f -exec touch {} + (sets to now the modification/access/change times of all files recursively) – olibre – 2013-08-26T16:23:15.670