How do I "copy" the modification date and time from one file/dir to another in Unix-based systems?
If you copy a file from C:\fat16 to D:\NTFS, it keeps the same modified date and time but changes the created date and time to the current date and time. If you move a file from C:\fat16 to D:\NTFS, it keeps the same modified date and time and keeps the same created date and time.
Modification Time: is the time when the contents of the file was last modified. For example, you used an editor to add new content or delete some existing content. Change Time: is the time when the file's inode has been changed. For example, by changing permissions, ownership, file name, number of hard links.
Setting specific timestampsUse the -d ( --date= ) option to specify a date string and use it instead of the current time. The date string needs to be enclosed in single quotes. For example, the following command will set the last access and modification times of file1 to 1 June 11:02 of the current year.
* -type f -exec bash -c 'mv "$@" $(date --date=@$(stat -c %Y "$@") +%Y-%m)/"$@"' _ {} \; it moves all files in followingly e.g. zoo. txt goes to 2020-01/zoo. txt etc.
You have some options:
touch -t STAMP -m file
if you want to change the timecp --preserve=timestamps
if you're copying the files and want to preserve the timetouch -r
to set the time to a "reference" fileFor convenience later on, put the following line in your .bashrc file:
cptimestamp() {
if [ -z $2 ] ; then
echo "usage: cptimestamp <sourcefile> <destfile>"
exit
fi
touch -d @$(stat -c "%Y" "$1") "$2"
}
Execute "source ~/.bashrc" and you're ready to go. If you prefer a script instead, remove the first and last lines -- then prepend "#!/bin/sh"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With