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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-01-2009, 10:34 AM
|
#1
|
Member
Registered: Dec 2008
Posts: 67
Rep:
|
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
|
|
|
01-01-2009, 10:48 AM
|
#2
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529
|
cd to the directory
you can use the -C option
man tar
|
|
|
01-01-2009, 11:38 AM
|
#3
|
Member
Registered: Dec 2008
Posts: 67
Original Poster
Rep:
|
I tried that before and it didn't work i.e.
tar -Ccf /home/user/Desktop/backupthis/backup.tar /home/user/Desktop/backupthis/
|
|
|
01-01-2009, 02:13 PM
|
#4
|
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039
Rep:
|
try:
tar -C /home/user/Desktop --exclude=backup.tar cf /home/user/Desktop/backupthis/backup.tar backupthis
|
|
|
01-01-2009, 02:24 PM
|
#5
|
Member
Registered: Dec 2008
Posts: 67
Original Poster
Rep:
|
I tried that and I get a message saying
Quote:
tar: You must specify one of the `-Acdtrux' options
|
|
|
|
01-01-2009, 02:34 PM
|
#6
|
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039
Rep:
|
sorry, i missed a character!
Try:
tar -C /home/user/Desktop --exclude=backup.tar -cf /home/user/Desktop/backupthis/backup.tar backupthis
|
|
|
01-01-2009, 04:53 PM
|
#7
|
Member
Registered: Dec 2008
Posts: 67
Original Poster
Rep:
|
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?
|
|
|
01-01-2009, 05:13 PM
|
#8
|
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039
Rep:
|
tar -C /home/user/Desktop/backupthis --exclude=backup.tar -cf /home/user/Desktop/backupthis/backup.tar .
|
|
|
01-03-2009, 04:50 AM
|
#9
|
Member
Registered: Dec 2008
Posts: 67
Original Poster
Rep:
|
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?
|
|
|
01-03-2009, 04:54 AM
|
#10
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083
|
Quote:
Originally Posted by mashcaster
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.
|
|
|
01-03-2009, 05:01 AM
|
#11
|
Member
Registered: Dec 2008
Posts: 67
Original Poster
Rep:
|
Quote:
Originally Posted by i92guboj
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:~$
|
|
|
|
01-03-2009, 05:05 AM
|
#12
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083
|
Try to cd into the directory, and get rid of that -C /dir stuff.
|
|
|
01-03-2009, 05:06 AM
|
#13
|
Member
Registered: Dec 2008
Posts: 67
Original Poster
Rep:
|
Quote:
Originally Posted by i92guboj
Try to cd into the directory, and get rid of that -C /dir stuff.
|
That worked perfectly! Thanks! 
|
|
|
All times are GMT -5. The time now is 06:00 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|