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-28-2009, 02:38 AM
|
#1
|
Member
Registered: Nov 2006
Posts: 56
Rep:
|
tar -k --keep-old-files extraction problem
I've been trying to extract an archive using tar and want to prevent it from overwriting any files with the same names using
Code:
tar -xkvf --keep-old-files (file.tar)
but it keeps giving errors.
Was wondering how to do it?
Thanks.
|
|
|
01-28-2009, 02:47 AM
|
#2
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
First don't put --keep-old-files AND -k. They are two forms (long and short) of the same option. Second invert the groups of option and it should work. This is because the -f option accepts as argument the name of the archive, so that the part f --keep-old-files is interpreted as the name of the archive. In summary the solution is either one of the following
Code:
$ tar --keep-old-files -xvf file.tar
$ tar -xkvf file.tar
|
|
|
02-02-2009, 01:44 AM
|
#3
|
Member
Registered: Nov 2006
Posts: 56
Original Poster
Rep:
|
Thanks.
One thing that confused me is that there are several alternatives for the "-k" option - some of which are the opposite of what I want.
I assume there is some interactive dialog that comes up when you use "-k"?
I just tried the
Code:
tar --keep-old-files -xvf file.tar
method and got alot of
Quote:
Cannot open: File exists
tar: Skipping to next header
|
which ended with
Quote:
tar: Error exit delayed from previous errors
|
.
Last edited by somae; 02-02-2009 at 01:55 AM.
Reason: adding more information
|
|
|
02-02-2009, 01:57 AM
|
#4
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Not an interactive dialog, but just an error message. You can either chose --overwrite to force overwriting OR --keep-old-files to prevent this behavior. That is your choice is made prior to run the extraction of the archive, not in run time.
What do you mean for "there are several alternatives for the -k option"? To me the -k option is unique.
|
|
|
02-03-2009, 12:31 AM
|
#5
|
Member
Registered: Nov 2006
Posts: 56
Original Poster
Rep:
|
Quote:
Originally Posted by colucix
What do you mean for "there are several alternatives for the -k option"? To me the -k option is unique.
|
The "tar --help" file says this:
Code:
-k, --keep-old-files don't replace existing files when extracting
--keep-newer-files don't replace existing files that are newer than
their archive copies
--no-overwrite-dir preserve metadata of existing directories
--overwrite overwrite existing files when extracting
--overwrite-dir overwrite metadata of existing directories when
extracting (default)
--recursive-unlink empty hierarchies prior to extracting directory
--remove-files remove files after adding them to the archive
It makes it look like these are all functions of "-k".
|
|
|
02-03-2009, 01:41 AM
|
#6
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by somae
It makes it look like these are all functions of "-k".
|
Nope. It tells that the -k option is the short form of --keep-old-files, while the other options listed do not have a short form. Indeed they are all related to the behavior of tar in case of already existing files with the same name, but -k is --keep-old-files only.
I see now the reason why you used both -k and --keep-old-files in the same command line. Well, the help can be confusing, but keep in mind that an option may accept one or more arguments, but never accept another option as argument, that is a string beginning with - or --.
Code:
-k, --keep-old-files don't replace existing files when extracting
The comma tells you they are two different alternatives of the same option.
|
|
|
02-03-2009, 01:45 AM
|
#7
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by somae
tar: Error exit delayed from previous errors
|
This is the normal behavior. If one or more files already exist, the file(s) are not extracted from the archive and tar gives an error message and an exit status different from zero.
|
|
|
02-27-2009, 02:34 PM
|
#8
|
Member
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Rep:
|
If you've specified "keep" or "-k" then tar shouldn't complain that a file already exists, it should ignore it. I think that's the crux of the problem.
|
|
|
02-27-2009, 02:51 PM
|
#9
|
Member
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Rep:
|
I've been reading through the info pages, and this is what is says verbatum:
Quote:
To be even more cautious and prevent existing files from being replaced, use the `--keep-old-files' (`-k') option. It causes `tar' to refuse to replace or update a file that already exists, i.e., a file with the same name as an archive member prevents extraction of that archive member. Instead, it reports an error.
|
So evidently it's by design.
|
|
|
All times are GMT -5. The time now is 04:56 AM.
|
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
|
|