Newbie needing help with tar command
I have a tar file named foldera-files.tar that contains files from foldera/files that was created using:
tar -czvf foldera-files.tar foldera/files/ I want to extract the contents from this tar file to an empty folder named folderb/files So I tried this command tar -C /folderb/files -xvf foldera-files.tar It shows the files being extracted, but the contents of folderb/files is still empty. Help greatly appreciated. |
It probably extracted the files at the point you were at when you ran that command. Is there a new foldera/files tree at the point where you ran that tar command? If so you should be able to move the file tree to where you want it to be.
But that put some question in my mind as to why this didn't work, or what would've worked correctly for you. I'm not too experienced at using the -C argument, but have done so. Therefore a quick test, in case your question has more to do with tar versus the fact that you didn't get the files where you wanted them. Code:
mkdir temp So I'm curious then why you didn't see foldera embedded within folderb. I hope it wasn't as simple as you hadn't created folderb before you performed your extraction? |
To explain my environment a little more as well as my results:
I was using putty to login to my server. There are two directories beneath the "root" of my hosting service foldera |---files folderb |---files I was at the "root" directory of my hosting service when I executed my tar extract command. I did not see any of the files that I knew were in my tar get extracted to either my "root" directory or the folderb > files directory. My TRUE intent is to copy the contents of the files directory beneath foldera to the files directory beneath folderb, but I'm having trouble getting the cp command to work. ...Jim P. |
Have you tried?
Code:
cp -rf foldera folderb |
Let's say you have something weird and cp isn't working properly, such as an oddball Busybox implementation and/or a cp which doesn't support the -r option. To do this with tar, I would do the following:
Code:
cd foldera Note further that say the hierarchy under foldera is all your stuff and you do have symbolic links, it's probably better to have those links not be fully qualified paths, but rather referenced based paths. Say the link points to ../../file versus /<path>/<path>/<path>/file. I find that helps if I create symbolic links and cp a whole directory tree, including those. |
Oneliner for same:
Code:
tar -cf - * | ( cd ../folderb; tar -xf -) Code:
find . -print -depth | cpio -pdm ../folderb |
Off the top of my head your
Code:
tar -C /folderb/files -xf foldera-files.tar Potential pitfalls:
However, should ethier of those be true sone error must have been presented. And.. it dosn't fit with post #3 maybe permissions? You would need read for foldera and write for b cp should work, but I do find myself using rsync more, especially when dealing with many files so you get no errors with tar or your original cp? Seems odd Edit, try cp with the -v flag It does nothing special, just prints what it tries |
Sorry, I realized that I didn't describe what I was wanting to do, correctly.
I had previously stated: foldera |---files (I should have called this subfoldera) |--data1.ext |--data1.ext folderb |---files (I should have called this subfolderb) The references to "files" above are both folders. Using my new terminology, I'm trying to get the contents of subfolders to subfolderb. Still not getting data1.ext and data2.ext in folderb>subfolderb More help is requested. Thanks to all who have provided feedback and I appreciate everyone's patience. Regards, Jim P. |
Checkout.
Code:
cp --help And Code:
man cp Code:
cp -a /path/to/foldera/* /path/to/folderb/ -a is short for a bunch of stuff, see the --help and manpage for details throw in a -v to see stuff If you want progress .. Code:
rsync -a --progress /path/to/foldera/* /path/to/folderb/ rsync is probably overkill for what you need, I like to use it for large or/and lots of files... mostly for the feedback, if I knew total size I can guesstimate how long I have to wait |
Actually, my previous post is mostly redundant, just reiterated rtmistler's post #4
|
Quote:
Also your inclusion list is ONLY foldera/files/, since there's no wildcards, you will probably grab the directory and not the contents of that directory. Having foldera/files* will likely better suit your intentions? YMMV. |
All times are GMT -5. The time now is 08:22 PM. |