Skip to content Gå til innhold


How to download files from the Linux command line Hvordan laste ned filer fra Linux kommandolinjen

LinuxWindows

Wget is a very cool command-line downloader for Linux and UNIX environments. Wget er en veldig kul kommandolinjeverktøy dataoverførte for Linux-og UNIX-miljøer. Don't be fooled by the fact that it is a command line tool. Ikke la deg lure av det faktum at det er et kommandolinje-verktøy. It is very powerful and versatile and can match some of the best graphical downloaders around today. Det er veldig kraftig og allsidig og kan matche noen av de beste grafiske nedlastere rundt i dag. It has features such as resuming of downloads, bandwidth control, it can handle authentication, and much more. Den har funksjoner som gjenoppta nedlastinger, båndbreddekontroll, den kan håndtere autentisering, og mye mer. I'll get you started with the basics of using wget and then I'll show you how you can automate a complete backup of your website using wget and cron . Jeg skal få deg i gang med det grunnleggende om bruk wget og så skal jeg vise deg hvordan du kan automatisere en fullstendig backup av din webside ved hjelp av wget og cron.

Let's get started by installing wget. La oss komme i gang med å installere wget. Most Linux distributions come with wget pre-installed. De fleste Linux-distribusjoner kommer med wget forhåndsinstallert. If you manage to land yourself a Linux machine without a copy of wget try the following. Hvis du klarer å lande selv en Linux-maskin uten en kopi av wget prøve følgende. On a Red Hat Linux based system such a Fedora you can use: På en Red Hat Linux-basert system slik Fedora du kan bruke:

# yum install wget # Yum installere wget

or if you use a Debian based system like Ubuntu: eller hvis du bruker en Debian-basert system som Ubuntu:

# sudo apt-get install wget Sudo apt-get install wget

One of the above should do the trick for you. En av de ovenfor bør gjøre triks for deg. Otherwise, check with your Linux distribution's manual to see how to get and install packages. Ellers, sjekk med din Linux-distribusjon i håndboken for å se hvordan du kan komme og installere pakker. wget has also been ported to Windows. wget har også blitt portet til Windows. Users on Windows can access Brukere på Windows kan få tilgang this website dette nettstedet . . Download the following packages: ssllibs and wget . Last ned følgende pakker: ssllibs og wget. Extract and copy the files to a directory such as C:\Program Files\wget and add that directory to you system's path so you can access it with ease. Pakk ut og kopiere filene til en katalog for eksempel C: \ Programfiler \ wget og legger til at katalogen til deg systemets banen slik at du får tilgang til den med letthet. Now you should be able to access wget from your Windows command line. Nå bør du kunne få tilgang wget fra Windows-kommandolinjen.

The most basic operation a download manager needs to perform is to download a file from a URL. Den mest grunnleggende drift en dataoverføre bestyrer må utføre, er å laste ned en fil fra en URL. Here's how you would use wget to download a file: Her ser du hvordan du ville bruke wget å laste ned en fil:

# wget http://www.sevenacross.com/photos.zip # Wget http://www.sevenacross.com/photos.zip

Yes, it's that simple. Ja, det er så enkelt. Now let's do something more fun. Nå skal vi gjøre noe mer morsomt. Let's download an entire website. La oss ned et helt nettsted. Here's a taste of the power of wget. Her er en smak av makt wget. If you want to download a website you can specify the depth that wget must fetch files from. Dersom du ønsker å laste ned en nettside kan du spesifisere dybde som wget må hente filer fra. Say you want to download the first level links of Yahoo!'s home page. Si du vil laste ned første nivå koblinger av Yahoo! 'S hjemmeside. Here's how would do that: Her ser du hvordan ville gjøre det:

# wget -r -l 1 http://www.yahoo.com/ # Wget-r-l 1 http://www.yahoo.com/

