wget 克隆 wordpress 博客镜像
wget -e robots=off -w 1 -xq -np -nH -pk -m -t 1 -P "./wordpress.org" "http://wordpress.org"
用wget做站点镜像 wget -r -p -np -k http://ys138.win
批量替换文本内容
sed -i "s/index.html?p=/index.php?p=/g" `grep -rl "index.html?p=" ./`
批量删除当前目录包括子目录的 .bak 文件
find ./ -name "*.bak" -exec rm -rf {} \;
批量替换文件名 http://blog.****.net/wangjichen_1/article/details/14124517
使用【 】 做分割符, -F'\\\[|]' ,如果是其他的分隔符,-F'[ 1 | a | c ]'
#!/bin/bash find . -type f -name "*.css?*" | while read name; do echo $name newName=$(echo $name | awk -F'[|?]' '{print $1}') echo $newName mv $name $newName done
抓取的文件有时候是 index.html?p=555 这个种格式的,index.html 中的超链接也是这种格式的。如果不批量更改的话,用这个 php 文件做个跳转也方便。
需要wordpress的备份文件,从备份文件中分析得到 id 和 url 的关系
<?php /* * * 从 wordpress 的备份数据中提取 id 和 url * 适用于 wget 提取的 wordpress 静态镜像 * */ $xmlfile = 'wordpress.2017-05-10.xml'; # wordpress备份文件 $host = 'ys138.win'; # 不带http或者https,最后边不加 / if(file_exists('url.txt') == false){ if(file_exists($xmlfile) == false)die('backupfileisnotexists'); $c = file_get_contents($xmlfile); $line = explode("\n", $c); $ny = count($line); $item = ''; $url = ''; for($y = 0;$y < $ny;$y++){ if(strpos($line[$y], '<item>'))$item .= "<itemline=$y>\r\n"; if(strpos($line[$y], '<wp:post_id>')){ $item .= $line[$y] . "\r\n"; $postid = str_replace(array('<wp:post_id>', '</wp:post_id>', '<![CDATA[', ']]>'), '', $line[$y]); $url .= trim($postid) . ' '; } if(strpos($line[$y], '<wp:post_date>')){ $item .= $line[$y] . "\r\n"; $date = str_replace(array('<wp:post_date>', '</wp:post_date>', '<![CDATA[', ']]>'), '', $line[$y]); $postdate = explode(' ', $date); $date = str_replace('-', '/', $postdate['0']) . '/'; $url .= trim($date); } if(strpos($line[$y], '<wp:post_name>')){ $item .= $line[$y] . "\r\n"; $postname = str_replace(array('<wp:post_name>', '</wp:post_name>', '<![CDATA[', ']]>'), '', $line[$y]); $url .= trim($postname) . "/\r\n"; } if(strpos($line[$y], '</item>'))$item .= "</item>\r\n"; } // file_put_contents('item.txt',$item); # 精简的 item file_put_contents('url.txt', $url); # 包含 id 和 url } $url = file_get_contents('url.txt'); $arr_url = array(); $array = explode("\r\n", $url); $nz = count($array)-1; for($z = 0;$z < $nz;$z++){ $array_url = explode(' ', $array[$z]); $arr_url = $arr_url + array($array_url['0'] => $array_url['1']); } // print_r($arr_url); # $arr_url 是 $url 的数组格式 if(isset($_GET['p'])){ $scheme = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'))?'https://':'http://'; $url = $scheme . $host . '/' . $arr_url[$_GET['p']]; echo $url; header('Location:' . $url); }