Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have remove.sh which contains:

rm -v test.tmp

And I have install.sh which contains:

script remove.log -c './remove.sh'

What can I do so that whether or not test.tmp exists, I don't see any rm related messages on the screen but see removed 'test.tmp' or rm: cannot remove 'test.tmp': No such file or directory in remove.log which the script command produces?

share|improve this question

If your question is, "how do I suppress stderr output from a command", the answer will be something along the lines of:

command 2> /dev/null

This will redirect stderr (aka file descriptor 2) to /dev/null, which simply discards anything it receives.

However, the rm command supports the -f flag, which will prevent it from producing an error message if the file does not exist:

$ rm file_that_does_not_exist
rm: file_that_does_not_exist: No such file or directory
$ rm -f file_that_does_not_exist
share|improve this answer
Thanks for your answer, but no. I don't want to suppress stderr. I just want to hide it from showing up on the terminal but want it logged in my log file. -f flag won't work either as again i need to see the error in the log file. – Codrguy Feb 17 '12 at 23:35
In that case, you want script -c remove.log 'your command' > /dev/null. The script command will capture stdout and stderr to your log file, and the redirection will suppress all terminal output from the script command. – larsks Feb 18 '12 at 0:06

script is overkill for this. Yes it works, but thats not what script was made for. Script is used for applications which access the TTY directly, and dont use STDOUT/STDERR.

You can easily accomplish this with basic shell redirection.

./remove.sh &> remove.log
share|improve this answer

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.