Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
echo 1 > 1.txt
echo 1 > 2.txt
tar -cvf test.tar temp/*
tar -C temp2 test.tar
ls -R temp2
So I feel this does work; however one has to be aware that the structure of the top level, including that top level is to be considered when you tar and extract. What I feel would've worked cleaner in this example is if I say was "in" temp and executed the tar command, specifying that the tar file be "../test.tar" so as to not include the tar file in my wildcard search in creating the tar. This way the top-most directory level would not have been included and I'd solely see 1.txt and 2.txt.
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?
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:
tar -cvf ../files.tar *
tar -xvf ../files.tar
This would leave the top level directory out of that picture. Honestly though I'm very interested what troubles you're running into with cp. There are also options to follow symbolic links; I think for both tar and cp if that is some of the problems.
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.
Well, -c is create -z is compress with gzip so technically the file should be .tar.gz, not that extensions matter much in linux. You should also include (or exclude) the "z" component in BOTH commands. With -x being extract.
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.