본문으로 건너뛰기

wget 명령어 활용법은 무엇인가요?

💡 요약 정리

  • wget은 커맨드라인에서 파일을 다운로드하는 유틸리티입니다.
  • FTP, HTTP, HTTPS 프로토콜을 지원합니다.
  • 재귀적 다운로드, 중단된 다운로드 재개, 백그라운드 다운로드 등 다양한 기능을 제공합니다.
  • 리눅스뿐 아니라 윈도우에서도 사용 가능합니다.

설치환경

  • CentOS 5.x (64bit)

1. wget이란?

wget은 커맨드라인에서 파일을 쉽게 다운로드할 수 있도록 해주는 명령어입니다.


2. 주요 옵션 및 사용 예

옵션: -r (재귀적 다운로드)

지정된 디렉토리의 하위 디렉토리 내 내용까지 모두 다운로드합니다. 이때 원본 디렉토리의 구조를 그대로 유지한 채로 다운로드합니다.

tree 명령어로 다운로드한 디렉토리 구조를 확인할 수 있습니다.

[root@cafe24 ~]# wget -r ftp://ftp.sayclub.net/isc/pubs/tn/
.
.
.
.
2013-02-14 17:08:54 (54.4 KB/s) - `ftp.sayclub.net/isc/pubs/tn/images/.listing' saved [186]

Removed `ftp.sayclub.net/isc/pubs/tn/images/.listing'.
--2013-02-14 17:08:54--  ftp://ftp.sayclub.net/isc/pubs/tn/images/TN-2008-1/
           => `ftp.sayclub.net/isc/pubs/tn/images/TN-2008-1/.listing'
==> CWD /isc/pubs/tn/images/TN-2008-1 ... done.
==> PASV ... done.  ==> LIST ... done.

    [ <=>                                                              ] 758       --.-K/s   in 0s

2013-02-14 17:08:54 (90.4 MB/s) - `ftp.sayclub.net/isc/pubs/tn/images/TN-2008-1/.listing' saved [758]

[root@cafe24 test]# ll
total 4
drwxr-xr-x 3 root root 4096 Feb 14 17:08 ftp.sayclub.net

[root@cafe24 test]# tree
.
`-- ftp.sayclub.net
    `-- isc
        `-- pubs
            `-- tn
                |-- ISC-TN-2008-1.html
                |-- ISC-TN-2008-1.pdf
                |-- Testbed.png
                |-- images
                |   `-- TN-2008-1
                |       |-- OStest.jpg
                |       |-- Testbed.png
                |       `-- ZJ7X3161.jpg
                |-- in-a-box.xml
                |-- index.pl
                |-- isc-tn-2002-1.html
                |-- isc-tn-2002-1.tn
                |-- isc-tn-2002-1.txt
                |-- isc-tn-2002-2.html
                |-- isc-tn-2002-2.tn
                |-- isc-tn-2002-2.txt
                |-- isc-tn-2003-1.html
                |-- isc-tn-2003-1.tn
                |-- isc-tn-2003-1.txt
                |-- isc-tn-2004-1.html
                |-- isc-tn-2004-1.tn
                |-- isc-tn-2004-1.txt
                |-- isc-tn-2004-2.html
                |-- isc-tn-2004-2.tn
                |-- isc-tn-2006-1.html
                |-- isc-tn-2006-1.tn
                |-- isc-tn-2006-1.txt
                |-- isc-tn-2006-2.html
                |-- isc-tn-2006-2.tn
                |-- isc-tn-2006-2.txt
                |-- isc-tn-2007-1.html
                |-- isc-tn-2007-1.tn
                |-- isc-tn-2007-1.txt
                `-- isc-tn-2008-1.html

6 directories, 32 files

옵션: -nd (디렉토리 구조 무시)

디렉토리를 만들지 않습니다. 계층적으로 나열된 디렉토리 구조를 무시하고 한 디렉토리로 모든 내용을 다운로드합니다.

-r 옵션과 함께 사용 시 모든 하위 디렉토리의 파일을 한 디렉토리로 받게 됩니다.

[root@cafe24 test]# wget -r -nd ftp://ftp.sayclub.net/isc/pubs/tn

.
.
.
.
2013-02-14 17:13:39 (277 KB/s) - `isc-tn-2004-1.html' saved [40307]

