I have a command I am running produces a ton of output, I want to silence the output without writing to a file. I have used the following to send all output to a file, but again I don't want any file output:

command > out.txt 2>&1

I have used command > /dev/null on my CentOS box before, but I can't find a similar thing for windows.

  • I hope you used command > /dev/null on your CentOS. – Kurt Pfeifle Aug 2 '10 at 20:43
  • @pipitas whatever i did it worked :D – Alec Gorge Aug 11 '10 at 18:19
  • If you indeed used command > /bin/null on CentOS, you have created a common file file named /bin/null on your system. You may say 'It worked!', if you want. This file now contains the stdout and stderr output of your command. Usually, in /bin/ there are only executable files. And usually, only the root user is allowed to create files there. So if that file is there, you did run your command as root user... /bin/null usually doesn't exist -- and /dev/null (which I mentioned) usually is used as the 'black whole' where unwanted output should disappear in... – Kurt Pfeifle Aug 11 '10 at 23:13
  • Good point, I hadn't thought of that. However, I am pretty sure it is just my faulty memory because I was on Windows at the time. – Alec Gorge Aug 18 '10 at 3:15

You want command > nul 2>&1.

  • thanks! that works. I need to wait 12 minutes to accept the answer though (serverfault requirement)! – Alec Gorge Apr 16 '10 at 3:22
  • 8
    This only redirects stdout. You also need > nul 2>&1 or 2> nul to kill stderr. – user1686 Apr 16 '10 at 14:02
  • Yes I know that, but thanks for mentioning it for others that visit this question! – Alec Gorge Apr 19 '10 at 20:52
  • just to add, I was getting permission denied error while using : sudo hostname -f 2> nul whereas following command worked well : sudo hostname -f 2> /dev/null For those who run out into permission issue while using nul – Ranvir Feb 10 '15 at 12:34
  • 2
    @AminM nul is Windows' special keyword for a null output (i.e. discard output). On *nix-based systems (like Ranvir is referring to) they instead use the special file /dev/null. The > means "redirect" (and 2> means redirect buffer 2 -- which is the error output) – Doktor J May 31 '19 at 17:11

You want command > $null 2>&1

nul only works in command prompt whereas $null works in powershell.

  • 3
    Command Prompt is cmd.exe. '> null' creates a file called 'null' with whatever you're directing into it from cmd.exe and from PowerShell. – Mr. Smythe Jul 29 '15 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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