Sunday, May 5, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 515  / 1 Year ago, fri, february 17, 2023, 12:37:09

When I read a script of makefile, I meet with the following linux script command:



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


What does this command mean? I understand mv obj/*.o . means that all the files with suffix o in the obj folder will be moved to the current folder. What does 2> mean? When they are combined together, what is purpose? Thanks!


More From » command-line

 Answers
4

You're looking at output redirection (Bash). 2 stands for 'stderr', the error output. By redirecting it to /dev/null, you're discarding it to oblivion. Regular output, 'stdout' or 1 is still shown (in your terminal by default), though.



Basically, this is just silencing error output of the mv command.



A snippet from the above link explains it more general:



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."

[#31416] Sunday, February 19, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
splenueak

Total Points: 448
Total Questions: 118
Total Answers: 110

Location: Vanuatu
Member since Mon, Oct 3, 2022
2 Years ago
;