濮阳杆衣贸易有限公司

主頁 > 知識庫 > Shell腳本實(shí)現(xiàn)批量下載資源并保留原始路徑

Shell腳本實(shí)現(xiàn)批量下載資源并保留原始路徑

熱門標(biāo)簽:寧波智能外呼系統(tǒng)公司 安裝外呼系統(tǒng)費(fèi)用 申請公司400電話要注意什么 電銷機(jī)器人 劍魚 曲阜400電話辦理 地圖標(biāo)注輻射圖案 聯(lián)通電話機(jī)器人怎么接 奧維互動地圖標(biāo)注參數(shù) 衛(wèi)星地圖標(biāo)注地名

示例資源列表
如url.txt:

復(fù)制代碼 代碼如下:

http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663703.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663701.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663704.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663705.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663706.png

我們需要下載這些圖片,并保存在各自的文件夾下。

腳本如下

如download.sh

復(fù)制代碼 代碼如下:

#!/bin/bash
# desc: download resource
# author: 十年后的盧哥哥

mydir=`pwd`

while read line
do
{
    if [ -n "$line" ]
    then
        cd $mydir
        url=$(echo "$line" | tr -d '\r')
        picdir=$(echo $url | sed -r 's/http:\/\///g')
        picname=$(echo ${picdir##*/})
        picpath=$(echo ${picdir%/*})
        mkdir -p $picpath
        cd $picpath
        wget -O $picname `echo $url`
    fi
}
done $1
exit 0


這里有幾點(diǎn)要注意:

1、為了去掉文本文件中行末的換行符,要進(jìn)行刪除:

復(fù)制代碼 代碼如下:

tr -d '\r'

2、取資源名:
復(fù)制代碼 代碼如下:

${picdir##*/}

3、取資源路徑:
復(fù)制代碼 代碼如下:

${picdir%/*}

運(yùn)行
復(fù)制代碼 代碼如下:

sh download.sh url.txt

標(biāo)簽:大慶 大興安嶺 仙桃 安康 江西 遵義 上饒 三門峽

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Shell腳本實(shí)現(xiàn)批量下載資源并保留原始路徑》,本文關(guān)鍵詞  Shell,腳本,實(shí)現(xiàn),批量,下載,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Shell腳本實(shí)現(xiàn)批量下載資源并保留原始路徑》相關(guān)的同類信息!
  • 本頁收集關(guān)于Shell腳本實(shí)現(xiàn)批量下載資源并保留原始路徑的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    沙田区| 吉水县| 武安市| 寿宁县| 东丰县| 乡宁县| 天水市| 易门县| 武穴市| 永安市| 南木林县| 衡山县| 肇源县| 武陟县| 名山县| 福海县| 浑源县| 象山县| 英德市| 邯郸县| 沭阳县| 永安市| 德州市| 牡丹江市| 德兴市| 庆云县| 金坛市| 新乐市| 剑河县| 泰兴市| 台湾省| 辰溪县| 克什克腾旗| 阳江市| 深泽县| 恩施市| 漠河县| 松阳县| 崇仁县| 普格县| 龙里县|