Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
1  
The 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 Jun 19 '11 at 0:46
    
Were these answers helpful to you @tomy? –  boehj Jun 27 '11 at 6:45
add comment

3 Answers

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.

share|improve this answer
add comment

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
share|improve this answer
2  
Without xargs: find dir -type f -exec touch {} + (sets to now the modification/access/change times of all files recursively) –  olibre Aug 26 '13 at 16:23
add comment

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.

share|improve this answer
    
As far as I know, most if not all Linux filesystems do not save a creation time. –  terdon Aug 26 '13 at 17:03
    
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 Aug 26 '13 at 17:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.