1

I would like to know if it is possible to extract a specific file inside tar file using find command.

Example:

  • Normal situation: find filaname called "file1" and extract

    tar xvf tarfilename file1 
    
  • My Situation:

    find . -iname "*tar*" -exec tar -xvf *file1* {} \;
    

    I don't know if possible to do.

Reason:

My internal prod system is not allowed to run tar command.

I know that the best practice is running tar directly, but the hope dies last

Thanks in advance.

1
1

If you can't run tar directly from the shell, but can run it from a different command, then you can do:

env tar xvf file.tar file1
find . -prune -exec tar xvf file.tar file1 ';'
perl -e 'exec @ARGV' tar xvf file.tar file1

However, that still runs tar, so you would likely still be infringing at least the spirit of the law that forbids you from running tar.

Instead of tar, you could also run pax instead (that's the POSIX command for dealing with archives).

pax -r < file.tar file1
1
  • I'm able to use env tar to solve my problem Thank you so much. – Leandro Lopes Nov 6 '20 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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