Key Takeaways
- The lack of terminal output from some successful Linux commands stems from a historical design choice.
- Quiet programs allow building pipelines easily at the shell and continue to influence Linux development, dating back to Unix Philosophy.
- Check for command success by examining the exit status, where 0 signifies success and other numbers indicate errors.
When you first start using Linux, you’ll often find yourself using the command line. You type a command, wait for output, and then—nothing. Just a blinking cursor, waiting for your input. What’s going on? Here’s why a lot of Linux commands just say nothing when they run successfully.
Why No Terminal Output?
For example, you might run the ls command in a directory without any files. You’ll simply get your prompt back without anything being printed to the terminal.
The main reason that a lot of terminal commands don’t print anything when they succeed is that this is a historical holdover from the Unix days.
A lot of Unix systems ran on Teletypes, which ran very slowly. Printing when an operation was successful just wasted time and paper.
Here’s a video where you can see—and hear—one in action.
Programmers Like Quiet Programs to Build Pipelines
Having programs without output by default also makes it to build programs into pipelines. This was a key element of the “Unix Philosophy” that still influences much Linux development today.
The traditional way of designing command-line programs in Unix-like systems is to chain the output to the input of another program, sometimes several, known as a pipeline, from the | operator. Under this line of thinking, if ls outputted something like “0 files found” other programs would have to work on it. Having no files is useless information to commands farther down the pipeline.
For example, you might pipe the ls command to wc:
ls | wc
Without any files from ls, wc will display a character count of 0.
As Eric S. Raymond wrote in “The Art of Unix Programming,” “Programs that babble don’t tend to play well with other programs.”
How to Check Exit Status to See If an Operation Succeeded
Linux programs will typically print a message to the standard error if something goes wrong. Typically, standard error goes to the terminal, though it can be redirected into another file.
A command-line program sets a variable called the exit status when it finishes running. An exit status of 0 indicates success, where any other number indicates an error. You can check the exit status of the last command run with the $? variable:
echo $?
Many shells can be configured to display an error at the prompt if the last command terminated with a nonzero exit status. Here’s an example with the Oh My Zsh extension for zsh, where the prompt turns red to indicate an error:
Commands that might take a long time, such as updating your packages, will usually generate more output.
Linux programs have inherited the Unix style of minimalism, and that includes their output. Now you know why you might sometimes get just a blank prompt when you run some Linux commands in the terminal. In Linux, the best output can occasionally be none at all.