Script to find tar archives, read tar file contents, output content to an index file.
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
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.
Script to find tar archives, read tar file contents, output content to an index file.
Just doing some tests, making directories into tar files:
find . -type d -links 2 -exec tar cvf {}.tar {} \;
Works fine.
I have been trying to do:
$ find . -type f -name \*.tar -execdir tar tvf {} > {}.lst \;
The result:
tar: Error is not recoverable: exiting now
tar: ./Outbox.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./Notes.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./cert8.db: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./tasks.ics: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./system.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./categories.xml: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./key3.db: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./signature-1: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./signature-0: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./calendar.ics: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./system.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./secmod.db: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./gvfs-metadata.tar: Cannot open: No such file or directory
Among other things (-iname, choosing between -execdir and using fixed or user-supplied full paths with loops, extension checking, getting rid of error messages) you need proper quoting as in
Code:
find /some/path/ -type f -iname \*.tar.\* 2>/dev/null|egrep -ie "\.(bz|bz2|gz|xz|z)$" 2>/dev/null|while read FILE; do tar -tf "${FILE}" > "${FILE}.ndx" 2>/dev/null; done
Among other things (-iname, choosing between -execdir and using fixed or user-supplied full paths with loops, extension checking, getting rid of error messages) you need proper quoting as in
Code:
find /some/path/ -type f -iname \*.tar.\* 2>/dev/null|egrep -ie "\.(bz|bz2|gz|xz|z)$" 2>/dev/null|while read FILE; do tar -tf "${FILE}" > "${FILE}.ndx" 2>/dev/null; done
?
I'm mostly a hardware guy, so please go easy on me.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.