The shell script implements the bulk download resource and retains the original path _linux shell

Source: Internet
Author: User

Sample Resources List
such as Url.txt:

Copy Code code as follows:

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

We need to download these pictures and save them in our respective folders.

The script is as follows

such as download.sh

Copy Code code as follows:

#!/bin/bash
# Desc:download Resource
# Author: Ten years later, Lou's brother

Mydir= ' pwd '

While Read line
Todo
{
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 < $
Exit 0


Here are a few points to note:

1. In order to remove line breaks at the end of a text file, delete:

Copy Code code as follows:

Tr-d ' \ r '

2, take the resource name:
Copy Code code as follows:

${picdir##*/}

3, take the resource path:
Copy Code code as follows:

${picdir%/*}

Run
Copy Code code as follows:

SH download.sh url.txt

Related Article

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.