UNDER CONSTRUCTION!!!

Tech News

Keeping You Up To Date With The Latest Tech News & Virus Threats
Font size: +

Why Don't Linux Commands Say Anything When They Run?

Why Don't Linux Commands Say Anything When They Run?

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.

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.

Output of Linux ls command on an empty directory called

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.

Output in Linux terminal of ls command piped into wc, with no output.

As Eric S. Raymond wrote in "The Art of Unix Programming," "Programs that babble don't tend to play well with other programs."

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:

Oh My ZSH prompt turning red after a command returns a nonzero exit status at the Linux terminal.

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.

(Originally posted by David Delony)
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

I'm a tech editor and cover shopping events. Here ...
BEver Wonder What a Krabby Patty Tastes Like? You ...
 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Wednesday, 02 October 2024

Captcha Image

I Got A Virus and I Don't Know What To Do!

I Need Help!