So, you want to copy files from one folder to another folder and change both the source and destination timestamp?
Linux can easily change or modify the timestamp with ‘touch’ command.
A one liner command with the help of ‘pipe’ to pass the arguments and ‘xargs’ to execute multiple commands in a single line can easily accomplish this task.
Command below will copy the files in the current directory where ‘ls’ command is executed to the directory ‘xfiles’, timestamp will be changed to 7 hours less from the current time.
ls | xargs -I % sh -c 'touch -d "7 hours ago" %; cp -p % ./xfiles';
-p option is important to preserve the modified timestamp
Note: the above command will change the timestamp for both source files and destination files.
Command below will change the source timestamp, but the destination timestamp will be the date and time that the command was executed.
ls | xargs -I % sh -c 'touch -d "2 Aug" %; cp % ./x';
Notice, that the -p option is omitted on the cp command; thus the source files timestamp will be changed while the destination timestamp will be the time and date that the command is executed.
Command below will change the timestamp of the files and folder in a current directory to 1 Aug.
ls | xargs -I % sh -c 'touch -d "1 Aug" %’;
Cheers! Till next time..
Free Android Apps:
Linux Android App cheat sheet:
Heaven's Dew Fall Prayer app for Android :
Catholic Rosary Guide for Android: