LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack 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: Slackware current
Posts: 8,460

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
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,007

Rep: Reputation: 81
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,007

Rep: Reputation: 81
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,007

Rep: Reputation: 81
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: 3,905

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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: 3,905

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 10 02-23-2008 05:40 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


All times are GMT -5. The time now is 09:31 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration