How to preserve file attributes?

QuestionsQuestions8 SkillsProBasic Files OperationsSep, 25 2025
0139

To preserve file attributes such as permissions, timestamps, and ownership when copying files in Linux, you can use the -p option with the cp command. Here’s how to do it:

cp -p source_file destination_file

For example, to copy a file named file.txt while preserving its attributes, you would use:

cp -p file.txt /path/to/destination/

If you are using the cp command to copy a directory and want to preserve attributes, you can use the -a (archive) option, which includes -p along with other options to preserve the structure and attributes:

cp -a source_directory/ destination_directory/

This command will copy the entire directory and its contents while preserving all file attributes.

0 Comments

no data
Be the first to share your comment!