我现在管理的网站已被破坏。我想保留内容,但从临时WordPress安装中复制所有php,txt和css文件,并使用脚本将它们移动到相应的位置。
我不知道如何制作类似这样的bash或shell脚本:
#!/usr/bash
type = [*\.php|*\.css|*\.ini|*\.txt]
find /temporary/WordPress/ -type f -name '$type' {} + > file-paths-in-temporary-wordpress ;
egrep -o '[a-zA-Z]\.[php|css|ini|txt]' file-paths-in-temporary-wordpress > file-names-of-temporary-WordPress-Installation
find /old/installation/WordPress -type f -name '$type' {} + > file-paths-to-use-as-reference
while read $type in file-names-of-temporary-WordPress-Installation ; do
// locating file-names-of-temporary-WordPress-Installation in old WordPress site, copy files from file-paths-in-temporary-wordpress to the matching locations in the old WordPress installation //
我对如何让它发挥作用感到困惑。显然,这非常不完整。
我希望的结果是将新WordPress安装中的所有php,ini,css和txt文件复制到旧WordPress站点的相应位置。
我可以使用:
find /temporary/WordPress -type f -name '*.php' -exec cp -fvr {} /old/WordPress/Installation/ + ;
find /temporary/WordPress -type f -name '*.css' -exec cp -fvr {} /old/WordPress/Installation/ + ;
...等。
有什么想法吗?
请帮忙。谢谢!
答案 0 :(得分:0)
为什么不能搜索每个目录并在匹配时复制?
int main(){
char process[2][2][22]={
"BE 4321 AU","Avanza","BE 2345 JU","Avanza",
"BE 1453 GU","Xenia","BE 2233 FI","Gran Max",
"BE 7809 GM","Mobilio","BE 4426 BI","Ertiga"
"BE 9012 AG","Pajero","BE 9320 YU","Fortuner"};
char broken[2][2][20]={"BE 4321 AU","Avanza","BE 2345 JU","Fortuner"};
int p;
system("clear");
cout<<"Please choose list vehicle\n1. Broken Vehicle\n2. Under Repair...";
cin>>p;
if(p==1){
system("clear");
cout<<"Broken Vehicle List\n\n";
cout<<" ID Car\tMerk Car"<<endl;
for (int i = 0; i < 2; i += 1) {
cout<<i+1<<". ";
for (int j = 0; j < 2; j += 1) {
cout<<process[i][j]<<"\t";
}
cout<<endl;
}
}
else if(p==2){
system("clear");
cout<<"Under Repair Vehicle List\n\n";
cout<<" ID Car\tCar Merk"<<endl;
for (int i = 0; i < 2; i += 1) {
cout<<i+1<<". ";
for (int j = 0; j < 2; j += 1) {
cout<<broken[i][j]<<"\t";
}
cout<<endl;
}
}
else{
cout<<"Wrong Choose";
}
}
答案 1 :(得分:0)
您可以先复制所有内容并删除不需要的内容:
cp -r /temporary/WordPress /old/WordPress/
find /old/WordPress/ -type f -regex ".*\.\(php\|css\|ini\|txt\)" -exec rm {} \;
这可能会留下空目录并修复出错的地方(复制你不想要的文件)。
所以正确的方法是只复制你需要的文件。首先转到/ temporary / WordPress,这样你就不需要切断那个目录了:
cd /temporary/WordPress
find . -type f -regex ".*\.\(php\|css\|ini\|txt\)" | while read file; do
dir="/old/WordPress/${file%/*}"
mkdir -p "${dir}" 2>/dev/null
cp "${file}" "/old/WordPress/${file}"
done
(抱歉,未经测试)