Linux Shell脚本获取当前路径遍历所有指定文件
- #!/bin/bash
- #获取当前SH脚本的绝对路径
- Cur_Dir=$(pwd)
- #echo $Cur_Dir
- function ergodic(){
- for file in ` ls $1`
- do
- # echo $file
- if [ -d $1"/"$file ]
- then
- ergodic $1"/"$file
- else
- local path=$1"/"$file #得到文件的完整的目录
- local name=$file #得到文件的名字
- #echo ${file##*.} /**** 打印返回的文件名 ****/
- #echo ${file##*.} /**** 打印返回的文件名 ****/
- #判断所匹配的文件扩展名
- if [ "${file##*.}" = "gz" ]||[ "${file##*.}" = "bz2" ]||[ "${file##*.}" = "zip" ]; then #警告:中括号内不前后必须流空格、等号前后必须留空格!
- #echo ${1#*/software} /**** 截取字符串处理当前路径 ****/
- echo "http://down.liuxinxiu.com"${1#*/software}"/"$file >>a.txt
- echo "http://down.liuxinxiu.com"${1#*/software}"/"$file
- fi
- fi
- done
- }
- INIT_PATH=$Cur_Dir
- ergodic $INIT_PATH
通用脚本,当前目录名为二级域名,一级域名自行定义
- #!/bin/bash
- #获取当前SH脚本的绝对路径
- Cur_Dir=$(pwd)
- Sub_Path=${Cur_Dir##*/}
- #echo $Cur_Dir
- #先清空一下文件,注明:如果不清空则一直在原文件尾部追加
- : > b.txt
- #当前目录下遍历循环文件的方法
- function ergodic(){
- for file in ` ls $1`
- do
- # echo $file
- if [ -d $1"/"$file ]
- then
- ergodic $1"/"$file
- else
- local path=$1"/"$file #得到文件的完整的目录
- local name=$file #得到文件的名字
- #echo ${file##*.} /**** 打印返回的文件名 ****/
- #echo ${file##*.} /**** 打印返回的文件名 ****/
- #判断所匹配的文件扩展名
- if [ "${file##*.}" = "gz" ]||[ "${file##*.}" = "bz2" ]||[ "${file##*.}" = "zip" ]; then #警告:中括号内不前后必须流空格、等号前后必须留空格!
- #echo ${1#*/software} /**** 截取字符串处理当前路径 ****/
- echo "http://"$Sub_Path".liuxinxiu.com"${1#*/software}"/"$file >>b.txt
- echo "http://"$Sub_Path".liuxinxiu.com"${1#*/software}"/"$file
- fi
- fi
- done
- }
- INIT_PATH=$Cur_Dir
- ergodic $INIT_PATH
linux内核升级时间图谱及版本号说明
编译安装更新SSH到6.7
- 下载openssh-6.7p1.tar.gz
- wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-6.7p1.tar.gz
- cd openssh-6.7p1/
- 备份ssh配置文件 :
- mv /etc/ssh /etc/ssh.bak
- 查看是否缺包
- rpm -qa | egrep "gcc|make|perl|pam|pam-devel|zlib|zlib-devel"
- 如果有配置yum了的话可以直接yum安装这些包,这样既可以检验是否装了,没装的直接装上。
- yum -y install gcc* make perl pam pam-devel zlib zlib-devel openssl openssl-devel
- 先卸载完旧版本的openssh
- rpm -e `rpm -qa | grep openssh
- 如果configure时出现-- configure: error: *** OpenSSL headers missing - please install first or check config.log ***
- [root@localhost openssh-6.7p1]#
- 解决办法:安装openssl以及openssl-devel
- yum install openssl openssl-devel
- ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords
- make
- make install
- 查看最新的版本:
- sshd -v
- 复制启动脚本到/etc/init.d
- cp /home/openssh-6.7p1/contrib/redhat/sshd.init /etc/init.d/sshd
- 加入开机自启
- chkconfig --add sshd
- chkconfig sshd on
- chkconfig --list
- 启动sshd,用start或reload。不要restart,restart 会直接断开连接,而并不会接着启动sshd服务,这时候要通过其他途径进入机器,然后启动sshd服务才行。
- 如果xshell4连接不上,修改配置,使xshell4默认支持:
- vi /etc/ssh/sshd_config
- #x11Forwarding yes
- #UseLogin yes
LINUX 机器配置整理文章
系统版本:CentOS-6.4
创建Xfile软连接指向目标目录
- rm -rf /www/youyuan.com.1/htdocs/xfile
- sudo ln -s /opt/xfile /www/youyuan.com.1/htdocs/xfile
Linux复制本地文件到远程
scp -r /www/next.youyuan.com2 root@192.168.3.162:/www/
CentOS下安装yuicompressor-2.4.8合并JS-CSS.txt
- 查看CentOS自带JDK是否已安装
- yum list installed |grep java
- root@pts/0 # yum list installed |grep java
- java-1.6.0-openjdk.x86_64
- java-1.6.0-openjdk-devel.x86_64
- 查看yum库中的Java安装包
- yum -y list java*
- 使用yum安装Java环境。
- yum -y install java-1.7.0-openjdk*
- 官方网站:http://yui.github.io/yuicompressor/
- wget http://soft.liuxinxiu.com/yuicompressor/yuicompressor-2.4.8.zip
- unzip yuicompressor-2.4.8.zip
- 2. 将yuicompressor.jar放在任意目录,比如 /opt/software/yuicompressor/yuicompressor.jar
- 3. 编写bash脚本,保存为yui.sh
- #!/usr/bin/env bash
- java -jar /root/bin/yuicompressor-2.4.8.jar $1 > $2
- java -jar /root/bin/yuicompressor-2.4.8.jar header.js -o header.yy.js --charset utf-8 --type js
- java -jar /root/bin/yuicompressor-2.4.8.jar /opt/xfile/www/js/pages/123/*.js -o /opt/xfile/www/js/pages/123/*.yy.js --charset utf-8 --type js
- 4. 运行命令使yui.sh可执行
- chmod +x /root/bin/yui.sh
- 5. 建立链接
- sudo ln -s /root/bin/yui.sh /usr/bin/yui
- 6. 使用方法
- yui old.js new.js
#!/bin/bash
#发布时临时存放svn里下载的style文件
XfileJS="/opt/xfile/www/js/pages/ceshi/"
XfileCSS="/opt/xfile/www/js/pages/ceshi/"
#rm -rf $svn_style
#查找到$xfileJS目录下的所有.js文件,然后逐个压缩之
echo "compress js ..."
for js in `find $XfileJS -name "*.js"`;
do
#转成绝对路径,find出来的是相对路径
apath=`readlink -f $js`
echo "compress $apath"
new=`echo $js | sed 's/\.js//g'`
cp -rf $js $new".temp.js"
temp=`echo $js | sed 's/\.temp.js//g'`
#压缩后还是输出在原来的位置,相当于覆盖原有文件
java -jar /root/bin/yuicompressor-2.4.8.jar $temp -o $temp --type js --charset utf-8
done
#压缩所有的.css文件,过程与上面类似
echo "compress css ..."
for css in `find $XfileCSS -name "*.css"`;
do
apath=`readlink -f $css`
echo "compress $apath"
java -jar /root/bin/yuicompressor-2.4.8.jar $apath -o $apath --type css --charset utf-8
done
#echo "force cp $svn_style to $style"
#强制(-f)复制到目标目录,即nginx下的style目录
#cp -fr $svn_style/* $style
#rm -rf $svn_style
echo "deploy style success!"
比较实用的sed命令总结
比较实用的sed命令总结
- sed '/^\/opt\//! s/^.*$/\/home\/admin\/mydoc&/' file
- sed -i '/^http:\/\//! s/^\/\//\/home\/admin\/mydoc&/' 1.txt (在//之前追加)
- sed -i '/^http:\/\//! s/^\/\///g' 1.txt (不是以http://打头的删除//)
- sed -i '/http:\/\//! s/\/\/.*//g' 1.txt (非常强大,无论是首行还是中间都删除//.*)
- 要求把含有冒号的连续的多行合并成一行,以空格分割(用于合并CSS写成一行):
- sed '/:/{:a;N;/\n[^:]*$/!{$!ba};s/\n\([^:]*:\)/ \1/g}' 2.txt
- 删除以#打头的内容
- sed -i "s/#.*//g" 1.txt
Linux find 批量查找文件内容
find ./ -name "*.php" | xargs grep "js.bjlcp.com"