Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to add file.txt to existing archive arch.rar, but in a way that arch.rar will contain only file.txt ? I use command like below, but arch.rar is updated and contains old files too. I don't see switch to do that.

rar a arch.rar file.txt
share|improve this question
1  
I know you've said you want to do it within RAR only (comment on deleted answer) but I think it would be simpler to delete the old archive and recreate it so that it just contains the new file. –  ChrisF Mar 4 '11 at 10:08
    
There is the "d" command rar d arch.rar *.* - but it doesn't look like you can combine commands in one operation. –  ChrisF Mar 4 '11 at 10:24
add comment

1 Answer

It doesn't make sense ;) but you can do something like this:

$ FILE2UPD=file.2; RARCH=arch.rar && for i in `rar l $RARCH | grep -v $FILE2UPD | tail -n +9 | head -n -3 | cut -f2 -d' '`; do rar d $RARCH $i; done && rar u $RARCH $FILE2UPD

example:

$ cat file.1
test 1
$ cat file.2
test 2
$ cat file.3
test 3
$ rar a arch.rar file.*

RAR 3.93   Copyright (c) 1993-2010 Alexander Roshal   15 Mar 2010
Shareware version         Type RAR -? for help

Evaluation copy. Please register.

Creating archive arch.rar

Adding    file.1                                                      OK 
Adding    file.2                                                      OK 
Adding    file.3                                                      OK 
Done

$ echo "test4" > file.2
$ cat file.2
test4

$ FILE2UPD=file.2; RARCH=arch.rar && for i in `rar l $RARCH | grep -v $FILE2UPD | tail -n +9 | head -n -3 | cut -f2 -d' '`; do rar d $RARCH $i; done && rar u $RARCH $FILE2UPD

RAR 3.93   Copyright (c) 1993-2010 Alexander Roshal   15 Mar 2010
Shareware version         Type RAR -? for help

Deleting from arch.rar
Deleting file.1
Done

RAR 3.93   Copyright (c) 1993-2010 Alexander Roshal   15 Mar 2010
Shareware version         Type RAR -? for help

Deleting from arch.rar
Deleting file.3
Done

RAR 3.93   Copyright (c) 1993-2010 Alexander Roshal   15 Mar 2010
Shareware version         Type RAR -? for help

Evaluation copy. Please register.

Updating archive arch.rar

Updating  file.2                                                      OK 
Done



$ rar l arch.rar 

RAR 3.93   Copyright (c) 1993-2010 Alexander Roshal   15 Mar 2010
Shareware version         Type RAR -? for help

Archive arch.rar

 Name             Size   Packed Ratio  Date   Time     Attr      CRC   Meth Ver
-------------------------------------------------------------------------------
 file.2              6       16 266% 04-03-11 12:45 -rw-r--r-- 012EC35E m3b 2.9
-------------------------------------------------------------------------------
    1                6       16 266%


$ rm file.*
$ rar e arch.rar 

RAR 3.93   Copyright (c) 1993-2010 Alexander Roshal   15 Mar 2010
Shareware version         Type RAR -? for help


Extracting from arch.rar

Extracting  file.2                                                    OK 
All OK
$ cat file.2 
test4
share|improve this answer
    
Of course it will fail if archived files have space in name –  Satanowski Mar 4 '11 at 12:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.