이 글에서는 wget 유틸리티를 검토할 것입니다. 이 유틸리티는 널리 사용되는 프로토콜인 월드 와이드 웹 (WWW)에서 HTTP, HTTPS, FTP, 그리고 FTPS 등을 사용하여 파일을 검색합니다.
Wget은 무료 명령줄 유틸리티이자 네트워크 파일 다운로더로, 파일 다운로드를 쉽게 만드는 다양한 기능을 제공합니다. 이 기능에는 다음이 포함됩니다:
- 대형 파일을 다운로드하거나 전체 웹 또는 FTP 사이트를 미러링합니다.
- 한 번에 여러 파일을 다운로드합니다.
- 다운로드 대역폭과 속도 제한을 설정합니다.
- 프록시를 통해 파일을 다운로드합니다.
- 중단된 다운로드를 재개할 수 있습니다.
- 디렉터리를 재귀적으로 미러링합니다.
- 대부분의 UNIX 유사 운영 체제와 Windows에서 실행됩니다.
- 비감시/백그라운드 작업입니다.
- 지속적인 HTTP 연결 지원입니다.
- OpenSSL 또는 GnuTLS 라이브러리를 사용하여 암호화된 다운로드를 위한 SSL/TLS 지원입니다.
- IPv4 및 IPv6 다운로드를 지원합니다.
목차
Wget 명령 구문
Wget의 기본 구문은 다음과 같습니다:먼저 다음 명령을 사용하여 Linux 상자에 이미 wget 유틸리티가 설치되어 있는지 확인하십시오.
$ wget [option] [URL]
$ rpm -q wget [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ dpkg -l | grep wget [On Debian, Ubuntu and Mint]
Linux에 Wget 설치
만약 Wget이 설치되어 있지 않다면, 다음과 같이 Linux 시스템의 기본 패키지 관리자를 사용하여 설치할 수 있습니다.
$ sudo apt install wget -y [On Debian, Ubuntu and Mint] $ sudo yum install wget -y [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a net-misc/wget [On Gentoo Linux] $ sudo pacman -Sy wget [On Arch Linux] $ sudo zypper install wget [On OpenSUSE]
여기서 사용된 -y
옵션은 어떤 패키지를 설치하기 전에 확인 프롬프트를 방지하기 위한 것입니다. 더 많은 YUM 및 APT 명령 예제 및 옵션에 대해서는 다음 기사를 읽어보십시오:
1. Wget을 사용하여 파일 다운로드
이 명령은 단일 파일을 다운로드하여 현재 디렉토리에 저장합니다. 또한 다운로드하는 동안 다운로드 진행 상황, 크기, 날짜, 및 시간을 표시합니다.
# wget http://ftp.gnu.org/gnu/wget/wget2-2.0.0.tar.gz --2021-12-10 04:15:16-- http://ftp.gnu.org/gnu/wget/wget2-2.0.0.tar.gz Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 3565643 (3.4M) [application/x-gzip] Saving to: ‘wget2-2.0.0.tar.gz’ wget2-2.0.0.tar.gz 100%[==========>] 3.40M 2.31MB/s in 1.5s 2021-12-10 04:15:18 (2.31 MB/s) - ‘wget2-2.0.0.tar.gz’ saved [3565643/3565643]
2. 다른 이름으로 Wget 파일 다운로드
-O
(대문자) 옵션을 사용하여 다른 파일 이름으로 파일을 다운로드합니다. 여기서는 아래에 표시된대로 wget.zip 파일 이름을 지정했습니다.
# wget -O wget.zip http://ftp.gnu.org/gnu/wget/wget2-2.0.0.tar.gz --2021-12-10 04:20:19-- http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 446966 (436K) [application/x-gzip] Saving to: ‘wget.zip’ wget.zip 100%[===================>] 436.49K 510KB/s in 0.9s 2021-12-10 04:20:21 (510 KB/s) - ‘wget.zip’ saved [446966/446966]
3. HTTP 및 FTP 프로토콜을 사용하여 여러 파일을 다운로드하는 Wget
여기에서는 HTTP 및 FTP 프로토콜을 사용하여 wget 명령을 동시에 사용하여 여러 파일을 다운로드하는 방법을 살펴봅니다.
$ wget http://ftp.gnu.org/gnu/wget/wget2-2.0.0.tar.gz ftp://ftp.gnu.org/gnu/wget/wget2-2.0.0.tar.gz.sig --2021-12-10 06:45:17-- http://ftp.gnu.org/gnu/wget/wget2-2.0.0.tar.gz Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 3565643 (3.4M) [application/x-gzip] Saving to: ‘wget2-2.0.0.tar.gz’ wget2-2.0.0.tar.gz 100%[==========>] 4.40M 4.31MB/s in 1.1s 2021-12-10 06:46:10 (2.31 MB/s) - ‘wget2-2.0.0.tar.gz’ saved [3565643/3565643]
4. 파일에서 여러 파일 다운로드하기
한 번에 여러 파일을 다운로드하려면 다운로드할 URL 목록이 포함된 파일의 위치와 함께 -i
옵션을 사용하십시오. 각 URL은 다음과 같이 별도의 줄에 추가해야 합니다.
예를 들어, 다음 파일 ‘download-linux.txt‘은 다운로드할 URL 목록을 포함하고 있습니다.
# cat download-linux.txt https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso https://download.rockylinux.org/pub/rocky/8/isos/x86_64/Rocky-8.5-x86_64-dvd1.iso https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/debian-11.2.0-amd64-DVD-1.iso
# wget -i download-linux.txt --2021-12-10 04:52:40-- https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso Resolving releases.ubuntu.com (releases.ubuntu.com)... 91.189.88.248, 91.189.88.247, 91.189.91.124, ... Connecting to releases.ubuntu.com (releases.ubuntu.com)|91.189.88.248|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 3071934464 (2.9G) [application/x-iso9660-image] Saving to: ‘ubuntu-20.04.3-desktop-amd64.iso’ ubuntu-20.04.3-desktop-amd64 4%[=> ] 137.71M 11.2MB/s eta 3m 30s ...
URL 목록에 특정 번호 패턴이 있는 경우 중괄호를 추가하여 해당 패턴과 일치하는 모든 URL을 가져올 수 있습니다. 예를 들어, Linux 커널 5.1.1에서 5.1.15까지의 시리즈를 다운로드하려면 다음과 같이 할 수 있습니다.
$ wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.1.{1..15}.tar.gz --2021-12-10 05:46:59-- https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.1.1.tar.gz Resolving mirrors.edge.kernel.org (mirrors.edge.kernel.org)... 147.75.95.133, 2604:1380:3000:1500::1 Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)|147.75.95.133|:443... connected. WARNING: The certificate of ‘mirrors.edge.kernel.org’ is not trusted. WARNING: The certificate of ‘mirrors.edge.kernel.org’ is not yet activated. The certificate has not yet been activated HTTP request sent, awaiting response... 200 OK Length: 164113671 (157M) [application/x-gzip] Saving to: ‘linux-5.1.1.tar.gz’ linux-5.1.1.tar.gz 100%[===========>] 156.51M 2.59MB/s in 61s 2021-12-10 05:48:01 (2.57 MB/s) - ‘linux-5.1.1.tar.gz’ saved [164113671/164113671] --2021-12-10 05:48:01-- https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.1.2.tar.gz Reusing existing connection to mirrors.edge.kernel.org:443. HTTP request sent, awaiting response... 200 OK Length: 164110470 (157M) [application/x-gzip] Saving to: ‘linux-5.1.2.tar.gz’ linux-5.1.2.tar.gz 19%[===========] 30.57M 2.58MB/s eta 50s
5. 다운로드 중단된 다운로드 재개하기
큰 파일을 다운로드하는 경우, 때로는 다운로드를 중지할 수 있습니다. 이 경우에는 -c
옵션을 사용하여 이전에 중단된 곳부터 동일한 파일을 다시 다운로드할 수 있습니다.
그러나 -c
옵션을 지정하지 않고 파일을 다운로드하면 wget이 파일 끝에 .1
확장자를 추가하여 새로운 다운로드로 간주합니다. 따라서 큰 파일을 다운로드할 때는 -c 스위치를 추가하는 것이 좋습니다.
# wget -c https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso --2021-12-10 05:27:59-- https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso Resolving releases.ubuntu.com (releases.ubuntu.com)... 91.189.88.247, 91.189.91.123, 91.189.91.124, ... Connecting to releases.ubuntu.com (releases.ubuntu.com)|91.189.88.247|:443... connected. HTTP request sent, awaiting response... 206 Partial Content Length: 3071934464 (2.9G), 2922987520 (2.7G) remaining [application/x-iso9660-image] Saving to: ‘ubuntu-20.04.3-desktop-amd64.iso’ ubuntu-20.04.3-desktop-amd64.iso 5%[++++++> ] 167.93M 11.1MB/s ^C [root@tecmint ~]# wget -c https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso --2021-12-10 05:28:03-- https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso Resolving releases.ubuntu.com (releases.ubuntu.com)... 91.189.88.248, 91.189.91.124, 91.189.91.123, ... Connecting to releases.ubuntu.com (releases.ubuntu.com)|91.189.88.248|:443... connected. HTTP request sent, awaiting response... 206 Partial Content Length: 3071934464 (2.9G), 2894266368 (2.7G) remaining [application/x-iso9660-image] Saving to: ‘ubuntu-20.04.3-desktop-amd64.iso’ ubuntu-20.04.3-desktop-amd64.iso 10%[+++++++=====> ] 296.32M 17.2MB/s eta 2m 49s ^
6. 전체 웹사이트 미러링하기
OFFLINE 보기 为目的으로 전체 웹사이트를 다운로드하거나 ミラー링하거나 이미지를 복사할 수 있는 다음 명령어를 사용할 수 있습니다.
$ wget --recursive --page-requisites --adjust-extension --span-hosts --convert-links --restrict-file-names=windows --domains yoursite.com --no-parent yoursite.com
위의 명령어의 설명
wget \ --recursive \ # Download the whole site. --page-requisites \ # Get all assets/elements (CSS/JS/images). --adjust-extension \ # Save files with .html on the end. --span-hosts \ # Include necessary assets from offsite as well. --convert-links \ # Update links to still work in the static version. --restrict-file-names=windows \ # Modify filenames to work in Windows as well. --domains yoursite.com \ # Do not follow links outside this domain. --no-parent \ # Don't follow links outside the directory you pass in. yoursite.com/whatever/path # The URL to download
7. Wget 배경으로 파일 다운로드
-b
옵션을 사용하면 다운로드가 시작되고 로그가 wget.log 파일에 기록되면 즉시 배경에 다운로드를 보냅니다.
$ wget -b wget.log https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso Continuing in background, pid 8999. Output will be written to ‘wget.log’.
8. Wget 파일 다운로드 속도 제한 설정
--limit-rate=100k
옵션을 사용하면 다운로드 속도를 100k로 제한하고 다음과 같이 wget.log 파일에 로그를 생성합니다.
$ wget -c --limit-rate=100k -b wget.log https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso Continuing in background, pid 9108. Output will be written to ‘wget-log’.
wget.log 파일을 보고 wget의 다운로드 속도를 확인합니다.
$ tail -f wget-log 5600K .......... .......... .......... .......... .......... 0% 104K 8h19m 5650K .......... .......... .......... .......... .......... 0% 103K 8h19m 5700K .......... .......... .......... .......... .......... 0% 105K 8h19m 5750K .......... .......... .......... .......... .......... 0% 104K 8h18m 5800K .......... .......... .......... .......... .......... 0% 104K 8h18m 5850K .......... .......... .......... .......... .......... 0% 105K 8h18m 5900K .......... .......... .......... .......... .......... 0% 103K 8h18m 5950K .......... .......... .......... .......... .......... 0% 105K 8h18m 6000K .......... .......... .......... .......... .......... 0% 69.0K 8h20m 6050K .......... .......... .......... .......... .......... 0% 106K 8h19m 6100K .......... .......... .......... .......... .......... 0% 98.5K 8h20m 6150K .......... .......... .......... .......... .......... 0% 110K 8h19m 6200K .......... .......... .......... .......... .......... 0% 104K 8h19m 6250K .......... .......... .......... .......... .......... 0% 104K 8h19m ...
9. Wget FTP와 HTTP로 암호 보호된 파일 다운로드
암호 보호된 FTP 서버의 파일을 다운로드하려면 --ftp-user=username
및 --ftp-password=password
옵션을 사용할 수 있습니다.
$ wget --ftp-user=narad --ftp-password=password ftp://ftp.example.com/filename.tar.gz
암호 보호된 HTTP 서버의 파일을 다운로드하려면 --http-user=username
및 --http-password=password
옵션을 사용할 수 있습니다.
$ wget --http-user=narad --http-password=password http://http.example.com/filename.tar.gz
10. SSL 인증서 확인 무시하기
HTTPS를 통해 파일을 다운로드할 때 SSL 인증서 확인을 무시하려면 --no-check-certificate
옵션을 사용할 수 있습니다:
$ wget --no-check-certificate https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.1.1.tar.gz --2021-12-10 06:21:21-- https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.1.1.tar.gz Resolving mirrors.edge.kernel.org (mirrors.edge.kernel.org)... 147.75.95.133, 2604:1380:3000:1500::1 Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)|147.75.95.133|:443... connected. WARNING: The certificate of ‘mirrors.edge.kernel.org’ is not trusted. WARNING: The certificate of ‘mirrors.edge.kernel.org’ is not yet activated. The certificate has not yet been activated HTTP request sent, awaiting response... 200 OK Length: 164113671 (157M) [application/x-gzip] Saving to: ‘linux-5.1.1.tar.gz’ ...
11. Wget 버전 및 도움말
--version
과 --help
옵션을 사용하여 필요한 버전과 도움말을 볼 수 있습니다.
$ wget --version $ wget --help
이 문서에서는 매일의 관리 작업을 위한 Linux wget 명령어와 옵션을 다루었습니다. 더 많은 정보를 원하시면 man wget을 참조하거나, 놓친 부분이 있다면 댓글 상자를 통해 공유해 주시기 바랍니다.
Source:
https://www.tecmint.com/10-wget-command-examples-in-linux/