Score:1

How to copy date created to date modified ubuntu 22.04

im flag

I am using ubuntu 22.04 LTS and I want to know if the date created on ubuntu can be copied to date modified? I think I've read that the date created on ubuntu isn't actually the date created even though the label 'date created' is in Nautilus, rather it's the ctime (date changed). Is this correct ? How can I copy the date changed or 'date created' into date modified?

Thanks!!

in flag
Welcome to AskUbuntu. Have you seen [this answer](https://askubuntu.com/a/62496/1222991)? The commands are still quite valid
waltinator avatar
it flag
Does this answer your question? [How can I change the date modified/created of a file?](https://askubuntu.com/questions/62492/how-can-i-change-the-date-modified-created-of-a-file)
ghostanime2001 avatar
im flag
Hi, What if i have 100+ files then how can I make it easier ?
ghostanime2001 avatar
im flag
and also instead of typing the time manually usonf touch is there any command to simply copy the date created into date modified?
Score:0
jp flag

You are right … ctime is the file's last status(i.e. meta data) change time.

However, in recent kernels, the support of the system call statx() is added ... That, when a file is queried with e.g. stat file, should return some extended file attributes including btime which is the birth/creation time of that file (Check first with stat file to see if birth time is reported) ... A quick check on Ubuntu 22.04 shows that stat indeed uses statx() to get the btime ... See for example:

$ strace -e statx -v -s 0 stat filename
statx(AT_FDCWD, "filename", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_blksize=4096, stx_attributes=0, stx_nlink=1, stx_uid=1000, stx_gid=1000, stx_mode=S_IFREG|0664, stx_ino=22022834, stx_size=0, stx_blocks=0, stx_attributes_mask=STATX_ATTR_COMPRESSED|STATX_ATTR_IMMUTABLE|STATX_ATTR_APPEND|STATX_ATTR_NODUMP|STATX_ATTR_ENCRYPTED|STATX_ATTR_AUTOMOUNT|STATX_ATTR_MOUNT_ROOT|STATX_ATTR_VERITY|STATX_ATTR_DAX, stx_atime={tv_sec=1679481498, tv_nsec=733858313} /* 2023-03-22T13:38:18.733858313+0300 */, stx_btime={tv_sec=1679481214, tv_nsec=228264332} /* 2023-03-22T13:33:34.228264332+0300 */, stx_ctime={tv_sec=1679481498, tv_nsec=733858313} /* 2023-03-22T13:38:18.733858313+0300 */, stx_mtime={tv_sec=1679481498, tv_nsec=733858313} /* 2023-03-22T13:38:18.733858313+0300 */, stx_rdev_major=0, stx_rdev_minor=0, stx_dev_major=8, stx_dev_minor=2}) = 0
  File: filename
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d  Inode: 22022834    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  ubuntu)   Gid: ( 1000/  ubuntu)
Access: 2023-03-22 13:38:18.733858313 +0300
Modify: 2023-03-22 13:38:18.733858313 +0300
Change: 2023-03-22 13:38:18.733858313 +0300
 Birth: 2023-03-22 13:33:34.228264332 +0300
+++ exited with 0 +++

Therefore, you should be able to copy the creation time of a file to replace its modification time with something like this:

touch -m -d "$(stat -c '%w' file)" file

Or to replace both access and modification times add the -a option to touch as well … or drop the -m option from touch as it should then default to both.

Or, you can do the same for all the files in the current working directory with something like this:

for f in *
  do
    [ -f "$f" ] && touch -m -d "$(stat -c '%w' "$f")" "$f"
  done
ghostanime2001 avatar
im flag
Hello, yes upon using stat filename.jpg I can also confirm that it shows the birth time of files. Actually to clarify, I am specifically using Ubuntu 22.04.2 LTS (sorry about not clarifying this earlier). I can also confirm that the birth time does copy perfectly into the date modified. If I make a copy of the original file, is there any possible way to preserve the birth time, change time, accessed time, modified time at all ? even with star archive ? (https://linux.die.net/man/1/star) it says it preserves extended timestamps but I dont know how to use it...yet
Raffa avatar
jp flag
@anmac1789 AFAIK you can only preserve the modification date with e.g. `cp --preserve=timestamps original copy` or `cp original copy && touch -r original copy` or `rsync -t original copy` ... Theoretically these commands should copy Access date as well but this one is constantly changing e.g. during the file copying process itself ,,, Change date or `ctime` and creation date or `btime` require a file system debugger level to change to earlier date/time, so not changeable via normal user tools.
ghostanime2001 avatar
im flag
Just out of curiosity, how would one change the date created/birth time on a file system debugger level ?
Raffa avatar
jp flag
@anmac1789 Curiosity killed the cat :-) … See for example https://unix.stackexchange.com/q/36021 and be very careful and backup first.
ghostanime2001 avatar
im flag
access system disk using debugfs, or modify the kernel, I see someone write that we have to add attr->ia_ctime = attr->ia_mtime; //Sets the ctime attr->ia_atime = attr->ia_mtime from this link https://stackoverflow.com/questions/16126992/setting-changing-the-ctime-or-change-time-attribute-on-a-file/17066309#17066309
Raffa avatar
jp flag
@anmac1789 kernel is a totally different beast and modifying its source code requires building that source code then loading the newly built kernel … Take my word if you would and let it slip or if you don’t then your system will not be considered Ubuntu anymore and we can’t support it here … And you will most likely need support then.
ghostanime2001 avatar
im flag
alright looks like a dangerous way to modify files, i assumed it would somewhat be easy since linux is supposed to be easy. I'll just work on modifying the date modified and leave the rest alone until a more proven solution comes along
ghostanime2001 avatar
im flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/144789/discussion-between-anmac1789-and-raffa).
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.