PDA

View Full Version : Explain this line of code please



despdan
18th June, 2009, 10:57 AM
Now I know the first bit goto this address & get filename it's the -O filename 2> /dev/null bit I don't know what exactly it does.


wget -q http://webaddress/filename -O filename 2> /dev/null

red devil
20th June, 2009, 11:50 AM
Now I know the first bit goto this address & get filename it's the -O filename 2> /dev/null bit I don't know what exactly it does.


wget -q http://webaddress/filename -O filename 2> /dev/null


have a look here Of Zeros and Nulls (http://tldp.org/LDP/abs/html/zeros.html)

Mjolinor
20th June, 2009, 01:53 PM
the "-O" should be "-o" it just defines the output file name. And by piping the output to NULL you are telling it to be quiet about it, you won't see any screen output, it throws it away

despdan
20th June, 2009, 01:58 PM
have a look here Of Zeros and Nulls (http://tldp.org/LDP/abs/html/zeros.html)
Thanks red just what i was looking for:)

I was following another tut but skipped over little things like -f -0 -s & you just know there the things that need explaining:)

beady
23rd June, 2009, 12:09 AM
the "-O" should be "-o" it just defines the output file name. And by piping the output to NULL you are telling it to be quiet about it, you won't see any screen output, it throws it away
Not really true. "-o" defines where the logfile is written to, while "-O" specifies a file to save to. So the original command save the file "http://webaddress/filename" to the local file "filename", and discards any output generated from the "wget" program itself (which would usually get sent to stderr, which will default to the terminal, as described in the link posted by red devil). You can get pretty much the same effect by using
wget http://webaddress/filename -O filename -o /dev/null in which you have specified that logging goes to the /dev/null device (i.e. is thrown away).
Overall though, the purpose of the command is to download a file from t'internet silently, without any text being sent to a terminal.

edit: Actually, it's already "quiet" because of the "-q" option, so if successful, nothing will be displayed on the terminal. However, in the event of an error, like the url being invalid or a more serious error, the "2 > /dev/null" makes sure nothing is displayed.

Mjolinor
23rd June, 2009, 04:55 AM
Not really true. "-o" defines where the logfile is written to, while "-O" specifies a file to save to. So the original command save the file "http://webaddress/filename" to the local file "filename", and discards any output generated from the "wget" program itself (which would usually get sent to stderr, which will default to the terminal, as described in the link posted by red devil). You can get pretty much the same effect by using
wget http://webaddress/filename -O filename -o /dev/null in which you have specified that logging goes to the /dev/null device (i.e. is thrown away).
Overall though, the purpose of the command is to download a file from t'internet silently, without any text being sent to a terminal.

edit: Actually, it's already "quiet" because of the "-q" option, so if successful, nothing will be displayed on the terminal. However, in the event of an error, like the url being invalid or a more serious error, the "2 > /dev/null" makes sure nothing is displayed.

Yup, my bad. Apologies.