Suppose I ran some command, and now want to save the output of that previous command to a text file (without re-running the command, of course, there's no reason to assume it's idempotent).

Is there some simple way to get that output of the previous command?

echo <magic_for_last_output> >file.txt

No, there isn't a way to save the last command's output to a file, as far as I know. The shell doesn't store that information.

However, you can hit the up arrow and add the redirection to the end of the last command, so you don't have to type anything new.

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.