Requirements: Copy the folder to the Linux directory, overwriting all folders with the same name under the Linux directory target: Linux, execute this script, enter the folder name, you can bulk copy overwrite. Instructions for use: first putThis script fileand thethe folder to copymove to the Linux that will be overwrittenCatalogue, and then execute this script. Execute command: ./tcopy.sh 1. If prompted-bash:./tcopy.sh:permission denied, assign permissions first: chmod +x tcopy.sh then execute the./tcopy.sh. 2. If you feel trouble, sh tcopy.sh is ok.
Logical Description: the CP command of the original system is the Cp-i command, so the command to execute the CP cannot be overwritten automatically. So change the file .~/.BASHRC, and finally change back. read the user input file name and use wildcards to put the full folder in the array the loop structure places all the files in the original folder into all the arrays.
Code:
#!/bin/shsed-i ' S/alias cp/#&/' ~/.bashrc >/dev/nullecho "Please input the filename:" Read namearray= ($name * ) name2= "$name/*" for ((I=1; i<${#array}; i++)) Docp-r $name 2 ${array[$i]}donesed-i "/#alias cp/i\alias cp= ' cp-i '" ~/.b ASHRC >/dev/nullsed-i '/#alias cp/d ' ~/.BASHRC >/dev/null
save file as tcopy.sh
Code Description:
Sed-i ' S/alias cp/#&/' ~/.BASHRC >/dev/null
Comment out the alias CP line in the ~/.BASHRC file
array= ($name *)
Use wildcards to put all folders into an array
Name2= "$name/*"
name2 All files in the original folder directory
${#array}
Get array length
Cp-r $name 2 ${array[$i]}
Copying files
<pre name= "code" class= "CPP" style= "FONT-SIZE:14PX; line-height:21px; " >sed-i "/#alias cp/i\alias cp= ' cp-i '" ~/.BASHRC >/dev/nullsed-i '/#alias cp/d ' ~/.BASHRC >/dev/null
Change back~/.BASHRC File
Risk items: The original ~/.BASHRC file may not be alias cp= ' cp-i '
If you use this script, the copy file appears every time you ask whether to overwrite that is: Cp:overwrite, please manually modify the ~/.BASHRC file, add # in front of alias CP Line
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Scripts for copying folders to all folders with the same name under Linux