Requirements: Copy the folder to the Linux folder. Overwrite all folders with the same name under the Linux folder target: Linux, run this script. Enter a directory name. You can bulk copy overrides. Instructions for use: first putThis script fileand thethe folder to copymove to the Linux that will be overwrittenfolder, and then run this script to do so. To Run the command: ./tcopy.sh 1. Hypothesis Hints-bash:./tcopy.sh:permission denied, assign permissions first: chmod +x tcopy.sh run it again./tcopy.sh can. 2. If you feel trouble, sh tcopy.sh is ok.
Logical Description: The CP command for the original system. is the Cp-i command. This way, running the CP command is not an active override.
So change the document ~/.BASHRC, and finally change back. reads the user input file name, uses the wildcard character to put the whole directory in the array loop structure to put all the files in the original directory 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
Stare out the alias CP line in the ~/.BASHRC file
array= ($name *)
Use wildcards to put all directories into arrays
Name2= "$name/*"
name2 All files under the original folder folder
${#array}
Get array length
Cp-r $name 2 ${array[$i]}
Copy 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 '
Suppose you use this script. A copy file appears every time you ask if the overlay is: Cp:overwrite. Please manually change the ~/.BASHRC file and add # to the front of the alias CP Line
A script that copies directories to all directories of the same name under Linux