--2013-02-14 17:13:39--  ftp://ftp.sayclub.net/isc/pubs/tn/isc-tn-2004-1.tn
           => `isc-tn-2004-1.tn'
==> CWD not required.
==> PASV ... done.  ==> RETR isc-tn-2004-1.tn ... done.
Length: 365

100%[====================================================================>] 365         --.-K/s   in 0.02s

[root@cafe24 test]# ll
total 1048
-rw-r--r-- 1 root root  14339 Sep  6  2007 in-a-box.xml
-rw-r--r-- 1 root root   1823 Jul 31  2008 index.pl
-rw-r--r-- 1 root root   5708 Jul 31  2008 isc-tn-2002-1.html
-rw-r--r-- 1 root root    474 Jul 31  2008 isc-tn-2002-1.tn
-rw-r--r-- 1 root root   5486 Jul 31  2008 isc-tn-2002-1.txt
-rw-r--r-- 1 root root   7570 Jul 31  2008 isc-tn-2002-2.html
-rw-r--r-- 1 root root    410 Jul 31  2008 isc-tn-2002-2.tn
-rw-r--r-- 1 root root   6542 Jul 31  2008 isc-tn-2002-2.txt
-rw-r--r-- 1 root root  24388 Jul 31  2008 isc-tn-2003-1.html
-rw-r--r-- 1 root root    507 Jul 31  2008 isc-tn-2003-1.tn
-rw-r--r-- 1 root root  18762 Jul 31  2008 isc-tn-2003-1.txt
-rw-r--r-- 1 root root  40307 Jul 31  2008 isc-tn-2004-1.html
-rw-r--r-- 1 root root    365 Jul 31  2008 isc-tn-2004-1.tn
-rw-r--r-- 1 root root  59537 Feb 29  2008 ISC-TN-2008-1.html
-rw-r--r-- 1 root root 740927 Feb 29  2008 ISC-TN-2008-1.pdf
-rw-r--r-- 1 root root  98679 Jul 31  2008 Testbed.png

[root@cafe24 test]# tree
.
|-- ISC-TN-2008-1.html
|-- ISC-TN-2008-1.pdf
|-- Testbed.png
|-- in-a-box.xml
|-- index.pl
|-- isc-tn-2002-1.html
|-- isc-tn-2002-1.tn
|-- isc-tn-2002-1.txt
|-- isc-tn-2002-2.html
|-- isc-tn-2002-2.tn
|-- isc-tn-2002-2.txt
|-- isc-tn-2003-1.html
|-- isc-tn-2003-1.tn
|-- isc-tn-2003-1.txt
|-- isc-tn-2004-1.html
`-- isc-tn-2004-1.tn

0 directories, 16 files

옵션: -A (특정 확장자만 다운로드)

지정된 확장자의 파일만 다운로드합니다. --accept=확장자 형식으로 입력합니다.

[root@cafe24 test]# wget -r -A html ftp://ftp.sayclub.net/isc/pubs/tn

.
.
.
.

[root@cafe24 test]# tree
.
`-- ftp.sayclub.net
    `-- isc
        `-- pubs
            `-- tn
                |-- ISC-TN-2008-1.html
                |-- isc-tn-2002-1.html
                |-- isc-tn-2002-2.html
                |-- isc-tn-2003-1.html
                |-- isc-tn-2004-1.html
                |-- isc-tn-2004-2.html
                |-- isc-tn-2006-1.html
                |-- isc-tn-2006-2.html
                |-- isc-tn-2007-1.html
                `-- isc-tn-2008-1.html

4 directories, 10 files

옵션: -R (특정 확장자 제외)

지정된 확장자의 파일은 제외하고 다운로드합니다. --reject=확장자 형식으로 입력합니다.

[root@cafe24 test]# wget -r -R tn,txt ftp://ftp.sayclub.net/isc/pubs/tn

.
.
.
.

[root@cafe24 test]# tree
.
`-- ftp.sayclub.net
    `-- isc
        `-- pubs
            `-- tn
                |-- ISC-TN-2008-1.html
                |-- ISC-TN-2008-1.pdf
                |-- Testbed.png
                |-- images
                |   `-- TN-2008-1
                |       |-- OStest.jpg
                |       |-- Testbed.png
                |       `-- ZJ7X3161.jpg
                |-- in-a-box.xml
                |-- index.pl
                |-- isc-tn-2002-1.html
                |-- isc-tn-2002-2.html
                |-- isc-tn-2003-1.html
                |-- isc-tn-2004-1.html
                |-- isc-tn-2004-2.html
                |-- isc-tn-2006-1.html
                |-- isc-tn-2006-2.html
                |-- isc-tn-2007-1.html
                `-- isc-tn-2008-1.html

6 directories, 19 files

옵션: -c (중단된 다운로드 재개)

다운로드가 중단된 파일의 나머지 부분을 이어받습니다.

[root@cafe24 test]# wget -c ftp://ftp.daum.net/mysql/Downloads/MySQL-5.5/mysql-5.5.39-linux2.6-x86_64.tar.gz

.
.
.
.

61% [==============================================>                             ] 111,341,568   156K/s  eta 8m 55s

# Ctrl+C로 중단

