So I have a directory containing sub-directories with some files in them. I want to copy all of the sub-directories along with their files to a different folder while keeping the structure.
I'm trying to use $ cp -R foo bar but that copies foo into bar.
Can anybody help me out?
Name:
Anonymous2010-10-18 20:37
Just use a GUI?
If you insist on using scriptan, you want something like :
#!/bin/bash
for i in `ls`
do
cp -r $i /dest/dir/
done
I suggest using a GUI--you can't beat copy-and-paste for simplicity--but if that's not an option, I've used the following technique since the '80s. At your command line:
$ cd foo
$ tar cf - . | (cd /path/to/bar; tar xvf -)
This uses tar to snarf up the contents of foo, but instead of creating a tar file, it sends your files into a pipe. On the other end of the pipe, in the bar directory, tar intercepts the files coming in and extracts them, putting everything into their original order and printing each filename as it completes.