How to Use the wget Linux Command to Download Web Pages and Files

리눅스 wget으로 사이트 다운로드 (저장)

The wget utility allows you to download web pages, files and images from the web using the Linux command line.

You can use a single wget command on its own to download from a site or set up an input file to download multiple files across multiple sites.

 

According to the manual page wget can be used even when the user has logged out of the system. To do this you would use the nohup command.

 

The wget utility will retry a download even when the connection drops, resuming from where it left off if possible when the connection returns.

You can download entire web sites using wget and convert the links to point to local sources so that you can view a website offline.

 

The features of wget are as follows:

 
  • Download files using HTTP, HTTPS and FTP
  • Resume downloads
  • Convert absolute links in downloaded web pages to relative URLs so that websites can be viewed offline
  • Supports HTTP proxies and cookies
  • Supports persistent HTTP connections
  • Can run in the background even when you aren't logged on
  • Works on Linux and Windows
 

How To Download A Website Using wget

For this guide, you will learn how to download this linux blog.

wget www.everydaylinuxuser.com

 

It is worth creating your own folder on your machine using the mkdir command and then moving into the folder using the cd command.

 

For example:

 

mkdir everydaylinuxuser
cd everydaylinuxuser
wget www.everydaylinuxuser.com

 

The result is a single index.html file. On its own, this file is fairly useless as the content is still pulled from Google and the images and stylesheets are still all held on Google.

 

To download the full site and all the pages you can use the following command:

 

wget -r www.everydaylinuxuser.com

 

This downloads the pages recursively up to a maximum of 5 levels deep.

 

5 levels deep might not be enough to get everything from the site. You can use the -l switch to set the number of levels you wish to go to as follows:

wget -r -l10 www.everydaylinuxuser.com

 

If you want infinite recursion you can use the following:

 

wget -r -l inf www.everydaylinuxuser.com

 

You can also replace the inf with 0 which means the same thing.

 

There is still one more problem. You might get all the pages locally but all the links in the pages still point to their original place. It is therefore not possible to click locally between the links on the pages.

 

You can get around this problem by using the -k switch which converts all the links on the pages to point to their locally downloaded equivalent as follows:

 

wget -r -k www.everydaylinuxuser.com

 

If you want to get a complete mirror of a website you can simply use the following switch which takes away the necessity for using the -r -k and -l switches.

wget -m www.everydaylinuxuser.com

 

Therefore if you have your own website you can make a complete backup using this one simple command.

 

Run wget As A Background Command

You can get wget to run as a background command leaving you able to get on with your work in the terminal window whilst the files download.

 

Simply use the following command:

 

wget -b www.everydaylinuxuser.com

 

You can of course combine switches. To run the wget command in the background whilst mirroring the site you would use the following command:

 

wget -b -m www.everydaylinuxuser.com

 

You can simplify this further as follows:

wget -bm www.everydaylinuxuser.com

 

Logging

If you are running the wget command in the background you won't see any of the normal messages that it sends to the screen.

 

You can get all of those messages sent to a log file so that you can check on progress at any time using the tail command.

 

To output information from the wget command to a log file use the following command:

 

wget -o /path/to/mylogfile www.everydaylinuxuser.com

 

The reverse, of course, is to require no logging at all and no output to the screen. To omit all output use the following command:

 

wget -q www.everydaylinuxuser.com

Download From Multiple Sites

You can set up an input file to download from many different sites.

 

Open up a file using your favorite editor or even the cat command and simply start listing the sites or links to download from on each line of the file.

 

Save the file and then run the following wget command:

 

wget -i /path/to/inputfile

 

Apart from backing up your own website or maybe finding something to download to read on the train, it is unlikely that you will want to download an entire website.

 

You are more likely to download a single URL with images or perhaps download files such as zip files, ISO files or image files.

 

With that in mind you don't want to have to type the following into the input file as it is time consuming:

 
  • http://www.myfileserver.com/file1.zip
  • http://www.myfileserver.com/file2.zip
  • http://www.myfileserver.com/file3.zip
 

If you know the base URL is always going to be the same you can just specify the following in the input file:

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

 
  • file1.zip
  • file2.zip
  • file3.zip
 

You can then provide the base URL as part of the wget command as follows:

 

wget -B http://www.myfileserver.com -i /path/to/inputfile

 

Retry Options

If you have set up a queue of files to download within an input file and you leave your computer running all night to download the files you will be fairly annoyed when you come down in the morning to find that it got stuck on the first file and has been retrying all night.

 

You can specify the number of retries using the following switch:

 

wget -t 10 -i /path/to/inputfile

 

You might wish to use the above command in conjunction with the -T switch which allows you to specify a timeout in seconds as follows:

 

wget -t 10 -T 10 -i /path/to/inputfile

 

The above command will retry 10 times and will try to connect for 10 seconds for each link in the file.

 

It is also fairly annoying when you have partially downloaded 75% of a 4 gigabyte file on a slow broadband connection only for your connection to drop out.

 

You can use wget to retry from where it stopped downloading by using the following command:

 

wget -c www.myfileserver.com/file1.zip

 

If you are hammering a server the host might not like it too much and might either block or just kill your requests.

 

You can specify a wait period which specifies how long to wait between each retrieval as follows:

 

