Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to duplicate a folder exactly

I am trying to copy a filesystem for a device I am programming for. After so much time trying to figure out why the filesystem I was installing wasn't working I found out that cp didn't get the job done. I used du -s to check the size of the original filesystem and the one that I copied with cp -r, as it turns out they differ by about 150 bytes.

Something is telling me that symbolic links or some sort of kernel objects aren't being copied correctly.

Is it possible to copy a folder/file system exactly? If so how would I go about it?

like image 644
TopGunCoder Avatar asked Oct 17 '13 18:10

TopGunCoder


People also ask

How do I duplicate a folder?

Open your folder, and select all the files ( Control + a or Command + a). Right-click and select Make a copy. That will create a new copy of each of those files, right in the same folder, with Copy of before their original file name.

Can I copy a whole folder in Google Drive?

Copy an Entire Folder in Google Drive Open the folder on Google Drive that you want to copy. Select the first file, hold down the Shift key on your keyboard and select the last file. This will select all files in the folder. Right-click inside the highlighted area and select Make a copy.

How do I copy everything from one folder to another?

Right-click and pick Copy, or press Ctrl + C . Navigate to another folder, where you want to put the copy of the file. Click the menu button and pick Paste to finish copying the file, or press Ctrl + V . There will now be a copy of the file in the original folder and the other folder.

Can you duplicate folders in Windows?

Hold down the Ctrl key on your keyboard and select any files and folders you want to copy. Release the key when you're done. All highlighted files and folders will be copied. Choose Edit and then Copy To Folder from the menu at the top of the folder's window.


2 Answers

Try doing this the straightforward way :

cp -a src target 

from man cp

    -a, --archive            same as -dR --preserve=all 

It preserve rights, symlinks...

like image 121
Gilles Quenot Avatar answered Sep 21 '22 12:09

Gilles Quenot


Here I tried all the code in my Linux. Seems Rsync proposed by @seanmcl as the right one while others failed to keep owners and/or some special files or a denied result. The exact code is:

$ sudo rsync -aczvAXHS --progress /var/www/html /var/www/backup 

Just remember to use just the directory name and not put a slash (/) or a wildcard (/*) at the end of source and target name otherwise the hidden files right below the source are not copied.

like image 34
Chetabahana Avatar answered Sep 21 '22 12:09

Chetabahana