Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make a shell script where I type an url and it returns me the status code.So far I've tested wget is there any other cause it has the tendency to save whatever you run. Then I tried to some kind awk the output but it doesn't do you have any advices.

Edit for Zelda: I tried the first one

enter image description here

but I always receive : enter image description here

P.S. Also I tried HTTP without '',now I putted for curiosity

share|improve this question
You left out 2>&1 from the wget ... line, that makes the output to stderr go to the pipe and grep. Quotes around HTTP not needed. – Zelda Dec 14 '13 at 11:26
Oops, thx very much now it works – Phil_Charly Dec 14 '13 at 11:36
up vote 9 down vote accepted

You can simply use curl for it. I have written a simple script for it.

curl -sL $url -w "%{http_code} %{url_effective}\\n" "URL" -o /dev/null

Where URL is your URL which you have to test output will gives you status.


image showing status for URL

share|improve this answer

You can just stick with wget:

wget -O /dev/null http://unix.stackexchange.com 2>&1 | grep -F HTTP

that gives you:

HTTP request sent, awaiting response... 200 OK

which you can further trim with cut:

wget -O /dev/null http://unix.stackexchange.com 2>&1 | grep -F HTTP | cut -d ' ' -f 6

If the url does not exist, then there is no output.

With query for url:

echo "give your url"
read url
wget -O /dev/null $url 2>&1 | grep -F HTTP
echo "ok?"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.