how to suppress error messages?

When I type a certain command in UNIX, and if there’s an error message, it outputs onto the screen. How do I suppresses those error messages into a file instead?

Depends on what command and whether the messages went to stdout or stderr. If stdout, then:

command > errs

If stderr, then:

command 2> errs

If both, then:

command > errs 2>&1

Unfortunately commands can be inconsistent about what goes to stdout and what goes to stderr so you’ll just have to experiment.

I don’t know why, but I’m typing this command, and I keep getting this error “Ambiguous output redirect”

/usr/sfw/bin/wget Google >> logfile 2>&1

Ambiguous output redirect

Nothing gets written into the logfile. All I get is that error.

Nothing gets written to the log file either way.

What are you trying to achieve?

Try man wget

Think you’re trying to get a log noticed a few flags that may do it for you.

Think you want

wget www.google.com -o logfile

As others have pointed out there are better ways of doing it with wget, but you must not have typed it in as shown, you must have some stray spaces somewhere, because that redirection is perfectly legal. In particular >> has no space in between and 2>&1 has no spaces either. Also there is a space after logfile.

And I don’t know why you have wget in /usr/sfw/bin when wget is available as a standard package in openSUSE.

PS: I’m assuming you are using bash. If you are using csh or tcsh, my sympathies.

Hi
You do realize it’s also solaris the OP is using :wink:


malcolml@ernie-solaris$ which wget
/usr/sfw/bin/wget
malcolml@ernie-solaris$ uname -a
SunOS ernie-solaris 5.10 Generic_127111-05 sun4u sparc SUNW,Ultra-5_10

But wget is wget… if the OP is using Linux then the command should
be;


/usr/bin/wget http://www.google.com >> logfile 2>&1


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.1 (i586) Kernel 2.6.27.21-0.1-pae
up 1 day 22:03, 2 users, load average: 0.41, 0.23, 0.13
ASUS eeePC 1000HE ATOM N280 1.66GHz | GPU Mobile 945GM/GMS/GME

Ah, I should have twigged that something was different when he wrote UNIX. I suppose we can teach old UNIX dogs some tricks after all. (But actually I’m a born-again as Linux puppy old UNIX dog ;))

But still, that is legal in Bourne shell too, so he must be using csh or tcsh. Oh well, there’s no accounting for taste. :wink: