<span id="Label3"></p><p><p><strong>The directory structure is as Follows:</strong></p></p><pre class="brush:bash;toolbar:false"><pre class="brush:bash;toolbar:false">/data/backup/├──20150508│├──access_20150508.gz│└──access_20150508.gz.1├──20150509│├──access_20150509.gz│└ ──access_20150509.gz.1├──20150510│├──access_20150510.gz│└──access_20150510.gz.1</pre></pre><p><p>requirements, Move all The. 1 files to the/data/backup1/directory, the directory structure can not be changed, that Is,/data/backup1 is also a date-named directory, the file is moved to the corresponding directory, and renamed Removed. 1</p></p><p><p><br></p></p><p><p><strong>Problem Recurrence:</strong></p></p><p><p>Create the required files for your experiment with a script that reads as Follows:</p></p><pre class="brush:bash;toolbar:false"><pre class="brush:bash;toolbar:false">#!/bin/shfor i in ' seq ' does dir_name=$ (date +%y%m%d-d "$i days Ago") dst_dirname=/data/backup/$dir _name mkdir-p $dst _dirname CD $DST _dirname #为区分移动后的同名文件, respectively 1 and 2 echo "1" > access_${dir_name}.gz echo "2" > access_${dir_name}.gz.1 Done</pre></pre><p><p><br></p></p><p><p><strong>Workaround:</strong></p></p><p><p>Or a script to implement:</p></p><pre class="brush:bash;toolbar:false"><pre class="brush:bash;toolbar:false">#!/bin/shfor file in ' find/data/backup/-name *.gz.1 ' do dir_name= ' echo $file |awk-f/' {print $4} ' #提取出目录名 dst_dir_na Me=/data/backup1/$dir _name/mkdir-p $dst _dir_name #创建要移动到的目录 mv $file $dst _dir_name cd $dst _dir_name rename gz.1 gz ./* #因为当前目录下只有一个. gz.1 file, so you can match the done with *</pre></pre><p><p>To view the results after executing the script:<br></p></p><pre class="brush:bash;toolbar:false">[[email protected] data]# tree /data/backup//data/backup/├── 20150508│ └── access_20150508.gz├── 20150509│ └── access_20150509.gz├── 20150510│ └── access_20150510.gz ... [[email protected] data]# grep -r 1 /data/backup//data/backup/20150524/access_ 20150524.gz:1/data/backup/20150514/access_20150514.gz:1/data/backup/20150519/access_20150519.gz:1 ... [[email protected] data]# tree /data/backup1//data/backup1/├── 20150508│ └── access_20150508.gz├── 20150509│ └── access_20150509.gz├── 20150510│ └── access_20150510.gz ... [[email protected] data]# grep -r 2 /data/backup1//data/backup1/20150524/access_ 20150524.gz:2/data/backup1/20150514/access_20150514.gz:2/data/backup1/20150519/access_20150519.gz:2 ...</pre><p><p>As you can see from the results, the contents of All/data/backup/directories are 2. gz.1 files have been successfully moved to the/data/backup1/directory, and the directory structure remains intact.<br></p></p><p><p>This article is from "sharing is a pleasure" blog, please make sure to keep this source http://gladiator.blog.51cto.com/2313511/1655914</p></p><p><p>Move files in bulk and rename them</p></p></span>
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