Mastering curl: Transfer URLs and Retrieve Data on Linux
This guide walks through curl’s syntax and options for fetching URLs, saving pages, handling cookies and headers, bypassing SSL verification, using proxies, performing POST requests, looping downloads, and FTP transfers, all illustrated with concrete command examples.
curl is a versatile command‑line tool that supports many protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET, TFTP) for sending data to a server or receiving data from a server.
Command format
curl [options] [URL...]Access a URL
curl http://www.bilibili.comSave the retrieved page
curl http://www.bilibili.com >> index.htmlUse built‑in -o to save a page
curl -o index.html http://www.bilibili.comUse built‑in -O to save a file with its original name
curl -O http://www.bilibili.com/main.cssTest HTTP response code
curl -o /dev/null -s -w %{http_code} www.bilibili.comGET mode example
curl http://www.bilibili.com/islogin.cgi?param1=abcdef¶m2=12345Skip SSL verification
curl -k 'https://www.bilibili.com/islogin.cgi?param1=abcdef¶m2=12345'POST mode
curl -d "param1=abcdef¶m2=12345" http://www.bilibili.com/login.cgiSpecify a proxy server and port
curl -x 172.16.71.233:1080 http://www.bilibili.comSave cookies from the response
curl -c cookie.txt http://www.bilibili.comSave response headers
curl -D cookied.txt http://www.bilibili.comNote: the cookie file created with -c differs from the one saved with -D.
Use saved cookies in a request
curl -b cookie.txt http://www.bilibili.comImitate a browser user‑agent
curl -A "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.0)" http://www.bilibili.comForge a Referer header (anti‑hotlinking)
curl -e "www.bilibili.com" http://live.bilibili.comThis makes the server think the request originated from www.bilibili.com.
Looped download
curl -O http://www.bilibili.com/dodo[1-5].JPGFTP file download
curl -O -u UserName:Password ftp://www.bilibili.com/banner.JPG curl -O ftp://UserName:[email protected]/banner.JPGFurther study
man curlSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ThinkingAgent
Sharing the latest AI-native technologies and real-world implementations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
