How can I change the creation time of all a folder's files to the current time?
Solution 1
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.
Solution 2
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.
Solution 3
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
Related videos on Youtube
tomy
Updated on September 18, 2022Comments
-
tomy almost 2 years
Under a Linux shell, how can I change the creation time of all a folder's files to the current time?
-
boehj about 13 yearsWere these answers helpful to you @tomy?
-
Meredith almost 10 years@boehj Thanks for pointing out that files don't have a creation time
-
-
oHo almost 11 yearsWithout
xargs
:find dir -type f -exec touch {} +
(sets to now the modification/access/change times of all files recursively) -
terdon almost 11 yearsAs far as I know, most if not all Linux filesystems do not save a creation time.