Here's what each options does. Her er hva hver alternativer gjør. The -r activates the recursive retrieval of files. The-r aktiverer rekursive henting av filer. The -l stands for level, and the number 1 next to it tells wget how many levels deep to go while fetching the files. The-l står for nivå, og tallet 1 ved den forteller wget hvor mange nivåer dypt å gå ved henting av filer. Try increasing the number of levels to two and see how much longer wget takes. Prøv å øke antall nivåer til to og se hvor mye lengre wget tar.

Now if you want to download all the “jpeg” images from a website, a user familiar with the Linux command line might guess that a command like “wget http://www.sevenacross.com*.jpeg” would work. Nå, hvis du vil laste ned alle de "jpeg" bilder fra en nettside, en bruker kjent med Linux kommandolinjen kan gjette at en kommando som "wget http://www.sevenacross.com *. jpeg" ville fungere. Well, unfortunately, it won't. Vel, dessverre, vil den ikke. What you need to do is something like this: Hva du trenger å gjøre er noe sånt som dette:

# wget -r -l1 –no-parent -A.jpeg http://www.sevenacross.com # Wget-r-L1-no-foreldre-A.jpeg http://www.sevenacross.com

Another very useful option in wget is the resumption of a download. En annen veldig nyttig alternativ i wget er gjenopptagelse av en nedlasting. Say you started downloading a large file and you lost your Internet connection before the download could complete. Si du startet å laste ned en stor fil og du mister Internett-tilkoblingen før nedlastingen kunne fullføre. You can use the -c option to continue your download from where you left it. Du kan bruke-c muligheten til å fortsette nedlastingen fra der du forlot det.

# wget -c http://www.sevenacross.com/ubuntu-live.iso # Wget-c http://www.sevenacross.com/ubuntu-live.iso

Now let's move on to setting up a daily backup of a website. La oss nå gå videre til å sette opp en daglig backup av en nettside. The following command will create a mirror of a site in your local disk. Følgende kommando vil opprette et speil av et område i den lokale disken. For this purpose wget has a specific option, –mirror . For dette formålet wget har en bestemt alternativ,-speilet. Try the following command, replacing http://sevenacross.com with your website's address. Prøv følgende kommando, og erstattet http://sevenacross.com med webområdets adresse.

# wget –mirror http://www.sevenacross.com/ # Wget-speilet http://www.sevenacross.com/

When the command is done running you should have a local mirror of your website. Når kommandoen er ferdig kjører du bør ha et lokalt speil av ditt nettsted. This make for a pretty handy tool for backups. Dette sørger for en ganske hendig verktøy for sikkerhetskopiering. Let's turn this command into a cool shell script and schedule it to run at midnight every night. La oss gjøre denne kommandoen til en kjølig shell script og planlegge det som skal kjøres ved midnatt hver natt. Open your favorite text editor and type the following. Åpne din favoritt teksteditor og skriv inn følgende. Remember to adapt the path of the backup and the website URL to your requirements. Husk å tilpasse banen til backup og webadresse til dine behov.

#!/bin/bash #! / bin / bash

YEAR=`date +”%Y”` ÅR = `date +"% Y "`
MONTH=`date +”%m”` MÅNED = `date +"% m "`
DAY=`date +”%d”` DAG = `date +"% d "`

BACKUP_PATH=`/home/backup/` # replace path with your backup directory BACKUP_PATH = `/ home / backup /` # erstatte banen med backup-katalog
WEBSITE_URL=`http://www.sevenacross.net` # replace url with the address of the website you want to backup WEBSITE_URL = `http://www.sevenacross.net` # erstatte url med adressen til nettstedet du ønsker å sikkerhetskopiere

# Create and move to backup directory # Lag og flytte til backup-katalog
cd $BACKUP_PARENT_DIR/$YEAR/$MONTH cd $ BACKUP_PARENT_DIR / $ ÅR / $ MÅNED
mkdir $DAY mkdir $ DAG
cd $DAY cd $ DAG

wget –mirror ${WEBSITE_URL} wget-speilet $ (WEBSITE_URL)

