LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-14-2014, 03:39 PM   #1
ccc
Member
 
Registered: Oct 2002
Posts: 100

Rep: Reputation: 0
copy a directory with all rights and permissions to the USB flash drive


hi

How to copy a directory with all rights and permissions to the USB flash drive?
 
Old 12-14-2014, 03:42 PM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
if the drive is fat32 formatted you can not. the FAT and NTFS file systems do not understand true file permissions.

if on the other hand the drive is some form of ext then you can use rsync to copy the data

rsync -aviS should do the trick for you.
 
1 members found this post helpful.
Old 12-14-2014, 04:20 PM   #3
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware
Posts: 441

Rep: Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574
Hi there. As lleb said, native Windows file systems like FAT and NTFS will not preserve Unix file ownership and permissions. Depending on your needs, you might want to repartition your flash drive (after backing up your data) and create two partitions, one that you will initialize as FAT (or NTFS) and the other as ext3 or ext4. Then create a directory in the ext partition and give it read & write permissions for your user: that's where your data will go.

Another command that will preserve file ownership and permissions, as well as timestamps and links, is 'cp -a' (i.e. "archive", which has the same effect as 'cp -dR --preserve=all'). See 'man cp' for reference.

Last edited by Philip Lacroix; 12-14-2014 at 04:26 PM.
 
Old 12-14-2014, 04:53 PM   #4
ccc
Member
 
Registered: Oct 2002
Posts: 100

Original Poster
Rep: Reputation: 0
The usb flash drive was formatted with ext4.
I have done the copy using rsync and will try to recover tomorrow on other server.
 
Old 12-16-2014, 08:01 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I know of rsync, but never got into using it. Anyone tell me what's wrong with just the cp command? You can use the -p option to preserve, the -r option to recurse directories, and the -f option to say "make it happen!"
 
Old 12-16-2014, 08:48 AM   #6
cepheus11
Member
 
Registered: Nov 2010
Location: Germany
Distribution: Gentoo
Posts: 286

Rep: Reputation: 91
you need

Code:
cp -a
or

Code:
rsync -a
to preserve everything (owner/group, permissions, timestamps, symlinks, extended attributes). "-pr" is not enough, it misses extended attributes and links (copies links as regular files).
 
Old 12-16-2014, 08:53 AM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Just for being complete, it is indeed possible to store a directory tree with preserved permissions on FAT/NTFS file systems, if you use tar for the job.
 
1 members found this post helpful.
Old 12-16-2014, 10:57 AM   #8
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Use:
cp -dpr a/* b
or
cp -dpr a b
 
  


Reply

Tags
copy, permissions, rights, usb



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cannot copy files to USB flash drive from internal HDD. erik2282 Linux - Desktop 8 10-04-2014 12:23 PM
[SOLVED] binary copy to usb device, not flash drive or hard disk Pedulla Linux - General 1 09-15-2012 07:12 PM
Copy mbr of usb flash drive using dd. sr_25 Linux - Newbie 4 02-22-2011 08:16 AM
low level copy an USB flash drive / memory stick mr.v. Linux - Software 1 02-26-2007 04:05 PM
Syncing your home directory on a USB Flash Drive neville310 Linux - Desktop 1 01-13-2007 05:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration