wget 명령어: 옵션과 -O, -P 저장 위치, -c 이어받기

wget 명령어는 HTTP, HTTPS, FTP 주소의 파일을 리눅스 터미널에서 다운로드하는 명령어입니다. AlmaLinux 9 서버에서 Apache Tomcat 압축 파일을 다운로드하다가 21%에서 끊은 뒤 -c 옵션으로 다시 실행해 받아 둔 앞부분은 건너뛰고 남은 9.8M만 이어 받았고, 받은 파일은 공식 SHA-512 체크섬과 같았습니다.
아래 출력의 저장 경로는 예시 값입니다. 파일은 예시 도메인 example.com과 Apache, GNU 공식 배포 서버(ftp.gnu.org), kernel.org 첫 화면에서만 다운로드했고, 응답 헤더에서 캐시 서버 이름이 든 줄은 뺐습니다.
1️⃣ wget 명령어 기본 사용법과 출력 읽기
명령의 기본 꼴은 wget, 옵션, 주소 순서입니다. 옵션 없이 주소만 주면 지금 있는 폴더에 주소 끝의 파일 이름으로 저장하고, 주소가 슬래시로 끝나면 index.html이라는 이름을 사용합니다.
cd /root/workwget https://example.com/--2026-10-29 01:07:46-- https://example.com/
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: 'index.html'
index.html [ <=> ] 577 --.-KB/s in 0s
2026-10-29 01:07:46 (19.1 MB/s) - 'index.html' saved [577]출력은 이름 찾기, 접속, 응답, 크기, 저장 위치, 진행 막대, 결과 순서로 나옵니다. 응답 줄이 200 OK면 서버가 파일을 보내고, Length 줄에는 파일 크기와 종류가, 마지막 saved 줄에는 저장한 바이트 수가 나옵니다. Resolving 줄에 IPv6 주소가 앞에 있으면 wget은 IPv6로 먼저 접속합니다.
다운로드가 끝나면 wget은 종료 코드로 결과를 남깁니다. -q로 메시지를 끄고 종료 코드만 출력하면, 성공했을 때 0이 나옵니다.
wget -q -O /root/work/dl/example.html https://example.com/echo $?0없는 주소를 요청하면 404 응답 뒤에 [ERROR 404: Not Found.] 줄이 나오고, 종료 코드는 8입니다.
wget -O /root/work/dl/nosuch.html https://example.com/nosuch.html--2026-10-29 01:05:03-- https://example.com/nosuch.html
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2026-10-29 01:05:03 ERROR 404: Not Found.echo $?8스크립트에서 다운로드가 성공했는지는 이 코드로 확인합니다. 코드는 아홉 가지이고, 이 글에서는 0, 4, 8이 나왔습니다.
| 종료 코드 | 뜻(매뉴얼 기준) | 이 글에서 나온 때 |
|---|---|---|
| 0 | 문제 없음 | -q로 받은 성공, --spider로 확인한 있는 주소 |
| 1 | 일반 오류 | — |
| 2 | 옵션을 해석하지 못함 | — |
| 3 | 파일 읽기·쓰기 오류 | — |
| 4 | 네트워크 오류 | 응답 없는 192.0.2.1에 -T 3 -t 2 |
| 5 | SSL 인증서 확인 실패 | — |
| 6 | 사용자 이름과 비밀번호 인증 실패 | — |
| 7 | 프로토콜 오류 | — |
| 8 | 서버가 오류 응답(404 등)을 보냄 | 없는 주소의 404, --spider의 broken link |
2️⃣ wget -O, -P 저장 위치와 -o 로그 파일
기본 동작대로 지금 있는 폴더에 저장하면, 스크립트나 크론에서 실행할 때 파일이 어디에 생길지 알기 어렵습니다. 그래서 저장 자리는 -P로 폴더를, -O로 파일 경로를 직접 적습니다.
wget -P /root/work/dl/ https://example.com/--2026-10-29 01:19:31-- https://example.com/
Resolving example.com (example.com)... 2606:4700:10::6814:179a, 2606:4700:10::ac42:93f3, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::6814:179a|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/dl/index.html'
index.html [ <=> ] 577 --.-KB/s in 0s
2026-10-29 01:19:31 (18.7 MB/s) - '/root/work/dl/index.html' saved [577]-P는 폴더만 정하고 파일 이름은 주소에서 가져옵니다. 같은 명령을 한 번 더 실행하면 있던 index.html은 그대로 두고 뒤에 .1을 붙인 새 파일로 저장합니다.
wget -P /root/work/dl/ https://example.com/--2026-10-29 01:19:31-- https://example.com/
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 104.20.23.154, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/dl/index.html.1'
index.html.1 [ <=> ] 577 --.-KB/s in 0s
2026-10-29 01:19:32 (23.2 MB/s) - '/root/work/dl/index.html.1' saved [577]wget -O /root/work/dl/example.html https://example.com/--2026-10-29 01:04:06-- https://example.com/
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/dl/example.html'
/root/work/dl/examp [ <=> ] 577 --.-KB/s in 0s
2026-10-29 01:04:07 (13.9 MB/s) - '/root/work/dl/example.html' saved [577]-O는 주소와 상관없이 적은 경로로 저장하고, 같은 파일이 있으면 그 파일을 덮어쓰게 됩니다. 진행 막대 줄 맨 앞에는 저장 경로가 잘려서 나옵니다.
-O 뒤에 하이픈을 주면 파일 대신 표준 출력으로 내보내므로 파이프로 다른 명령에 넘길 수 있습니다. 메시지가 섞이지 않게 -q를 같이 붙입니다.
wget -q -O - https://example.com/ | head -n 4<!doctype html><html lang=en><head><meta charset=utf-8><link rel=icon href=data:,><meta name=viewport content="width=device-width,initial-scale=1"><title>Example Domain</title><style>html{color-scheme:light dark;background:light-dark(#eee,#222)}body{font:16px/1.6 system-ui,sans-serif;max-width:26em;margin:auto;padding:25vh 2em 2em;text-align:center}</style></head><body><p>This domain is for use in documentation examples without needing permission. This is not a service; avoid relying on it for testing and monitoring purposes.</p><script src=/s.js></script></body></html>example.com의 HTML은 한 줄이라 head도 한 줄만 출력합니다.
이름이 비슷한 대문자 -O와 소문자 -o는 하는 일이 다릅니다. 소문자 -o는 메시지를 쓸 로그 파일을 정합니다. 그래서 화면에는 아무것도 나오지 않고, 접속부터 저장까지의 줄이 로그 파일에 남습니다.
wget -o /root/work/log/wget.log -P /root/work/dl/ https://example.com/echo $?0cat /root/work/log/wget.log--2026-10-29 01:08:11-- https://example.com/
Resolving example.com (example.com)... 2606:4700:10::6814:179a, 2606:4700:10::ac42:93f3, 104.20.23.154, ...
Connecting to example.com (example.com)|2606:4700:10::6814:179a|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/dl/index.html'
0K 25.6M=0s
2026-10-29 01:08:11 (25.6 MB/s) - '/root/work/dl/index.html' saved [577]로그 파일에는 진행 막대 대신 0K로 시작하는 점 진행 줄이 들어갑니다. 네 옵션이 내용과 메시지를 각각 어디로 보내는지는 아래 다이어그램에서 버튼으로 견줄 수 있습니다.
3️⃣ wget -c 이어받기와 속도 제한, 재시도
저장 자리를 정해도 큰 파일은 다운로드 도중에 끊기는 일이 생깁니다. Tomcat 9.0.123 압축 파일을 --limit-rate=1m으로 초당 1MB까지 제한해 받다가 21%에서 Ctrl+C로 끊었습니다.
wget --limit-rate=1m -P /root/work/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz--2026-10-29 01:07:47-- https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13233352 (13M) [application/x-gzip]
Saving to: '/root/work/apache-tomcat-9.0.123.tar.gz'
che-tomcat-9.0.123. 21%[===> ] 2.65M 1024KB/s
^Cls -l /root/work/total 2928
-rw-r--r-- 1 root root 2997039 Oct 29 01:07 apache-tomcat-9.0.123.tar.gz끊긴 파일은 2,997,039바이트로 남아 있습니다. 같은 명령에 -c를 붙여 다시 실행하면 이 크기 다음부터 요청합니다. -c 없이 같은 주소를 다시 받으면 이어 받지 않고 이름 뒤에 .1을 붙인 새 파일을 처음부터 다운로드합니다.
wget -c -P /root/work/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz--2026-10-29 01:07:50-- https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 13233352 (13M), 10236313 (9.8M) remaining [application/x-gzip]
Saving to: '/root/work/apache-tomcat-9.0.123.tar.gz'
apache-tomcat-9.0.1 100%[++++===============>] 12.62M --.-KB/s in 0.04s
2026-10-29 01:07:50 (262 MB/s) - '/root/work/apache-tomcat-9.0.123.tar.gz' saved [13233352/13233352]응답이 [206 Partial Content]로 바뀌고, Length 줄에 전체 13M 가운데 남은 9.8M이 나옵니다. 막대 안의 + 기호는 이미 받아 둔 앞부분입니다. -c는 매뉴얼 기준으로 Range 요청을 받는 HTTP 서버와 FTP 서버에서만 동작합니다.
ls -l /root/work/total 15168
-rw-r--r-- 1 root root 13233352 Oct 6 19:11 apache-tomcat-9.0.123.tar.gz다 받은 파일의 시각은 Oct 6 19:11입니다. wget은 서버가 보낸 Last-Modified 시각을 받은 파일에 그대로 붙입니다.
이어 받은 파일이 원본과 같은지는 Apache가 함께 배포하는 .sha512 파일로 확인했습니다.
wget -q -P /root/work/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512cd /root/worksha512sum -c apache-tomcat-9.0.123.tar.gz.sha512apache-tomcat-9.0.123.tar.gz: OK[OK]가 나오면 끊겼다 이어 받은 파일도 공식 배포 파일과 바이트까지 같습니다.
-N은 서버 파일이 로컬 파일보다 새로울 때만 다운로드합니다. 같은 .sha512를 -N으로 다시 요청한 결과는 [304 Not Modified] 응답이었고, 다운로드를 건너뛰었습니다.
wget -N -P /root/work/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512--2026-10-29 01:05:14-- https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response... 304 Not Modified
File '/root/work/apache-tomcat-9.0.123.tar.gz.sha512' not modified on server. Omitting download.응답이 없는 서버에는 -T로 기다릴 초를, -t로 시도 횟수를 정합니다. 기본값은 읽기 시간 초과 900초, 시도 20번이라 그대로 두면 오래 멈춰 있게 됩니다. 문서 예시용으로 예약된 주소 192.0.2.1에 -T 3 -t 2를 준 결과, 응답이 없어 두 번 시도한 뒤 종료 코드 4로 끝났습니다.
wget -T 3 -t 2 -O /root/work/dl/t.html http://192.0.2.1/--2026-10-29 01:05:25-- http://192.0.2.1/
Connecting to 192.0.2.1:80... failed: Connection timed out.
Retrying.
--2026-10-29 01:05:29-- (try: 2) http://192.0.2.1/
Connecting to 192.0.2.1:80... failed: Connection timed out.
Giving up.echo $?4-O로 받다가 404나 시간 초과로 실패해도 그 경로에는 빈 파일이 남습니다. 위 두 실패 뒤 ls로 확인한 두 파일은 모두 0바이트였습니다.
ls -l /root/work/dl/nosuch.html /root/work/dl/t.html-rw-r--r-- 1 root root 0 Oct 29 01:05 /root/work/dl/nosuch.html
-rw-r--r-- 1 root root 0 Oct 29 01:05 /root/work/dl/t.html같은 404를 -P로 요청하면 파일을 만들지 않습니다.
wget -q -P /root/work/dl/ https://example.com/nosuch2.htmlecho $?8ls -l /root/work/dl/nosuch2.htmlls: cannot access '/root/work/dl/nosuch2.html': No such file or directoryls로 확인하면 nosuch2.html이 없다는 [No such file or directory]가 나옵니다. -O는 실패해도 빈 파일을 남기므로, 스크립트에서 -O를 사용할 때는 종료 코드가 0인지 확인한 뒤 그 파일을 읽습니다.
4️⃣ wget 옵션 정리와 -i 여러 파일, -b 백그라운드 받기
받을 파일이 여럿이면 주소를 한 줄에 하나씩 적은 파일을 -i로 넘깁니다. -nv를 더하면 파일마다 결과 한 줄만 출력합니다.
cat /root/work/urls.txthttps://example.com/
https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512wget -nv -i /root/work/urls.txt -P /root/work/list/2026-10-29 01:05:14 URL:https://example.com/ [577] -> "/root/work/list/index.html" [1]
2026-10-29 01:05:14 URL:https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512 [158/158] -> "/root/work/list/apache-tomcat-9.0.123.tar.gz.sha512" [1]
FINISHED --2026-10-29 01:05:14--
Total wall clock time: 0.3s
Downloaded: 2 files, 735 in 0s (14.7 MB/s)마지막 세 줄은 -i로 받은 전체 요약으로, 받은 파일 수와 크기 합계가 나옵니다.
오래 걸리는 다운로드는 -b로 백그라운드에서 실행합니다. 매뉴얼 기준으로 -o 없이 -b만 주면 지금 폴더에 wget-log 파일이 생기므로, 로그 경로를 같이 적었습니다.
wget -b -o /root/work/log/bg.log -P /root/work/bg/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gzContinuing in background, pid 3623651.tail -n 4 /root/work/log/bg.log 12900K .......... .......... ... 100% 423M=0.07s
2026-10-29 01:05:22 (183 MB/s) - '/root/work/bg/apache-tomcat-9.0.123.tar.gz' saved [13233352/13233352]셸 프롬프트는 바로 돌아오고, 다운로드는 백그라운드 프로세스로 계속됩니다. 끝나면 로그 마지막 줄에 [saved]가 남습니다.
옵션은 아래 두 탭에 모았습니다.
| 옵션 | 복사 | 설명 |
|---|---|---|
| -O, --output-documentFILE | 저장할 파일 경로 정하기 | |
| -P, --directory-prefixPREFIX | 저장할 폴더만 정하기 | |
| -q, --quiet | 메시지를 끔 | |
| -o, --output-fileLOGFILE | 메시지를 로그 파일로 | |
| -c, --continue | 끊긴 파일 이어 받기 | |
| -N, --timestamping | 새로울 때만 받기 | |
| -nc, --no-clobber | 이미 받은 파일이 있으면 받지 않음 | |
| -T, --timeoutSECONDS | 기다릴 초를 정함 | |
| -t, --triesNUMBER | 시도 횟수를 정함 | |
| -i, --input-fileFILE | 여러 주소 한 번에 | |
| -nv, --no-verbose | 파일마다 결과 한 줄만 출력 | |
| -b, --background | 백그라운드로 받기 | |
| --spider | 받지 않고 주소만 확인 | |
| -S, --server-response | 응답 헤더 보기 | |
| -r, --recursive | 링크 따라 받기 | |
| -l, --levelDEPTH | 링크를 따라갈 깊이를 정함 | |
| --limit-rateAMOUNT | 속도 제한 |
| 옵션 | 복사 | 설명 |
|---|---|---|
| --userUSER | FTP와 HTTP 받기에 쓸 사용자 이름 | |
| --passwordPASSWORD | FTP와 HTTP 받기에 쓸 비밀번호 | |
| --ask-password | 접속할 때마다 비밀번호를 물음(--password와 함께 못 씀) | |
| --ftp-userUSER | FTP 서버의 사용자 이름 | |
| --ftp-passwordPASSWORD | FTP 서버의 비밀번호 | |
| -U, --user-agentAGENT | HTTP 서버에 AGENT 이름으로 알림 | |
| --headerHEADER-LINE | HTTP 요청마다 헤더 한 줄을 더 보냄 | |
| --no-check-certificate | 서버 인증서를 인증 기관과 대조하지 않음 | |
| -4, --inet4-only | IPv4 주소로만 접속 | |
| -w, --waitSECONDS | 받기와 받기 사이에 기다릴 초 | |
| -m, --mirror | 미러링에 맞는 옵션을 켬(재귀, 시각 비교, 깊이 무제한) | |
| -np, --no-parent | 재귀로 받을 때 상위 폴더로 올라가지 않음 | |
| -nd, --no-directories | 재귀로 받을 때 폴더 구조를 만들지 않음 | |
| -k, --convert-links | 받은 뒤 문서 안 링크를 로컬에서 볼 수 있게 바꿈 | |
| -A, --acceptACCLIST | 받을 파일 이름 끝이나 패턴 목록(쉼표로 구분) |
5️⃣ wget 링크 확인과 응답 헤더
다운로드 전에 주소가 살아 있는지만 확인할 때는 --spider를 사용합니다. 파일은 저장하지 않고 응답 코드만 확인합니다.
wget --spider https://example.com/Spider mode enabled. Check if remote file exists.
--2026-10-29 01:05:03-- https://example.com/
Resolving example.com (example.com)... 2606:4700:10::6814:179a, 2606:4700:10::ac42:93f3, 104.20.23.154, ...
Connecting to example.com (example.com)|2606:4700:10::6814:179a|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.echo $?0wget --spider https://example.com/nosuch.htmlSpider mode enabled. Check if remote file exists.
--2026-10-29 01:05:04-- https://example.com/nosuch.html
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
Remote file does not exist -- broken link!!!echo $?8있는 주소는 종료 코드 0으로, 없는 주소는 [broken link] 문구와 함께 8로 끝납니다. 스크립트에서 링크를 점검할 때 이 코드를 그대로 사용합니다.
-S를 더하면 서버가 보낸 응답 헤더가 함께 나옵니다.
wget -S --spider https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gzSpider mode enabled. Check if remote file exists.
--2026-10-29 01:03:54-- https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 13233352
Server: Apache
Last-Modified: Tue, 06 Oct 2026 19:11:51 GMT
ETag: "c9ecc8-65d30c56390be"
Access-Control-Allow-Origin: *
Content-Type: application/x-gzip
Via: 1.1 varnish, 1.1 varnish
Accept-Ranges: bytes
Age: 2047
Date: Thu, 29 Oct 2026 01:03:54 GMT
X-Cache: HIT, HIT
X-Cache-Hits: 400, 0
Length: 13233352 (13M) [application/x-gzip]
Remote file exists.Content-Length가 파일 크기이고, Last-Modified는 -N이 로컬 파일과 견주는 시각입니다. [Accept-Ranges: bytes]는 이 서버가 -c의 이어 받기 요청을 받는다는 뜻입니다.
링크를 따라 여러 파일을 받는 -r은 -l로 깊이를 정합니다. example.com에 -l 1을 준 결과, 페이지를 받은 뒤 robots.txt를 확인하고 페이지가 불러오는 s.js까지 두 파일을 다운로드했습니다.
wget -r -l 1 -P /root/work/mirror/ https://example.com/--2026-10-29 01:05:38-- https://example.com/
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/mirror/example.com/index.html'
0K 28.7M=0s
2026-10-29 01:05:38 (28.7 MB/s) - '/root/work/mirror/example.com/index.html' saved [577]
Loading robots.txt; please ignore errors.
--2026-10-29 01:05:38-- https://example.com/robots.txt
Reusing existing connection to [example.com]:443.
HTTP request sent, awaiting response... 404 Not Found
2026-10-29 01:05:38 ERROR 404: Not Found.
--2026-10-29 01:05:38-- https://example.com/s.js
Reusing existing connection to [example.com]:443.
HTTP request sent, awaiting response... 200 OK
Length: 1963 (1.9K) [text/javascript]
Saving to: '/root/work/mirror/example.com/s.js'
0K . 100% 17.6M=0s
2026-10-29 01:05:38 (17.6 MB/s) - '/root/work/mirror/example.com/s.js' saved [1963/1963]
FINISHED --2026-10-29 01:05:38--
Total wall clock time: 0.2s
Downloaded: 2 files, 2.5K in 0s (19.3 MB/s)find /root/work/mirror -type f/root/work/mirror/example.com/index.html
/root/work/mirror/example.com/s.js-P 폴더 아래에 도메인 이름 폴더가 생기고, 그 안에 사이트의 경로대로 파일이 저장됩니다.
🔲 wget 명령어 시뮬레이터
아래 시뮬레이터에서 wget을 -O, -P, -o, -c, -N, -i, --spider 옵션으로 직접 입력할 수 있습니다. 받을 수 있는 주소와 출력은 본문과 같은 예시 값이고, 21%에서 끊긴 Tomcat 파일을 -c로 이어 받은 뒤 sha512sum으로 대조하는 흐름까지 해 볼 수 있습니다.
6️⃣ wget 명령어 실무 예시
🔲 받은 tar.gz 바로 풀기와 이미 받은 파일 건너뛰기
설치 파일을 받아 바로 풀 때는 압축 파일을 저장하지 않고 tar로 넘깁니다. hello-2.12.1.tar.gz를 wget -qO-로 받아 tar -xzf -에 넘겨 보니 종료 코드 0으로 끝났고, src 폴더에 hello-2.12.1 폴더가 풀렸습니다.
mkdir srcwget -qO- https://ftp.gnu.org/gnu/hello/hello-2.12.1.tar.gz | tar -xzf - -C src; echo $?0ls src; ls src/hello-2.12.1 | head -5hello-2.12.1
ABOUT-NLS
AUTHORS
COPYING
ChangeLog
ChangeLog.O크론처럼 같은 명령을 되풀이할 때는 -nc를 붙입니다. -nc는 이미 받은 파일이 있으면 받지 않습니다. 두 번 실행해 보니 두 번째에 [already there; not retrieving.] 줄이 나왔고, dl 폴더의 파일은 하나 그대로였습니다.
wget -q -nc -P dl https://ftp.gnu.org/gnu/hello/hello-2.12.1.tar.gz.sig; echo $?0wget -nc -P dl https://ftp.gnu.org/gnu/hello/hello-2.12.1.tar.gz.sig; echo $?File 'dl/hello-2.12.1.tar.gz.sig' already there; not retrieving.
0ls dlhello-2.12.1.tar.gz.sig🔲 처음에 자주 하는 실수
물음표와 & 기호가 든 주소는 따옴표로 감쌉니다. 따옴표 없이 [?C=M&O=D]를 붙여 받으면, 셸이 & 기호를 백그라운드 실행으로 읽어 wget에는 ?C=M까지만 넘어갑니다. [C=M&O=D]는 수정 시각 기준 최신 순으로 정렬하라는 값이라, 따옴표 없이 받은 목록은 오래된 hello-1.3부터, 따옴표로 감싸 받은 목록은 최신 hello-2.12.3부터 나왔습니다.
wget -q -O list.html https://ftp.gnu.org/gnu/hello/?C=M&O=Dgrep -o "hello-[0-9.]*tar.gz\"" list.html | head -3hello-1.3.tar.gz"
hello-2.1.1.tar.gz"
hello-2.1.0.tar.gz"wget -q -O list.html "https://ftp.gnu.org/gnu/hello/?C=M&O=D"grep -o "hello-[0-9.]*tar.gz\"" list.html | head -3hello-2.12.3.tar.gz"
hello-2.12.2.tar.gz"
hello-2.12.1.tar.gz"-O와 -P를 함께 주면 -O에 적은 경로가 그대로 쓰입니다. -P dl을 붙여 실행해 보니 hello.sig는 dl 폴더 대신 지금 폴더에 저장되었습니다.
wget -q -P dl -O hello.sig https://ftp.gnu.org/gnu/hello/hello-2.12.1.tar.gz.sig; echo $?; ls hello.sig dl0
hello.sig
dl:
hello-2.12.1.tar.gz.sig
hello.html
kernel.html🔲 wget 결과 읽는 법
주소가 다른 주소로 넘어가면 응답 줄이 두 번 나옵니다. http://kernel.org/를 받으며 응답 줄만 골라 보니, 첫 응답은 [301 Moved Permanently]였고 Location 줄에 넘어갈 주소 https://kernel.org/가 [following]과 함께 나왔습니다. 두 번째 요청에서는 [200 OK]와 Length 줄이 나왔습니다.
wget -O dl/kernel.html http://kernel.org/ 2>&1 | grep -E "HTTP request|Location|Length"HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://kernel.org/ [following]
HTTP request sent, awaiting response... 200 OK
Length: 20436 (20K) [text/html]그래서 첫 응답이 301이어도 받기에 실패한 것이 아니며, 마지막 응답 줄과 Length 줄이 실제로 받은 파일의 결과입니다.
-O, -P, -c 옵션은 wget 명령어 시뮬레이터에서 직접 입력해 볼 수 있습니다.
🔢 FAQ & 추천 콘텐츠
ℹ️ 제휴 안내
본 사이트의 콘텐츠에는 제휴 링크가 포함되어 있습니다. 방문자가 이 링크를 통해 상품 또는 서비스를 구매하면 본 사이트는 판매처로부터 수수료를 지급받습니다. 이 과정에서 구매자가 지불하는 금액(이벤트 할인 시 금액이 내려갑니다↓)은 오르지 않습니다. 게시된 가격·할인·재고 정보는 작성 시점 기준이며 실제와 다를 수 있으므로, 구매 전 판매처에서 최종 확인하시기 바랍니다. 상품 선정과 평가는 자체 기준에 따라 작성되며, 수수료 지급 여부가 소개 순서나 평가 내용에 영향을 주지 않습니다.