[LINUX] Output of the previous executed command

To simply view the output of the previous executed command, you can run the following echo:

~$ echo "$?"

Indeed, $? returns the output code or message of the last executed command. Below a common example:

~$ touch foobar
~$ rm foobar
~$ echo "$?"
0 ~$ rm foobar
rm: cannot remove 'foobar': No such file or directory
~$ echo "$?"

A value of 0 means “Success”, while a value of 1 means “Fail”.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.