How to Hide curl Output in Linux?

The curl is a powerful command line utility primarily utilized for file transfer. Users can upload and download data using protocols such as HTTP, POP3, TFTP, FTP, and others. The curl command requires minimal user interaction and shows the complete progress of what is done. The output of the curl command can be hidden for the reasons such as to improve readability, reduce clutter, or view only the relevant information like errors.

This guide explains the different methods of hiding the curl output on Linux.

  • Hide curl Output
  • Hide curl Output but Print the Error

How to Hide curl Output in Linux?

To hide the curl output, use the “curl” command with the “-s” or “— silent” and “-o /dev/null” options as in this format:

Syntax:

$ curl -s -o /dev/null URL

The explanation of the above syntax is explained:

  • The “-s” flag stands for “silent” and tells curl to hide any unnecessary output such as errors or progress
  • The “-o” flag stands for “output” and specifies the output file.
  • The “/dev/null” is a file that discards any data written to it and discards the output from the curl command.
  • The URL is the website’s address.

Let’s see the output of the curl command with and without the “-s” option.

Standard curl Output 

The curl command, without the “-s” flag, is executed this way:

$ curl google.com.

The above image shows the whole output of the curl command.

Suppress the curl Output Using the -s and -o /dev/null Flag

The curl command with the “-s” and “-o /dev/null” flags are executed in this way:

$ curl -s -o /dev/null https://google.com

Now the output is hidden, but what if there is an error? Here is an example to see if it displays the errors:

$ curl -s -o /dev/null https://googlee.com.

As expected, it did not display any error even though nothing is called “https://googlee.com.”

Hide curl Output but Print the Error?

To hide the correct output but print the error, use the “-S” flag with “-s -o /dev/null” in this way:

$ curl -S -s -o /dev/null https://googlee.com

The above image provides evidence that -S flag when used with  “-s -o /dev/null” flags, also displays errors. 

Note: It hides the output if there is no error.

Conclusion

To hide the output of the curl command can be used to hide sensitive information like the authentication token. It is used to view only the required information, like errors or no errors, which could come in handy where the curl command output is too long to read. This guide explained the flags required to hide the curl output in Linux.