Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

what is the best way to store the filename of an extracted file in a text file?

I have a script that extract a single file from a tar file and then I need to store the name extracted file to a txt file.

tar -xvf tarfile.tar filename 
share|improve this question
Have you tried tar -xvf tarfile.tar filename > filenamefile.txt? If that doesn't work, try it with 2> instead of >. – Scott Oct 26 '13 at 0:31
thanks! I tried using >> because its in a loop. anyway, what does 2> do? – william39 Oct 26 '13 at 1:10
2> redirects stderr, whereas > redirects standard output. The correct thing to do is to write normal output, eg the file list, on stdout, and error messages on stderr. Some programs get this wrong, so if one does not do what you want, you try the other. – fstx Oct 26 '13 at 8:41
And just to add a bit of background: Unix invented the idea that all processes should have two default output streams: one for normal output and one for error messages. This idea was that you should be able to run a command, redirect the (standard) output, and still have error message(s) appear on the screen. The problem that @fstx alludes to is that some programs/programmers use the error output stream (known as “standard error”) for status information and other metadata. I was afraid that tar would write the filenames to stderr because they are metadata, but I guess they did it correctly. – Scott Oct 26 '13 at 19:45

Your Answer


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

Browse other questions tagged or ask your own question.