Question

What would be the best way to store the name of an extracted file from a tar to a text file?

I want to extract one file from a tar and store the name of the extracted file to a temp file.

tar -xvf tar_file.tar file_to_be_extracted
Was it helpful?

Solution

If you know the name to be extracted, echo file_to_be_extracted > temp.file?

Or, more seriously, send the output from tar to a file:

tar -xvf tar_file.tar file_to_be_extracted 2>&1 | tee temp.file

This sends both standard error and standard output through tee which writes to the named file and to its standard output. If all goes well, just the file name will be in the file. If something goes wrong, the error messages will be in the file instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top