Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I run the following command:

pkg_add emacs-23.4,2.tbz 2> output.log

The output still displays in the terminal. When I press , I get

pkg_add emacs-23.4,2.tbz 2 > output.log

with a space before the 2.

I did not originally put this. I try

pkg_add emacs-23.4,2.tbz > output.log 2>&1

Again, when I press , spaces have been added.

Why is this happening to me?

I am running csh on FreeBSD.

share|improve this question
Are you sure you are running bash or sh? On FreeBSD csh or tcsh is often the default. –  Craig Apr 4 '12 at 16:50
What does echo $SHELL show? –  Karlson Apr 4 '12 at 16:51
@Craig I'm on csh. –  gadgetmo Apr 4 '12 at 16:59
@Karlson I'm on csh. –  gadgetmo Apr 4 '12 at 17:00
i have edited.. –  gadgetmo Apr 4 '12 at 17:00
add comment

2 Answers

up vote 5 down vote accepted

The 2> redirect does not work with csh or tcsh.

Use the chsh command to change your shell to /bin/sh or /usr/local/bin/bash in order to use the 2> style redirect. Note: Do not change root's shell to /usr/local/bin/bash

csh and tcsh cannot redirect standard out and error separately, but >& will redirect the combined output to a file.

share|improve this answer
+1 and ✔. I changed shells using sh. –  gadgetmo Apr 4 '12 at 17:45
@Craig He's running pkg_add on FreeBSD, so I'm assuming this is for the root user (/bin/csh is the default for root on FreeBSD). In this case you should not change the shell to /usr/local/bin/bash. /bin/sh is acceptable. You could also just switch to another shell after logging in as root. –  James O'Gorman Apr 6 '12 at 23:21
@JamesO'Gorman Good catch I updated my answer. –  Craig Apr 7 '12 at 1:35
add comment

I know how to do it in Csh, but using 2 shells:

csh -c 'SOME_COMMAND 1>/dev/null' |& tee file.txt

Such a way allows to redirect only stderr to file.txt, without stdout - namely what you wanted.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.