linux腳本命令解釋

linux腳本命令解釋

當我讀取 makefile 腳本時,遇到以下 linux 腳本命令:

mv obj/*.o .  2>/dev/null 

這個指令是什麼意思?我理解的意思是資料夾中mv obj/*.o .所有帶有後綴的檔案都會被移動到當前資料夾中。這是什麼意思?當它們結合在一起時,目的是什麼?謝謝!oobj2>

答案1

你正在看輸出重定向 (Bash)。 2 代表“stderr”,錯誤輸出。透過將其重定向到/dev/null,您將把它丟棄到遺忘的位置。不過,常規輸出“stdout”或 1 仍然顯示(預設在您的終端中)。

基本上,這只是消除mv命令的錯誤輸出。

上面連結中的一個片段更概括地解釋了它:

COMMAND_OUTPUT >
  # Redirect stdout to a file.
  # Creates the file if not present, otherwise overwrites it.

  ls -lR > dir-tree.list
  # Creates a file containing a listing of the directory tree.
[..]
1>filename
  # Redirect stdout to file "filename."
1>>filename
  # Redirect and append stdout to file "filename."
2>filename
  # Redirect stderr to file "filename."
2>>filename
  # Redirect and append stderr to file "filename."
&>filename
  # Redirect both stdout and stderr to file "filename."

答案2

順便說一句,有時您可能想阻止在螢幕上顯示,但可能想將其捕獲到文件中。如果是這種情況,你可能會這樣做:

mv obj/*.o . > move.log 2>&1

相關內容