ShareYourGroupShareYourGroupCommands

Linux and Mac commands

ping, curl and wget: network commands

A few commands answer most questions about a network: is it reachable, what is my address, and can I fetch this file? They were not run for this page, since the results would describe a real network. Sample outputs are illustrations.

ping: is it reachable?

Linux or Mac terminal not run here
ping -c 4 example.com
What the output looks like an illustration, not a real run
PING example.com (93.184.215.14): 56 data bytes
64 bytes from 93.184.215.14: icmp_seq=0 ttl=56 time=18.4 ms
64 bytes from 93.184.215.14: icmp_seq=1 ttl=56 time=17.9 ms
64 bytes from 93.184.215.14: icmp_seq=2 ttl=56 time=18.6 ms
64 bytes from 93.184.215.14: icmp_seq=3 ttl=56 time=18.1 ms

--- example.com ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss

On Linux and the Mac, ping carries on for ever unless you give -c with a count, or press Ctrl + C. Each line is one reply, with the time taken. The summary gives the share lost.

You seeIt usually means
steady repliesthe connection is fine
"Request timeout" or no repliesthe other end is off, unreachable, or ignores pings
"cannot resolve" or "Name or service not known"the name could not be found: a DNS problem
"Network is unreachable"your own computer has no connection

Test in three steps: your router, then a public address by number, then a site by name. Where the replies stop tells you where the fault is.

What is my address?

Linux or Mac terminal not run here
ip addr
hostname -I

On Linux, ip addr lists each network interface with its addresses. Look for the line beginning inet under your Wi-Fi or Ethernet interface. hostname -I prints just the addresses.

On a Mac, use ifconfig, or for one answer: ipconfig getifaddr en0.

These are the addresses on your local network. The address the internet sees is your router's.

curl: fetch from a web address

curl requests a web address and prints what comes back.

Linux or Mac terminal not run here
curl https://example.com

That prints the page's HTML. More useful forms:

CommandDoes
curl -I URLshow only the headers: status, type, size
curl -o file URLsave to a file with the name you give
curl -O URLsave using the name from the address
curl -L URLfollow redirects
curl -s URLsilent: no progress display
curl -C - -O URLresume an interrupted download
Linux or Mac terminal not run here
curl -I https://example.com
curl -L -o page.html https://example.com

The first line of the headers is the status. 200 means success, 301 and 302 mean the page has moved, 404 means not found, and numbers from 500 mean the server has a problem.

wget: download files

wget is made for downloading. It saves to a file by default and retries if the connection drops.

Linux or Mac terminal not run here
wget https://example.com/file.zip
wget -c https://example.com/file.zip

-c continues a partial download. wget comes with most Linux systems. The Mac has curl but not wget unless you install it.

Never pipe a download into a shell without reading it

Installation instructions often look like this:

Linux or Mac terminal not run here
curl -sSL https://example.com/install.sh | sh

Danger. That line downloads a program from the internet and runs it at once, with your permissions, without your seeing a word of it. With sudo in it, the program has full control of the computer. Do this only for software you have decided to trust, from its official site, over https. The careful way is to download first, read, and then run: curl -o install.sh URL, then less install.sh, then sh install.sh.

DNS: names into addresses

Linux or Mac terminal not run here
nslookup example.com
dig example.com +short

Both ask a DNS server for the address behind a name. If these fail while pinging a numeric address works, the trouble is with name lookup, not the connection.

traceroute: the route

Linux or Mac terminal not run here
traceroute example.com

It lists each router on the way to the destination. Lines of stars are routers that did not answer, which is common. What matters is where replies stop for good. On Linux it may need installing. tracepath is a close relative that is usually present.

Open ports and connections

Linux or Mac terminal not run here
ss -tuln

On Linux, ss -tuln lists the ports on which your computer is listening for connections. The older netstat -tuln does the same where it is installed. On a Mac, lsof -i -P | grep LISTEN.

ssh: a terminal on another computer

ssh user@host opens a command line on a remote computer that you have an account on. It asks for the password, or uses a key file. exit closes the connection. scp file user@host:folder/ copies a file to it.

Stay within your own network

Testing your own connection and your own computers is fine. Scanning or probing systems that belong to someone else, without their permission, may be against the law and against your internet provider's terms. If you are learning, practise on your own machines.

The Windows equivalents are ipconfig, ping and tracert.

Examples shown with output were run on 12 November 2026 in a practice folder: Windows commands in cmd.exe on Windows 11, Linux commands with the GNU tools of Git Bash. The folder path and user name were replaced with made-up ones. Commands marked "not run here" are shown as you would type them.

This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.