Now save this file as something like website_backup.sh and grant it executable permissions: Nå lagre denne filen som noe som website_backup.sh og gi det startbar tillatelser:

# chmod +x website_backup.sh # Chmod + x website_backup.sh

Open your cron configuration with the crontab command and add the following line at the end: Åpne cron konfigurasjonen med crontab-kommandoen, og legg til følgende linje til slutt:

0 0 * * * /path/to/website_backup.sh 0 0 * * * / sti / til / website_backup.sh

You should have a copy of your website in /home/backup/YEAR/MONTH/DAY every day. Du bør ha en kopi av webområdet ditt i / home / backup / år / måned / dag hver dag. For more help using cron and crontab, see For mer hjelp med cron og crontab, se this tutorial denne opplæringen . .

There's a lot more to learn about wget than I've mentioned here. Det er mye mer å lære om wget enn jeg har nevnt her. Read up wget's man page. Les up wget mann siden.

Posted in Posted in Guest Blogger Guest Blogger , , Linux Linux , , Windows Windows . .

Related Posts: Relaterte innlegg:

How to post to Twitter from the Linux command line Hvordan legge til Twitter fra Linux kommandolinjen
How to enable the root user account in Ubuntu Linux Slik aktiverer root brukerkonto i Ubuntu Linux
Some useful Linux bash tricks Noen nyttige Linux bash triks
How to recursively copy files from an FTP server with Linux Slik rekursivt kopiere filer fra en FTP-server med Linux
Linux command line magic – find and replace Linux kommandolinje magi - finn og erstatt

8 Responses 8 Svar

Stay in touch with the conversation, subscribe to the Hold kontakten med samtalen, abonnere på RSS feed for comments on this post RSS feed for kommentarer til dette innlegget . .

  1. azeddine azeddine says sier

    per aprire per aprire

  2. marco says marco sier

    Another good downloadmanager for the console is Axel: En annen god downloadmanager for konsollen er Axel:
    http://axel.alioth.debian.org/ http://axel.alioth.debian.org/

    Features: Funksjoner:
    -multiple connections, -flere forbindelser,
    -multiple mirrors, -flere speil,
    -resuming (if the server supports it), -gjenoppta (hvis serveren støtter det),
    -no dependencies and -ingen avhengigheter og
    -lightweight -lett

    If you have big downloads (CD/DVD-Images), i suggest to use axel instead of wget, it's a WAY faster then wget. Hvis du har store nedlastinger (CD / DVD-bilder), foreslår jeg å bruke axel stedet for wget, er det en WAY hurtigere så wget.

  3. zzz says zzz sier

    # Ням установить Wget – это круто. # Ням установить Wget - это круто.

  4. Info Gaptek Info gaptek says sier

    This page is very useful. Denne siden er veldig nyttig.
    Thanks for your help! Takk for hjelpen!

  5. Fernando says Fernando sier

    O comando para certo no fedora é # yum instal [nome do programa] O commando para certo ingen fedora é # yum instal [nome do programa]
    ou ainda # rpm -Uvh nomedopacote.rpm ou ainda # rpm-Uvh nomedopacote.rpm

  6. Abhishek says Abhishek sier

    my first ever comment…realy very gud and simple for novice user…hats off man!!!!! min første kommentar ... veldig gud og enkel for uerfarne brukere ... Hats Off mann !!!!!

  7. ankur says Ankur sier

    very clearly written!! helt klart skrevet!

Continuing the Discussion Fortsetter Discussion

  1. Daily Lifestream Digest for 2009-01-05 Daglig Lifestream Digest for 2009-01-05 linked to this post on January 6, 2009 knyttet til dette innlegget den 6 januar 2009

    [...] Jackie bookmarked a link on Delicious. [...] Jackie Bokmerkede en kobling på Delicious. How to download files from the Linux command line – Simple Help [...] Hvordan laste ned filer fra Linux kommandolinjen - Enkelt Hjelp [...]



Some HTML is OK Some HTML is OK

or, reply to this post via eller svare på dette innlegget via trackback styrekule . .