Greetings All, I am currently engaged in copying files from a desktop machine to an external USB hard drive.
The machine has both Windows 98 and Linux on it, and dual-boots. Because Win98 does not recognise the external drive, while the Linux installation does, I'm booting into Linux to do the copying.
The objective is to transfer every file on the desktop onto the external drive. The external drive is mounted as /media/sda1 in Linux, and has a vfat filesystem.
The Windows drives \C, \D, \E, \F are mounted, when the machine is booted into Linux, as:
/windows/C /windows/D ... /windows/F
With the Windows files, no problem: I make the directories /media/sda1/WinLinMachine/C (and similar for .../D, .../E, .../F, these being all the Windows drives). Then I do the likes of:
cd /windows/C cp -a * /media/sda1/WinLinMachine/C
(and similar for D, E and F). This has worked fine. However, I now want to copy over all the Linux files as well. I have made a directory
/media/sda1/WinLinMachine/LinuxFiles
but now, of course,
cp -a /* /media/sda1/WinLinMachine/LinuxFiles
will not work, because the external drive is mounted under / and so will be itself copied and recopied in an infinite recursion. There would be no problem if there was an "exclude" option for 'cp' (say "-X") so that
cp -a -X /media /* /media/sda1/WinLinMachine/LinuxFiles
would inhibit anything under /media from being copied. But I can find no such option for 'cp'.
So how to proceed???
With thanks, Ted. ---------------------------------- E-Mail: (Ted Harding) Ted.Harding@wlandres.net Date: 14-Jan-2012 Time: 20:49:49
This message was sent by XFMail ----------------------------------
On 14/01/12 21:11, (Ted Harding) wrote: []
but now, of course,
cp -a /* /media/sda1/WinLinMachine/LinuxFiles
will not work, because the external drive is mounted under / and so will be itself copied and recopied in an infinite recursion. There would be no problem if there was an "exclude" option for 'cp' (say "-X") so that
cp -a -X /media /* /media/sda1/WinLinMachine/LinuxFiles
would inhibit anything under /media from being copied. But I can find no such option for 'cp'.
So how to proceed???
Tongue in cheek answer: http://lmgtfy.com/?q=linux+copy+one+directory+to+a+subdirectory+excluding+di...
Slightly more helpful answer: rsync will copy and has an exclude option. Above URL will give examples.
HTH Steve
On Sat, 14 Jan 2012 21:11:03 -0000 (GMT), Ted.Harding@wlandres.net said:
cp -a -X /media /* /media/sda1/WinLinMachine/LinuxFiles
tar -C / --exclude /media -cf -|tar -C /media/sda1/WinLinMachine/LinuxFiles -xvf -
All on one line; multiple --excludes may be used, or see tar(1) for possibly better options.
Explanation:
-C : change to directory --exclude : DWISOTT --cf : create, output file is... - : stdout | : pipe to tar -C : change to directory that follows -xvf : extract, verbose (list files as they are processed), read from file - : stdin (ie, read from the pipe).
On 14/01/12 23:58, Keith Edmunds wrote:
On Sat, 14 Jan 2012 21:11:03 -0000 (GMT), Ted.Harding@wlandres.net said:
cp -a -X /media /* /media/sda1/WinLinMachine/LinuxFiles
tar -C / --exclude /media -cf -|tar -C /media/sda1/WinLinMachine/LinuxFiles -xvf -
Perhaps you could use cpio as in the copy example here:
http://en.wikipedia.org/wiki/Cpio
with find modified to exclude the destination directory. cpio in copy mode won't compress and decompress, so /may/ be faster than tar.
Steve