wget -w 60 -i /path/to/inputfile

 

The above command will wait 60 seconds between each download. This is useful if you are downloading lots of files from a single source.

 

Some web hosts might spot the frequency however and will block you anyway. You can make the wait period random to make it look like you aren't using a program as follows:

 

wget --random-wait -i /path/to/inputfile

 

Protecting Download Limits

Many internet service providers still apply download limits for your broadband usage, especially if you live outside of a city.

 

You may want to add a quota so that you don't blow that download limit. You can do that in the following way:

 

wget -q 100m -i /path/to/inputfile

 

Note that the -q command won't work with a single file. So if you download a file that is 2 gigabytes in size, using -q 1000m will not stop the file downloading.

 

The quota is only applied when recursively downloading from a site or when using an input file.

 

Getting Through Security

Some sites require you to log in to be able to access the content you wish to download.

 

You can use the following switches to specify the username and password.

 

wget --user=yourusername --password=yourpassword

 

Note on a multi user system if somebody runs the ps command they will be able to see your username and password.

 

Other Download Options

By default the -r switch will recursively download the content and will create directories as it goes.

 

You can get all the files to download to a single folder using the following switch:

 

wget -nd -r

 

The opposite of this is to force the creation of directories which can be achieved using the following command:

 

wget -x -r

 

How To Download Certain File Types

If you want to download recursively from a site but you only want to download a specific file type such as an mp3 or an image such as a png you can use the following syntax:

 

wget -A "*.mp3" -r

 

The reverse of this is to ignore certain files. Perhaps you don't want to download executables. In this case, you would use the following syntax:

 

wget -R "*.exe" -r

 

Cliget

There is a Firefox add-on called cliget. You can add this to Firefox in the following way.

 

Visit https://addons.mozilla.org/en-US/firefox/addon/cliget/ and click the "add to Firefox" button. 

 

Click the install button when it appears. You will required to restart Firefox.

 

To use cliget visit a page or file you wish to download and right click. A context menu will appear called cliget and there will be options to "copy to wget" and "copy to curl".

 

Click the "copy to wget" option and open a terminal window and then right click and paste. The appropriate wget command will be pasted into the window.

 

Basically, this saves you having to type the command yourself.

 

Summary

The wget command as a huge number of options and switches.

 

It is worth therefore reading the manual page for wget by typing the following into a terminal window:

 

man wget

 

[출처] https://www.lifewire.com/uses-of-command-wget-2201085

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
38 꼭 필요한 리눅스 명령어, file 졸리운_곰 2019.10.15 411
37 [Ubuntu 18.04] 원격 데스크톱 file 졸리운_곰 2019.02.23 331
36 Tasksel – Easily and Quickly Install Group Softwares in Debian and Ubuntu file 졸리운_곰 2018.10.14 296
» How to Use the wget Linux Command to Download Web Pages and Files : 리눅스 wget으로 사이트 다운로드(저장) 졸리운_곰 2018.09.12 472
34 우분투 16.04 원격 데스크탑 설정 ubuntu 16.04 xrdp file 졸리운_곰 2018.08.12 495
33 Connect To Ubuntu 16.04 / 17.10 / 18.04 Desktop Via Remote Desktop Connection (RDP) With Xrdp file 졸리운_곰 2018.06.22 254
32 ubuntu 18.04 원격데스크톱 xrdp 그놈접속 : Ubuntu 18.04: Connect to GNOME desktop environment via XRDP file 졸리운_곰 2018.05.13 1442
31 MSI 외장그래픽 노트북에 Ubuntu 설치 : How to Install Ubuntu 16.04 on MSI GE62 6QC 졸리운_곰 2018.05.06 499
30 Ubuntu 16.04에서 Docker 설치 졸리운_곰 2018.05.04 351
29 Docker: Docker image which runs XRDP on Ubuntu 16.04 desktop file 졸리운_곰 2018.05.03 387
28 [리눅스 GUI 하드디스크 상태 모니터링 툴] GSmartControl - A GUI Tool to Check HDD/SSD Health on Linux file 졸리운_곰 2018.01.16 346
27 ubuntu xfce4 rdp에서 MS Code나 Atom 에디터가 안뜰때 졸리운_곰 2017.10.14 251
26 Install Atom Text Editor in Ubuntu 16.04 (both 32&64bit) file 졸리운_곰 2017.10.14 305
25 우분투 서버 윈도우 원격접속(rdp) 설정 졸리운_곰 2017.10.14 431
24 우분투 서버 한글 설정 및 한글폰트 설치 졸리운_곰 2017.10.14 458
23 우분투(Ubuntu)에서 putty로 ssh 원격 접속 실패 해결 방법 file 졸리운_곰 2017.08.27 316
22 우분투 16.04 원격 데스크탑 설정 file 졸리운_곰 2017.07.08 559
21 Ubuntu에서 PATH 설정하기 졸리운_곰 2017.03.22 294
20 [Ubuntu] GUI를 통해 쉽고 빠르게 폴더 공유하기 file 졸리운_곰 2017.02.19 328
19 ubuntu 에서 compiz 화면루틴이 cpu rate 많이 (20%이상) 잡을 때 낮추는 법 졸리운_곰 2017.02.15 243
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED