Shell recursive function---loop copy file to the specified directory

Source: Internet
Author: User

Function: Title

Code:

#!/bin/shrecursive ( ) {     for file in $1      do       subfile= ' ls $2$3/$file '         for subsubfile in  $subfile        do #                echo  $subsubfile          if [  "$subsubfile"  ==  "$2$3/$file"  ]         then                 rm -rf $3/$file                  mv  $subsubfile  $3/$file           else                 recursive  ' ls $2$3/$file '  $2 $3/$file;          fi       done     done}cd / tmpmkdir update;tar -zxvf update.tgz -c update;chmod -r 755 /tmp/ Update/*;rootdir= "/tmp/update" filelist= ' ls /tmp/update/' for file in  $filelistdo   Subfile= ' ls  $rootdir/$file '   for subsubfile in  $subfile    do    if [  "$subsubfile"  !=  "$rootdir/$file"  ]   then         $ (recursive  ' ls  $rootdir/$file '   $rootdir  / $file)         # rm -rf /$file/$subfile          # mv  $rootdir/$file/$subsubfile  /$file          break 1;   else        kill -9  ' ps|grep  $file '         rm -f /usr/bin/$file          mv  $rootdir/$file  /usr/bin   fi  donedone#reboot


The following are the newly added


Create a soft link for all the files under the folder, the link file can be specified to save to a different directory

When FileList is assigned, you can specify the source path,

In the following "Ln-s $file arm-linux-" $LASTWD "", you can specify the directory of the linked file, such as the source path is the current path, the target path is the current path

#/bin/bash


filelist= ' ls./'


For file in $filelist
Do
firstwd= $file | Cut-d "-"-f1


# if ["$firstwd" = = "Arm"]
# Then
Lastwd= ' echo ' $file | Sed ' s/.*-< Span style= "border:0px;padding:0px;margin:0px;vertical-align:0px;line-height:normal;" >[ ]$/\1/"
Echo $LASTWD
Ln-s $file arm-linux-"$LASTWD"
# fi
Done


This article is from the "QT Development" blog, make sure to keep this source http://2161404.blog.51cto.com/2151404/1825919

Shell recursive function---loop copy file to the specified directory

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.