How to keep file attributes during copy in Linux?

 


Every time you create a new file, it has several attributes that are automatically dedicated to this file, such as owner, group, permissions, time and date of creation. When you copy the file without any option, those attributes are not copy. But there is a way that you can keep the file attributes during a copy. In this article, you can find out just how?


For the purpose of this article I'm going to use the kings.txt file which I created previously. Before we issue a copy command on this file, let us list the file attributes. Here's a command.


# ls -l kings.txt 




As mentioned in short intro of this article, the file kings.txt belongs to a user 'abdi', group by the name of 'amurru' and on the left side there are read and write permission for root account, read and write permission for group and everyone else can only read this file but can't edit. 


Now, our goal is to preserve this attributes of the file and copy it into a new file by the name of kings1.txt. Here's the command.


# sudo cp -r  --preserve=all  kings.txt  kings1.txt 




Once we have entered the command, the file kings.txt was successfully copy into a new file by the name kings1.txt with all the attributes of original file, including it's time stamp (or time and date of creation): 


There you go. Now you now how you can keep file attributes during a copy in Linux. Same goes for a directory, as long as you are doing it with sudo account. Till the next time. 

Share:

Nema komentara:

Objavi komentar

POPULARNI POSTOVI

NAJNOVIJE