シェルコマンドでダウンロードする方法


シェルコマンドを使用してファイルをダウンロードする方法について、主要なツールとサンプルコードを交えて説明します。

  1. wget

wgetは最も一般的なダウンロードツールの1つです。

# 基本的な使用法
wget https://example.com/file.zip

# 出力ファイル名を指定
wget -O output.zip https://example.com/file.zip

# バックグラウンドでダウンロード
wget -b https://example.com/largefile.iso

# 再開可能なダウンロード
wget -c https://example.com/largefile.iso
  1. curl

curlはURLを使用してデータを転送するためのツールです。

# 基本的な使用法
curl -O https://example.com/file.txt

# 出力ファイル名を指定
curl -o output.txt https://example.com/file.txt

# 進行状況を表示
curl -# -O https://example.com/file.zip

# リダイレクトに従う
curl -L -O https://example.com/redirected-file.zip
  1. aria2

aria2は高速で多機能なダウンロードユーティリティです。

# 基本的な使用法
aria2c https://example.com/file.iso

# 複数のURLから同時にダウンロード
aria2c https://mirror1.com/file.iso https://mirror2.com/file.iso

# トレントファイルからダウンロード
aria2c file.torrent

# 最大同時ダウンロード数を指定
aria2c -x 5 https://example.com/file.zip
  1. yt-dlp (YouTube-DLのフォーク)

yt-dlpは動画サイトからの動画ダウンロードに特化したツールです。

# Pythonのパッケージ・マネージャでインストール
pip install --upgrade yt-dlp

# YouTubeビデオをダウンロード
yt-dlp https://www.youtube.com/watch?v=dQw4w9WgXcQ

# 最高品質の音声のみをダウンロード
yt-dlp -f 'bestaudio' https://www.youtube.com/watch?v=dQw4w9WgXcQ

# プレイリスト全体をダウンロード
yt-dlp https://www.youtube.com/playlist?list=PLxxxxxxxxxxxxxxxx

これらのツールは、それぞれ異なる特徴と使用シナリオがあります。wgetとcurlは一般的なファイルダウンロードに適しており、aria2は複数のソースからの同時ダウンロードに優れています。yt-dlpは動画コンテンツに特化しています。

使用するツールは、ダウンロードするコンテンツの種類、必要な機能、システムの制約などに応じて選択してください。