LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-15-2014, 09:15 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Rep: Reputation: 52
tar does not do what I expected


I have never used tar before and trying it does not work as I expected. I still have to try it as a normal user but I do not think my problem is due to the fact I do it as root.

First, file "home.tar" does not exist and I execute the following command:
Code:
sudo tar -c -p -n -X /home/user01/tar/xclude -f /media/sandisk01/home.tar /home/ /etc/apache2/
This gives a file "home.tar" of about 1.6G on the usb stick.

then I immediately run the following command:
Code:
sudo tar -p -n -u -X /home/user01/tar/xclude -f /media/sandisk01/home.tar /home/ /etc/apache2/
The same file "home.tar" now takes about 3.3G, it looks like this second command has appended a new archive to the old one when I thought the first command created the archive with "-c" and the second one updated it with "-u" which should have resulted in an unchanged archive since no file has been changed.

I do not understand what is meant by "seekable" in the man page about "-n".

Can someone tell me what I am doing wrong?

Thank you for your help
 
Old 03-15-2014, 10:59 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Couldn't find option -n in the documentation.
 
1 members found this post helpful.
Old 03-15-2014, 11:23 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well my man page says:
Code:
-n, --norecurse, --no-recursion
             (c, r, u modes only) Do not recursively archive the contents of directories.
Might help if you tell us which version of tar?

Whilst you are correct that running as root will not alter the outcome (except -p as root can overwrite permissions), I would think you would test a new function that you do not know how to use as
a regular user, just in case something went wrong??
 
1 members found this post helpful.
Old 03-15-2014, 12:53 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
And for me, "info tar" contains:
`--seek'
`-n'
Assume that the archive media supports seeks to arbitrary locations. Usually `tar' determines automatically whether the archive can be seeked or not. This option is intended for use in cases when such recognition fails.
It's one of those short options that has seen several conflicting uses as tar evolved, and should be avoided.

I can't reproduce the OP's problem. Output from "tar --version" needed.
 
1 members found this post helpful.
Old 03-18-2014, 05:30 AM   #5
Sandcrawler
LQ Newbie
 
Registered: Feb 2014
Distribution: CentOS
Posts: 9

Rep: Reputation: Disabled
tar

Try using a 'date' (-N --newer --after-date) in combination with the -u operator.

http://www.gnu.org/software/tar/manu...ion/after.html

My example (sorry for not using same files was a quick test)

Code:
# tar -c -p -n -X /SIPP/Traffic -f /test/backup.tar /SIPP/ /home/Unreal3.2/
gives:
342M Mar 18 10:26 backup.tar

Code:
# tar -p -n -u --after-date '1 day ago' -X /SIPP/Traffic -f /test/backup.tar /SIPP/ /home/Unreal3.2/
gives:
342M Mar 18 10:26 backup.tar

Although i also noted while doing this that the excluded file was still included.. but hey..


so it will only update anything modified after 1 day ago.
If you check link above will also give other date formats if checking the link in text.

version used:
tar (GNU tar) 1.23


Edit:
o btw - i did manage to replicate OPs issue with commands given. I think if no date is given it will just reappend all given files again.


Hope this helps.

Last edited by Sandcrawler; 03-18-2014 at 06:42 AM.
 
1 members found this post helpful.
Old 03-18-2014, 07:57 AM   #6
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
I use tar 1.26
I found tar -u does not replace an old file with a newer one, it keeps both which is not what I wanted.
Thank you all.
 
Old 03-18-2014, 08:21 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
The name "tar" comes from "Tape ARchiver". It was designed to work with linear magnetic tapes. There is no practical way to replace a file in the middle of such a tape -- it would require reading and re-writing the whole remainder of the tape.
 
  


Reply



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
PIPE find results to tar not behaving as expected. a1danel Linux - Newbie 4 01-15-2011 01:50 PM
tar not working as expected pendal Linux - Newbie 6 07-31-2009 09:52 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:13 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
Open Source Consulting | Domain Registration