Shell script downloads resources in batches and retains the path. shell downloads resources.

Source: Internet
Author: User

Shell script downloads resources in batches and retains the path. shell downloads resources.
Sample resource list

For example, url.txt:

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

We need to download these images and save them in their respective folders.

The script is as follows:

For example, download. sh.

#! /Bin/bash # desc: download resource # author: ten years later, Lu's brother mydir = 'pwd' while read linedo {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

Note the following points:

1. Delete the line break at the end of the text file:

tr -d '\r' 

2. Obtain the Resource Name:

${picdir##*/}

3. Obtain the resource path:

${picdir%/*}
Run
sh download.sh url.txt

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.