[root@cafe24 test]# ll
total 108732
-rw-r--r-- 1 root root 111341568 Jun 27 08:30 mysql-5.5.39-linux2.6-x86_64.tar.gz

[root@cafe24 test]# wget -c ftp://ftp.daum.net/mysql/Downloads/MySQL-5.5/mysql-5.5.39-linux2.6-x86_64.tar.gz
--2014-08-22 00:14:24--  ftp://ftp.daum.net/mysql/Downloads/MySQL-5.5/mysql-5.5.39-linux2.6-x86_64.tar.gz
           => `mysql-5.5.39-linux2.6-x86_64.tar.gz'
Resolving ftp.daum.net... 211.110.6.100
Connecting to ftp.daum.net|211.110.6.100|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /mysql/Downloads/MySQL-5.5 ... done.
==> SIZE mysql-5.5.39-linux2.6-x86_64.tar.gz ... 181604403
==> REST 111341568 ... done.
==> RETR mysql-5.5.39-linux2.6-x86_64.tar.gz ... done.
Length: 181604403 (173M), 70262835 (67M) remaining (unauthoritative)

 61% [++++++++++++++++++++++++++++++++++++++++++++++==========>                  ] 116,318,208   189K/s  eta 7m 39s

옵션: -b (백그라운드 다운로드)

백그라운드로 다운로드합니다. 다운로드 진행 상황은 wget-log 파일에 기록됩니다.

[root@cafe24 test]# wget -b ftp://ftp.daum.net/mysql/Downloads/MySQL-5.5/mysql-5.5.39-linux2.6-x86_64.tar.gz
Continuing in background, pid 8599.
Output will be written to `wget-log'.

[root@cafe24 test]# tail -f wget-log
--2014-08-22 00:30:31--  ftp://ftp.daum.net/mysql/Downloads/MySQL-5.5/mysql-5.5.39-linux2.6-x86_64.tar.gz
           => `mysql-5.5.39-linux2.6-x86_64.tar.gz.1'
Resolving ftp.daum.net... 211.110.6.100
Connecting to ftp.daum.net|211.110.6.100|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /mysql/Downloads/MySQL-5.5 ... done.
==> SIZE mysql-5.5.39-linux2.6-x86_64.tar.gz ... 181604403
==> PASV ... done.    ==> RETR mysql-5.5.39-linux2.6-x86_64.tar.gz ... done.
Length: 181604403 (173M) (unauthoritative)

 1% [                                                                             ] 2,015,232     152K/s  eta 17m 12s

옵션: -O (출력 파일명 지정)

다운로드한 파일을 지정한 이름으로 저장합니다.

[root@cafe24 test]# wget -O mysql.tar.gz ftp://ftp.daum.net/mysql/Downloads/MySQL-5.5/mysql-5.5.39-linux2.6-x86_64.tar.gz

[root@cafe24 test]# ll
total 177348
-rw-r--r-- 1 root root 181604403 Jun 27 08:30 mysql.tar.gz

3. 기타 유용한 옵션

옵션설명
-i지정한 파일 목록에 있는 모든 URL을 다운로드
-t재시도 횟수 지정 (0 = 무제한)
-T타임아웃 시간 설정 (초 단위)
-qQuiet 모드 (진행 상황 출력 안 함)
-vVerbose 모드 (상세 정보 출력)
--limit-rate다운로드 속도 제한 (예: --limit-rate=200k)
--userFTP/HTTP 인증 사용자 이름
--passwordFTP/HTTP 인증 비밀번호
--no-check-certificateSSL 인증서 검증 생략

4. 활용 예시

웹사이트 전체 미러링

wget -r -p -k -E -np http://example.com
  • -r: 재귀적 다운로드
  • -p: 페이지 표시에 필요한 모든 파일 다운로드
  • -k: 다운로드한 HTML 파일의 링크를 로컬 링크로 변환
  • -E: HTML 파일 확장자를 .html로 변경
  • -np: 상위 디렉토리로 이동하지 않음

파일 목록 일괄 다운로드

wget -i file_list.txt

file_list.txt 파일 내용 예시:

http://example.com/file1.zip
http://example.com/file2.zip
http://example.com/file3.zip

속도 제한을 두고 다운로드

wget --limit-rate=100k http://example.com/large_file.zip

참고사항

  • wget은 대부분의 리눅스 배포판에 기본적으로 설치되어 있습니다.
  • 설치되어 있지 않은 경우: yum install wget 또는 apt-get install wget 명령으로 설치할 수 있습니다.
  • 윈도우에서는 별도로 다운로드하여 설치해야 합니다.
  • FTP 서버에서 대용량 파일을 받을 때는 -c 옵션을 사용하여 중단 시 재개할 수 있도록 하는 것이 좋습니다.