How to preserve original times?

QuestionsQuestions4 SkillsProBasic Files OperationsSep, 12 2025
0456

To preserve the original timestamps (modification time, access time, and change time) of files when copying or moving them in Linux, you can use the cp command with the -p option. Here’s how to do it:

  1. Using cp with -p: When copying files, use the -p option to preserve the original timestamps:

    cp -p source_file.txt destination_file.txt
    
  2. Using rsync: If you are using rsync to copy files, you can use the -a (archive) option, which preserves timestamps along with other attributes:

    rsync -a source_file.txt destination_file.txt
    
  3. Using tar: When archiving files with tar, the timestamps are preserved by default. You can create an archive and extract it while keeping the original timestamps:

    tar -cvf archive.tar source_directory/
    tar -xvf archive.tar
    

These methods ensure that the original timestamps of files are preserved during copying or moving operations.

0 Comments

no data
Be the first to share your comment!