Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I copy files/folders from an ubuntu computer on a ext4 filesystem to another ubuntu computer which also is on an ext4 filesystem, using a usb stick which uses a vfat filesystem without losing file permissions?

I've tried the basic ctrl-c from source computer, then ctrl-v to usb, then ctrl-c from usb then ctrl-v to target computer, and none of the file/folder permissions stay intact.

share|improve this question
    
vfat does not support unix filesystem permissions. You will need to store them in a tarball, or something similar, if you want to preserve them. –  Alex L. Dec 5 '12 at 20:37
    
why not rsync, as i suggested? –  SiddharthaRT Dec 6 '12 at 21:25
add comment

3 Answers

up vote 15 down vote accepted

You can make a tar archive of the source, copy that to the other computer using the USB drive, and extract it there. Tar preserves file permissions.

1 - On the source computer:

cd /path/to/folder/to/copy
tar cvpzf put_your_name_here.tar.gz .

2 - Copy put_your_name_here.tar.gz to the USB drive and then to the other computer

3 - On the destination computer:

cd /path/to/destination/folder
tar xpvzf put_your_name_here.tar.gz

tar will recreate the archived folder structure with all permissions intact.

Those commands will archive the contents of the source folder and then extract them into the destination folder. If you want to copy the folder itself, then you should, at step 1:

cd /path/to/parent/folder
tar cvpzf put_your_name_here.tar.gz folder_to_copy

The same mechanism could be used for single files.


If you can connect from one computer to the other using ssh, @siddharthart answer (rsync) might be more practical.

share|improve this answer
    
Don't forget the -p flag to tar to ensure permissions are preserved. –  haziz Dec 5 '12 at 23:47
    
@haziz Actually, the -p isn't really needed, see my comment to @mikewhatever's answer. The -z also isn't necessary when untarring, as tar is able to figure out the type of compression itself, unless it's an old version. Including the flags in the command doesn't hurt, tough. –  sierrasdetandil Dec 6 '12 at 0:54
    
I don't think you can count on this behavior. BTW quoting from the man tar page "-p, --preserve-permissions, --same-permissions extract information about file permissions (default for superuser)" this appears to be the default behavior only if tar is ivoked as superuser. Would not count on this as default behavior. I would also always explicitly spell out the -z flag when compressing or decompressing (or -j if using bzip2). –  haziz Dec 6 '12 at 1:07
    
Could (basic) encryption be easily added? (I guess there'd be many ways of doing it, but I'm wondering, but if done via the command line, how would the password / encryption key/passphrase be supplied? Like so ******** or like the sudo-password, where no key-strokes are made visible?) –  nutty about natty Apr 29 '13 at 5:58
add comment

You could try rsync with -a flag to maintain all permissions while copying. I'm not aware of a simpler solution, but I had used it for a purpose in the past.

Rsync gives brilliant support to repeated copying, updating folders etc. while remaining blazingly fast.

share|improve this answer
1  
I do like rsync (love it, in fact :-]), but the ext4 file permissions will be lost if the destination device is vfat formatted, like oshirowanen described. The tar solution is better in this case. –  YuriC Jan 31 '13 at 14:17
add comment

I think taring and then untaring should work on both files and directories.

to tar:

tar cvpfz /target.tar.gz /source/

to untar:

tar xvpfz /source/

The p flag stands for --preserve-permissions.

You should see man tar for more info.

share|improve this answer
    
I just did a quick test to be sure and -p is not needed -- tar preserves permissions by default, at least when the user owns the files being archived/extracted. –  sierrasdetandil Dec 5 '12 at 21:05
    
True, but you've not told us what files you wanted to copy, and I had no reason to assume anything on my own. –  mikewhatever Dec 5 '12 at 21:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.