相关文章推荐
冲动的楼梯  ·  ASP.NET Core で HTTPS ...·  2 周前    · 
完美的鸡蛋面  ·  vue3 npm run ...·  6 天前    · 
谦虚好学的椰子  ·  C#Winform ...·  4 天前    · 
大鼻子的海龟  ·  c# dev ...·  4 天前    · 
冷冷的草稿本  ·  Keywhiz - OSCHINA - ...·  1 年前    · 
发怒的棒棒糖  ·  jenkins ...·  1 年前    · 
粗眉毛的大熊猫  ·  Window.OnSourceInitial ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I would like to redirect the output generated from a background application in Linux to /dev/null.

I am using kate text editor and it prints all the debug messages on the terminal which I would like to redirect to /dev/null.

Any idea how to do it ?

Thanks

>/dev/null 2>&1 means redirect stdout to /dev/null AND stderr to the place where stdout points at that time

If you want stderr to occur on console and only stdout going to /dev/null you can use:

yourcommand 2>&1 > /dev/null

In this case stderr is redirected to stdout (e.g. your console) and afterwards the original stdout is redirected to /dev/null

If the program should not terminate you can use:

nohup yourcommand &

Without any parameter all output lands in nohup.out

If this is the last command in a bash file, one thing that I noticed is that it leaves the command console that called the file without a prompt. – Dennis Mar 10, 2013 at 17:28 @elig redirecting output of an already running application is not possible imo, or at least not that easily, because the redirection via dup2() happens immediately after fork() but before exec*(). Once exec*() has executed the program, the shell has not the capability to redirect the output of that process. Correct me if I am wrong, but I don't know about a shell that has implemented such functionality. – evildead Oct 17, 2019 at 13:12 What is the difference between yourcommand 2>&1 > /dev/null and yourcommand > /dev/null? Both seem to redirect stderr to stdout. – avriis Dec 17, 2020 at 11:03 The manual and preference referred to is found here: gnu.org/software/bash/manual/html_node/Redirections.html (at section 3.6.4) – brokkr Aug 22, 2021 at 17:06

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.