Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Previous: appending files, Up: append


4.2.2.2 Multiple Files with the Same Name

You can use --append (-r) to add copies of files which have been updated since the archive was created. (However, we do not recommend doing this since there is another tar option called --update; see update for more information. We describe this use of --append here for the sake of completeness.) When you extract the archive, the older version will be effectively lost. This works because files are extracted from an archive in the order in which they were archived. Thus, when the archive is extracted, a file archived later in time will replace a file of the same name which was archived earlier, even though the older version of the file will remain in the archive unless you delete all versions of the file.

Supposing you change the file blues and then append the changed version to collection.tar. As you saw above, the original blues is in the archive collection.tar. If you change the file and append the new version of the file to the archive, there will be two copies in the archive. When you extract the archive, the older version of the file will be extracted first, and then replaced by the newer version when it is extracted.

You can append the new, changed copy of the file blues to the archive in this way:

     $ tar --append --verbose --file=collection.tar blues
     blues

Because you specified the --verbose option, tar has printed the name of the file being appended as it was acted on. Now list the contents of the archive:

     $ tar --list --verbose --file=collection.tar
     -rw-r--r-- me user     28 1996-10-18 16:31 jazz
     -rw-r--r-- me user     21 1996-09-23 16:44 blues
     -rw-r--r-- me user     20 1996-09-23 16:44 folk
     -rw-r--r-- me user     20 1996-09-23 16:44 rock
     -rw-r--r-- me user     58 1996-10-24 18:30 blues

The newest version of blues is now at the end of the archive (note the different creation dates and file sizes). If you extract the archive, the older version of the file blues will be replaced by the newer version. You can confirm this by extracting the archive and running ‘ls’ on the directory.

If you wish to extract the first occurrence of the file blues from the archive, use --occurrence option, as shown in the following example:

     $ tar --extract -vv --occurrence --file=collection.tar blues
     -rw-r--r-- me user     21 1996-09-23 16:44 blues

See Writing, for more information on --extract and See –occurrence, for the description of --occurrence option.

 
 
  Published under the terms of the GNU General Public License Design by Interspire