GNU/Linux >> Linux Esercitazione >  >> Linux

Installa e usa il comando Wget come un professionista (13 suggerimenti)

Cos'è Wget?

Wget è un pacchetto software gratuito per recuperare file utilizzando HTTP, HTTPS, FTP e FTPS, i protocolli Internet più utilizzati. È uno strumento a riga di comando non interattivo, quindi può essere facilmente chiamato da script, lavori cron, terminali senza supporto X-Windows, ecc.

Come si installa 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)

Come si usa Wget?

  1. Ora se vogliamo scaricare un singolo file usando HTTP digitiamo:
# Download a single file
wget http://site-name.com/file-name.tar.gz
Code language: Bash (bash)

2. Puoi scaricare una pagina web e salvarla in una cartella che desideri:

# 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. Ecco come scaricare file da siti Web protetti da password:

# 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. Un altro modo è scaricare un tipo specifico di file dal sito 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. Un'opzione interessante è scaricare più file con protocolli diversi:

# 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. È anche possibile limitare la larghezza di banda di un file che stai scaricando:

# Limit the bandwidth of a file you are downloading
wget --limit-rate=50k http://site-name.com/file.rar
Code language: Bash (bash)

7. Se lo desideri, puoi scaricare un intero sito Web con tutti i file e le cartelle all'interno:

# Mirror entire websites (all its pages and assets)
wget --mirror --no-parent --continue http://site-name.com
Code language: PHP (php)

8. Puoi inserire gli URL in un file e quindi dire a Wget di scaricare tutti i collegamenti nel file

# Download all of the links in the file 
wget ‐‐input filename.txt
Code language: PHP (php)

9. Ecco come riprendere un file attualmente scaricato da dove era stato lasciato

# Resume a currently download file from where it was left
wget -c http://site-name.com/file.zip
Code language: PHP (php)

10. Scarica in background usando 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. Controlla lo stato del download usando 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. Un bel trucco è testare l'URL di download usando Wget –spider

# Test download
wget --spider http://site-name.com/link/file.tar.bz2
Code language: PHP (php)

13. E infine ecco come scaricare solo determinati tipi di file usando wget -r -A

# Download only certain file types
wget -r -A.pdf http://site-name.com/files-folder/
Code language: PHP (php)

In questa lezione, abbiamo imparato alcuni dei modi più interessanti per gestire Wget. Uno strumento senza il quale nessun amministratore di sistema può lavorare. Per ulteriori esempi puoi fare riferimento alla pagina man del programma.

Ecco una rapida installazione video su Ubuntu e il download di un'intera pagina web

Ci auguriamo che questo articolo ti sia piaciuto. in tal caso, valuta questa pagina con le stelle qui sotto e iscriviti al nostro canale YouTube.


Linux
  1. Installa e usa Docker Compose su CentOS 8

  2. Come installare e utilizzare SSHFS su Linux

  3. Come installare e utilizzare il comando fping su Linux

  4. Come usare il comando wget come un professionista nel terminale Linux

  5. Come installare e utilizzare il comando Ping in Linux

5 suggerimenti per utilizzare il comando SS di Linux come un professionista

Come installare e utilizzare il comando Ack nel sistema Linux

Come installare e utilizzare MongoDB su Debian 11

Come installare e utilizzare il comando dello schermo Ubuntu 20.04

Come installare e utilizzare Podman (alternativa Docker)

Come installare e utilizzare Snapd su Debian 11