Wgetとは何ですか?
Wgetは、最も広く使用されているインターネットプロトコルであるHTTP、HTTPS、FTP、およびFTPSを使用してファイルを取得するための無料のソフトウェアパッケージです。これは非対話型のコマンドラインツールであるため、スクリプト、cronジョブ、X-Windowsをサポートしていない端末などから簡単に呼び出すことができます。
Wgetをインストールするにはどうすればいいですか?
# Install wget in Ubuntu \ Debian Linux
apt-get install wget
# Install wget on RHEL / CentOS / Fedora
yum install wget
# Install wget on OpenSUSE
zypper install wget
# Install wget on ArchLinux
pacman -Sy wget
# Install wget on FreeBSD
pkg install wget
# Install wget Using FreeBSD Ports Collection
portsnap fetch update
cd /usr/ports/ftp/wget
make install clean
rehash ## or hash -r for 'bash/sh/ksh'
Code language: PHP (php)
Wgetの使い方は?
- HTTPを使用して単一のファイルをダウンロードする場合は、次のように入力します。
# Download a single file
wget http://site-name.com/file-name.tar.gz
Code language: Bash (bash)
2. Webページをダウンロードして、希望のフォルダーに保存できます。
# Download a website
wget -o index.html http://site-name.com/page-url
# Download a website into a different folder
wget --directory-prefix='./home/user/Downloads/site-name/' http://site-name.com/page-url
Code language: Bash (bash)
3.パスワードで保護されたWebサイトからファイルをダウンロードする方法は次のとおりです。
# Download files from password protected websites
wget ‐‐http-user=username ‐‐http-password=password http://site-name.com/path-secret/file.tar.gz
Code language: Bash (bash)
4.別の方法は、Webサイトから特定の種類のファイルをダウンロードすることです。
# Download specific type of files from the website
# This will download all the mp3 files
$ wget --level=2 --recursive --accept mp3 http://site-name.com
# will download all jpeg files
$ wget ‐‐level=1 ‐‐recursive ‐‐no-parent ‐‐accept jpg,JPG http://site-name.com/
Code language: Bash (bash)
5.クールなオプションは、異なるプロトコルで複数のファイルをダウンロードすることです。
# Download multiple files with different protocols
wget http://site-name.com/file.tar.gz ftp://151.232.45.6/picture.jpg
Code language: Bash (bash)
6.ダウンロードするファイルの帯域幅を制限することもできます:
# Limit the bandwidth of a file you are downloading
wget --limit-rate=50k http://site-name.com/file.rar
Code language: Bash (bash)
7.必要に応じて、すべてのファイルとフォルダを中に入れてWebサイト全体をダウンロードできます。
# Mirror entire websites (all its pages and assets)
wget --mirror --no-parent --continue http://site-name.com
Code language: PHP (php)
8. URLをファイルに入れてから、ファイル内のすべてのリンクをダウンロードするようにWgetに指示できます
# Download all of the links in the file
wget ‐‐input filename.txt
Code language: PHP (php)
9.現在ダウンロード中のファイルを残した場所から再開する方法は次のとおりです
# Resume a currently download file from where it was left
wget -c http://site-name.com/file.zip
Code language: PHP (php)
10. wget -b
を使用してバックグラウンドでダウンロードします# Download in the Background Using wget -b
wget -b http://www.site-name.com/link/filename.tar.bz2
Code language: PHP (php)
11. tail -f
を使用してダウンロードのステータスを確認します# Check the status of the download using tail -f
tail -f wget-log
Saving to: `filename.tar.bz2.4'
0K .......... .......... .......... .......... .......... 1% 65.5K 57s
50K .......... .......... .......... .......... .......... 2% 85.9K 49s
100K .......... .......... .......... .......... .......... 3% 83.3K 47s
150K .......... .......... .......... .......... .......... 5% 86.6K 45s
200K .......... .......... .......... .......... .......... 6% 33.9K 56s
250K .......... .......... .......... .......... .......... 7% 182M 46s
300K .......... .......... .......... .......... .......... 9% 57.9K 47s
Code language: PHP (php)
12.良いトリックは、Wget –spider
を使用してダウンロードURLをテストすることです。# Test download
wget --spider http://site-name.com/link/file.tar.bz2
Code language: PHP (php)
13.最後に、wget -r -A
を使用して特定のファイルタイプのみをダウンロードする方法を示します。# Download only certain file types
wget -r -A.pdf http://site-name.com/files-folder/
Code language: PHP (php)
このレッスンでは、Wgetを処理するための最もクールな方法のいくつかを学びました。システム管理者が作業できないツール。その他の例については、プログラムのマニュアルページを参照してください。