wget下載與tar壓縮/解壓


wget命令

Usage: wget [OPTION]... [URL]...

# 后台運行
-b,  --background                go to background after startup

# log信息打印
-o,  --output-file=FILE          log messages to FILE
-a,  --append-output=FILE        append messages to FILE
-d,  --debug                     print lots of debugging information
-q,  --quiet                     quiet (no output)

# url來源文件
-i,  --input-file=FILE           download URLs found in local or external FILE
-F,  --force-html                treat input file as HTML
-B,  --base=URL                  resolves HTML input-file links (-i -F)

# 下載回復
-O,  --output-document=FILE      write documents to FILE
-c,  --continue                  resume getting a partially-downloaded file         # 斷電續傳
     --start-pos=OFFSET          start downloading from zero-based position OFFSET
     --progress=TYPE             select progress gauge type
     --show-progress             display the progress bar in any verbosity mode

-N,  --timestamping              don't re-retrieve files unless newer than local    # 不下載早於的時間戳
      --no-if-modified-since      don't use conditional if-modified-since get requests in timestamping mode # 自從上次下載未進行修改
      --no-use-server-timestamps  don't set the local file's timestamp by the one on the server             # 不使用服務器提供的時間戳

# 響應response                                  
-S,  --server-response           print server response
     --spider                    don't download anything

# 下載速率設置...
-Q,  --quota=NUMBER              set retrieval quota to NUMBER                    # 設置遞歸層數
     --bind-address=ADDRESS      bind to ADDRESS (hostname or IP) on local host   # 綁定ip訪問,即以ip進行下載數據
     --limit-rate=RATE           limit download rate to RATE                      # 下載速率
     --no-dns-cache              disable caching DNS lookups                      # 不使用dns緩存,直接進行dns查詢
     --restrict-file-names=OS    restrict chars in file names to ones OS allows   # 使用系統所限制字符
     --ignore-case               ignore case when matching files/directories      # 忽略大小寫

# Http請求頭設置
-E,
      --header=STRING             insert STRING among the headers
      --compression=TYPE          choose compression, one of auto, gzip and none. (default: none)
      --max-redirect              maximum redirections allowed per page           # 最大次數進行重定向
      --proxy-user=USER           set USER as proxy username
      --proxy-password=PASS       set PASS as proxy password
      --referer=URL               include 'Referer: URL' header in HTTP request
      --save-headers              save the HTTP headers to file    
-U,   --user-agent=AGENT          identify as AGENT instead of Wget/VERSION
      --no-http-keep-alive        disable HTTP keep-alive (persistent connections)
      --no-cookies                don't use cookies
      --load-cookies=FILE         load cookies from FILE before session
      --save-cookies=FILE         save cookies to FILE after session
      --keep-session-cookies      load and save session (non-permanent) cookies
      --post-data=STRING          use the POST method; send STRING as the data
      --post-file=FILE            use the POST method; send contents of FILE
      --method=HTTPMethod         use method "HTTPMethod" in the request
      --body-data=STRING          send STRING as data. --method MUST be set
      --body-file=FILE            send contents of FILE. --method MUST be set
      --content-disposition       honor the Content-Disposition header when
                                    choosing local file names (EXPERIMENTAL)
      --content-on-error          output the received content on server errors
      --auth-no-challenge         send Basic HTTP authentication information
                                    without first waiting for the server's
                                    challenge

參考:linux下載命令

使用wget -Q限制總下載文件大小
當你想要下載的文件超過5M而退出下載,你可以使用以下命令:

wget -Q5m -i filelist.txt

注意:這個參數對單個文件下載不起作用,只能遞歸下載時才有效。

使用wget -r -A下載指定格式文件
可以在以下情況使用該功能

  • 下載一個網站的所有圖片
  • 下載一個網站的所有視頻
  • 下載一個網站的所有PDF文件
wget -p /path -A "*.png" url 
wget -p /path -A png,jpg url

下載整個網站

你甚至可以用wget下載完整的站點, 然后進行離線瀏覽. 方法是使用如下命令:

wget --mirror --convert-links --page-requisites --no-parent -P /path/to/download https://example-domain.com

--mirror 會開啟鏡像所需要的所有選項.
--convert-links 會將所有鏈接轉換成本地鏈接以便離線瀏覽.
--page-requisites 表示下載包括CSS樣式文件,圖片等所有所需的文件,以便離線時能正確地現實頁面.
--no-parent 用於限制只下載網站的某一部分內容.
-P設置下載路徑.

壓縮與解壓

tar
-c: 建立壓縮檔案
-x:解壓
-t:查看內容
-r:向壓縮歸檔文件末尾追加文件
-u:更新原壓縮包中的文件
這五個是獨立的命令,壓縮解壓都要用到其中一個,可以和別的命令連用但只能用其中一個。下面的參數是根據需要在壓縮或解壓檔案時可選的。

-z:有gzip屬性的
-j:有bz2屬性的
-Z:有compress屬性的
-v:顯示所有過程
-O:將文件解開到標准輸出

下面的參數-f是必須的
-f: 使用檔案名字,切記,這個參數是最后一個參數,后面只能接檔案名。

小節

  1. *.tar 用 tar –xvf 解壓
  2. *.gz 用 gzip -d或者gunzip 解壓
  3. .tar.gz和.tgz 用 tar –xzf 解壓
  4. *.bz2 用 bzip2 -d或者用bunzip2 解壓
  5. *.tar.bz2用tar –xjf 解壓
  6. *.Z 用 uncompress 解壓
  7. *.tar.Z 用tar –xZf 解壓
  8. *.rar 用 unrar e解壓
  9. *.zip 用 unzip 解壓
    解壓的時候,有時候不想覆蓋已經存在的文件,那么可以加上-n參數
unzip -n test.zip
unzip -n -d /temp test.zip

只看一下zip壓縮包中包含哪些文件,不進行解壓縮unzip -l test.zip

查看顯示的文件列表還包含壓縮比率unzip -v test.zip

檢查zip文件是否損壞unzip -t test.zip

如果已有相同的文件存在,要求unzip命令覆蓋原先的文件unzip -o test.zip -d /tmp/

示例:

eg1:  unzip mydata.zip -d mydatabak #解壓到mydatabak目錄
  1. xz
    這是兩層壓縮,外面是xz壓縮方式,里層是tar壓縮,所以可以分兩步實現解壓
$ xz -d node-v6.10.1-linux-x64.tar.xz
$ tar -xvf node-v6.10.1-linux-x64.tar


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM