File Move Script

Source: Internet
Author: User

Scripting features: Move files from the specified directory to the target directory and keep the structure intact

Scenario: Used to remove old data (the author is an FTP server environment) that does not need to be retained in the server

Usage Note: Modify the source directory and target directory in the script and modify the data for the number of days before the move

Script code:

#!/bin/bashwdir= "/ftp"   #源目录bdir = "/mvbackup/ftp"   #目标目录fl = "/tmp/filelist" okl= "/tmp/oklist" erl= "/tmp/ Errlist "dl="/tmp/dirlist "mvlog="/var/log/mvfile.log "mdlog="/var/log/mkdir.log "#enter  working (source)  directorcd  $wdir #create source file listif [ -f  $FL  ]; then  rm -f  $flfifind  -mtime +300 -type f | grep -v  "\/\." >  $fl #            ^300 days ago Data #filter  source file listif [ -f  $okl  ]; then rm -f  $oklfiif  [  -f  $erl  ]; then rm -f  $erlfiif  [ ! -f  $fl  ];  then echo stop:1 exit 1fioldifs= $IFSIFS =$ ' \ n ' for i in $ (cat  $FL) do if [ -f  $i  ]; then  echo  $i  >>  $okl   else  echo  "$i"  >>  $erl  fidoneifs= $oldIFS #create traget director listif [ -f   $DL  ]; then rm -f  $dlfiif  [ ! -f  $okl  ]; then  echo stop:2 exit 2ficat  $okl  | awk -f '/'   ' {$1= ""; nf-=1;ofs= "/";p rint} '  | sort -u >  $dl #create traget directorif [  ! -f  $dl  ]; then echo stop:3 exit 3fioldifs= $IFSIFS =$ ' \ n ' for  i in $ (cat  $dl) do if [ ! -d  "$bdir $i"  ]; then   mkdir -p  "$bdir $i"   if [ ! $? = 0 ]; then    echo  "$bdir $i"  >>  $mdlog   fi   #echo   $bdir $i  fidoneifs= $oldIFS #move file to traget folderif [ ! -f  $okl  ];  then echo stop:4 exit 4fioldifs= $IFSIFS =$ ' \ n ' for i in $ (cat  $okl) do if [ -f  "$i"  ];  Then  j= "$bdir $ (echo  $i  | awk -f '/'   ' {$1=" "; nf-=1;ofs= "/";p Rint} ') " fi if [ -d  $j"  ]; then  echo s: "$i"   echo d: "$j"   mv -f  "$i"   "$j"   if [ ! $?  = 0 ]; then   echo  "$i"  >>  $mvlog   fi  fidoneifs= $oldIFS


This article is from the "Old Tan Linux Cluster blog" blog, please be sure to keep this source http://cmdschool.blog.51cto.com/2420395/1843962

File Move Script

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.