Uvais Ibrahim
Uvais Ibrahim

Reputation: 169

How to hide displaying terminal command output

When I run this command,

sudo htpasswd -b /home/reynolds/.htpasswd admin admin

I am getting output Updating password for user admin in terminal but I dont want to display that output. So I searched some in google and try with the following commands.

sudo htpasswd -b /home/reynolds/.htpasswd admin admin 2>&1
sudo htpasswd -b /home/reynolds/.htpasswd admin admin > /dev/null

But still I am getting that output in terminal.Please help to avoid displaying such output while running this command. Please advice me as I am a very beginner in shell scripting.

Thanks.

Upvotes: 3

Views: 5901

Answers (3)

Alex M.
Alex M.

Reputation: 21

The reason you are getting this error is that sudo only applies to the very first command in the argument list.

The way to get around this is to encapsulate your command like so, using bash as an example:

sudo bash -c "htpasswd -b /home/reynolds/.htpasswd admin admin 2>&1"

Just remember that this creates a new bash shell, so any relative paths will not work and make sure that any environment variables you rely on, etc. are all available as well.

Upvotes: 2

nu1silva
nu1silva

Reputation: 149

Just do the following;

sudo htpasswd -b /home/reynolds/.htpasswd admin admin > /dev/null 2>&1

should hide everything!

Upvotes: 2

JBuenoJr
JBuenoJr

Reputation: 975

 > /dev/null

and normal output is suppressed but errors are still shown

follow the command with

 > /dev/null 2>&1

and everything, including errors is supressed

Upvotes: 7

Related Questions