LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-01-2009, 10:34 AM   #1
mashcaster
Member
 
Registered: Dec 2008
Posts: 67

Rep: Reputation: 15
SOLVED - tar Problems


I am having problems with tar. If I use the command

tar czf "/home/user/Desktop/backup.tar" "/home/user/Desktop/documents"

it creates a tar file, but it also includes the folder structure "/home/user/Desktop/documents". How do I stop it from creating the folder structure in the tar file and only compress the files/folders I want without having to click through the whole folder structure to get to the backup files?

Last edited by mashcaster; 01-03-2009 at 05:09 AM. Reason: SOLVED
 
Old 01-01-2009, 10:48 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
cd to the directory
you can use the -C option

man tar
 
Old 01-01-2009, 11:38 AM   #3
mashcaster
Member
 
Registered: Dec 2008
Posts: 67

Original Poster
Rep: Reputation: 15
I tried that before and it didn't work i.e.

tar -Ccf /home/user/Desktop/backupthis/backup.tar /home/user/Desktop/backupthis/
 
Old 01-01-2009, 02:13 PM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
try:

tar -C /home/user/Desktop --exclude=backup.tar cf /home/user/Desktop/backupthis/backup.tar backupthis
 
Old 01-01-2009, 02:24 PM   #5
mashcaster
Member
 
Registered: Dec 2008
Posts: 67

Original Poster
Rep: Reputation: 15
I tried that and I get a message saying

Quote:
tar: You must specify one of the `-Acdtrux' options
 
Old 01-01-2009, 02:34 PM   #6
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
sorry, i missed a character!

Try:

tar -C /home/user/Desktop --exclude=backup.tar -cf /home/user/Desktop/backupthis/backup.tar backupthis
 
Old 01-01-2009, 04:53 PM   #7
mashcaster
Member
 
Registered: Dec 2008
Posts: 67

Original Poster
Rep: Reputation: 15
That is almost perfect, but it also tar's the folder "backupthis". How do I stop it from tar'ing that folder and only tar the contents of that folder?
 
Old 01-01-2009, 05:13 PM   #8
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
tar -C /home/user/Desktop/backupthis --exclude=backup.tar -cf /home/user/Desktop/backupthis/backup.tar .
 
Old 01-03-2009, 04:50 AM   #9
mashcaster
Member
 
Registered: Dec 2008
Posts: 67

Original Poster
Rep: Reputation: 15
That doesn't really work either, it creates a folder with a . and puts the files in that folder. Will tar not allow archive to start without creating a folder?
 
Old 01-03-2009, 04:54 AM   #10
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Quote:
Originally Posted by mashcaster View Post
That doesn't really work either, it creates a folder with a . and puts the files in that folder. Will tar not allow archive to start without creating a folder?
Don't include the directory in the command line. "." is a directory

Use "*" to mean "all files in current dir" instead. You should also check shopt and the dotglob option if you intend to pack the hidden files in that dir (if any).

PS. However I can't see a problem with having ./ in front of your files in the tar file... The effect will be the same.

Last edited by i92guboj; 01-03-2009 at 04:55 AM.
 
Old 01-03-2009, 05:01 AM   #11
mashcaster
Member
 
Registered: Dec 2008
Posts: 67

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by i92guboj View Post
Don't include the directory in the command line. "." is a directory

Use "*" to mean "all files in current dir" instead. You should also check shopt and the dotglob option if you intend to pack the hidden files in that dir (if any).

PS. However I can't see a problem with having ./ in front of your files in the tar file... The effect will be the same.
That seems to give me an error:

Quote:
mashcaster@mashcaster-desktop:~$ tar -C /home/mashcaster/Desktop/backupthis/ --exclude=backup.tar -cf /home/mashcaster/Desktop/backupthis/backup.tar *
tar: abusesingingspe00yeargoog_meta.xml: Cannot stat: No such file or directory
tar: Arabic Basics: Cannot stat: No such file or directory
tar: Desktop: Cannot chdir: No such file or directory
tar: Error is not recoverable: exiting now
mashcaster@mashcaster-desktop:~$
 
Old 01-03-2009, 05:05 AM   #12
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Try to cd into the directory, and get rid of that -C /dir stuff.
 
Old 01-03-2009, 05:06 AM   #13
mashcaster
Member
 
Registered: Dec 2008
Posts: 67

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by i92guboj View Post
Try to cd into the directory, and get rid of that -C /dir stuff.
That worked perfectly! Thanks!
 
  


Reply

Tags
tar


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
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
installation problems with libxml2-2.2.66.tar.gz and libxml2-devel2-2.6.20-3.tar.gz g-string 3 Linux - Software 6 11-24-2005 11:39 AM
Diferance between rpm, tar, tar.gz, scr.tar, etc mobassir Linux - General 12 08-21-2003 06:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:00 PM.

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
Open Source Consulting | Domain Registration