大网数据广告活动
服务器运维问答

What is the meaning of the "/dev/null 2>&1" in a Cronjob entry?

· 52CE 我爱测

Can someone explain to me what is the meaning of "2>&1" doing here in the below cron job 0 23 * * * wget -q -O /dev/null "https://example.com/index.php" > /dev/null 2>&1

问题原文

原帖链接 · mahen3d · CC BY-SA 4.0

Can someone explain to me what is the meaning of "2>&1" doing here in the below cron job

0 23 * * * wget -q -O /dev/null "https://example.com/index.php" > /dev/null 2>&1

社区高分解答

原帖链接 · digijay · CC BY-SA 4.0

It means that stderr (2 - containing error messages from the executed command or script) is redirected (>&) to stdout (1 - the output of the command) and that the latter is being redirected to /dev/null (the null device).

This way you can suppress all messages that might be issued by the executed command. In cron this is often done to avoid being spammed by lots of irrelevant messages from service scripts. Nevertheless be careful with this as some messages might be important.

More information on output redirects can be found in The Linux Documentation Project here and here. The null device is described here.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-08-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。