LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 05-02-2014, 10:28 AM   #1
jkpalmer
LQ Newbie
 
Registered: Jan 2006
Posts: 4

Rep: Reputation: 0
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.
 
Old 05-02-2014, 10:43 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,476
Blog Entries: 10

Rep: Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639
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
cd temp
echo 1 > 1.txt
echo 1 > 2.txt
cd ..
tar -cvf test.tar temp/*
temp/1.txt
temp/2.txt
mkdir temp2
tar -C temp2 test.tar
temp/1.txt
temp/2.txt
ls -R temp2
temp2:
temp

temp2/temp:
1.txt  2.txt
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?
 
Old 05-02-2014, 01:22 PM   #3
jkpalmer
LQ Newbie
 
Registered: Jan 2006
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 05-02-2014, 01:32 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,476
Blog Entries: 10

Rep: Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639
Have you tried?
Code:
cp -rf foldera folderb
 
Old 05-02-2014, 01:37 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,476
Blog Entries: 10

Rep: Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639
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
tar -cvf ../files.tar *
cd ../folderb
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.
 
Old 05-02-2014, 02:51 PM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,104

Rep: Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515
Oneliner for same:

Code:
tar -cf - * | ( cd ../folderb; tar -xf -)
Or to use the old faithful cpio:

Code:
find . -print -depth | cpio -pdm ../folderb
 
Old 05-02-2014, 05:28 PM   #7
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Off the top of my head your

Code:
tar -C /folderb/files -xf foldera-files.tar
Should work..
Potential pitfalls:
  • /folderb/files does not exist
    Try mkdir -p /folderb/files before the tar
  • the foldera-files.tar doesn't exist , full path?

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

Last edited by Firerat; 05-02-2014 at 05:29 PM.
 
Old 05-03-2014, 07:32 AM   #8
jkpalmer
LQ Newbie
 
Registered: Jan 2006
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 05-03-2014, 05:31 PM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Checkout.
Code:
cp --help
.
And
Code:
man cp
I think this will work

Code:
cp -a /path/to/foldera/* /path/to/folderb/
Assumes folderb exists

-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/
Same folderb exists assumption

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
 
Old 05-03-2014, 05:33 PM   #10
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Actually, my previous post is mostly redundant, just reiterated rtmistler's post #4
 
Old 05-04-2014, 01:09 AM   #11
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,506
Blog Entries: 1

Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
Quote:
Originally Posted by jkpalmer View Post
tar -czvf foldera-files.tar foldera/files/

tar -C /folderb/files -xvf foldera-files.tar
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.

Last edited by Shadow_7; 05-04-2014 at 01:11 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie needing little help lordashraf Linux - Software 9 11-02-2005 09:56 AM
newbie needing some help linu Linux - Hardware 7 09-01-2004 06:37 PM
Another Newbie Needing Help kimbo1962 Linux - Newbie 8 03-14-2004 09:15 PM
Newbie.....needing some help... jwyant Linux - General 27 06-12-2003 11:28 AM


All times are GMT -5. The time now is 06:30 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration