广州葆元健康生物科技有限公司


Shell脚本实现批量下载资源并保留原始路径

网络编程 Shell脚本实现批量下载资源并保留原始路径 06-22

示例资源列表
如url.txt:

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

#!/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


这里有几点要注意:

1、为了去掉文本文件中行末的换行符,要进行删除:

tr -d 'r'

2、取资源名:
${picdir##*/}

3、取资源路径:
${picdir%/*}

运行
sh download.sh url.txt

Shell脚本实现从文件夹中递归复制文件
需求前两天碰到需要在十层左右的文件夹中提取文件的需求,于是写了此脚本。如下面这样的文件结构:dir1├──a│├──b││└──file1│└──file2

Shell脚本美化登录界面装饰图(含农历)
今天同事闲得无聊,要我帮忙在linux登录页面里加点他认为很独特的东西,看了下他发的东西,对他表示很无语,下面来看看吧.脚本1:catclcal.sh#!/bin/bash#showChine

Shell脚本自动更新hosts实现免翻墙访问google
上次给大家发了一个python更新googlehosts的脚本,今天看到有人发出了一句用shell来获取googlehosts的脚本,我就拿来稍微简单加工了下,下面给大家shell版的更新


编辑:广州葆元健康生物科技有限公司

标签:脚本,文件,给大家,递归,里加