在将windows上的jsp网页移植到linux情况中时,开采三个个的转移编码及修改暗中同意编码类型太慢,写此脚本实行尝试文件遍历~

1.开立文件夹

一、查找重复的文书(基于md五)

①.寻找test目录下小于十0k和超过300k的文书
#
!/bin/sh
ls
-l /tmp/test/ |awk ‘{print $9}’ |grep -v ^$ | while read LINE
do
size=`ls
-l /tmp/test/$LINE |awk ‘{print $5}’`
if
[ $size -le 100 -o $size -ge 300 ];then
#mv
$LINE /tmp
echo
$LINE
fi
done
或:
find
/tmp -size -100k -o -size +300k -exec ls -l {} \;

好久不写,手生了。

!/bin/sh

mkdir -m 777 “%%1”

二.开立文件

find -type f -exec md5sum ‘{}’ ‘;’ | sort | uniq –all-repeated=separate
-w 33 | cut -c 35- 

二.寻找test目录下大小在40K-60K之间的公文
find test -size +40k -a -size -60k -exec ls -l {} \;

复制代码 代码如下:

!/bin/sh

touch “%%1”

叁.删减文件

二、寻觅最大的1一个文件

三、在目录/tmp下找到一百个以abc开端的文书,然后把这一个文件的率先行保存到文件new中。
#!/bin/sh
cd /tmp
for i in `find . -type f -name “abc*”| head -n 100`
do
head -n1 $i>>new
done

#!/bin/bash
#
#
SPATH=”/root/chengji/WebRoot”
DPATH=”/web”
# 函数初阶有些
CYCLING(){
  filelist=`ls -1 $SPATH`
for filename in $filelist ; do
if [ -f $filename ] ; then 
        echo Filename:$filename
        /usr/bin/iconv -f GBK -t UTF-8  $SPATH/$filename -o 
$DPATH/$filename
        #cp -pv $SPATH/$filename  $DPATH/$filename
该句为中期便利效果测试
        sed  -i  -e  ‘s/gb2312/UTF-8/g’  -e ‘s/GB2312/UTF-8/g’ 
$DPATH/$filename
    elif [ -d $filename ] ; then
        DPATH=$DPATH/$filename
        mkdir -pv $DPATH
        cd $filename
        SPATH=`pwd`
    # Next for recurse 假诺境遇目录举办本人调用。。。完毕深层遍历
        CYCLING
    # Next Usag: basename dirname
        DPATH=`dirname $DPATH`
        SPATH=`dirname $SPATH`
        cd $SPATH
else
        echo “File $SPATH/$filename is not a common file.Please
check.”
    fi
  done
}
 # 命令初始部分
cd $SPATH
CYCLING
echo “All Done.”

!/bin/sh

rm -if “%%1”

4.去除文件夹

find / -type f 2>/dev/null | xargs du 2>/dev/null | sort -n | tail
-n 10 | cut -f 2 | xargs -n 1 du -h

四、把文件b中部分,但是文件a中未有的富有行,保存为文件c,并计算c的行数。
# !/bin/sh
for i in `cat b`
do
grep $i a                     #将b中的行,在a中查找
if [ “$?” -gt “0” ];then      #假使结果大于0(即为找不到)
echo $i>>c                    #将此行输入到c中
fi
done
总结行数wc -l就可以~

理之当然,上边的代码由于使用了函数循环调用,显的很臃肿。上面来1种简易的法子,find一下:

!/bin/sh

rm -rf “%%1”

伍.剔除多个目录下具备的文书夹

三、寻觅文件名长度前10的公文

其一不对,不过先保留着啊~
解决再次的,再用cut,已一为分隔域,打字与印刷出第二域到最后壹域
cat b a | sort -n |uniq -c | awk ‘{if ($1==1) print $0}’|cut -f2- -d “1”
| wc -l
除此以外 uniq -u就可以打字与印刷出不重复的。

复制代码 代码如下:

!/bin/bash

direc=”%%1″ #$(pwd)
for dir2del in $direc/* ; do
if [ -d $dir2del ]; then
rm -rf $dir2del
fi
done

六.清空文件夹

find | sed -e “s/^.*\///” | awk ‘ BEGIN { FS=””} { print NF ”  ” $0  }
‘ | sort -nrf | head -10

伍.贯彻从1加到十0,得出结果:
一:
#!/bin/sh

#/bin/bash
#Auth: Mo
#Desc:
#
SPATH=”/root/chengji”
DIR=WebRoot
DPATH=”/web”
 find ${DIR}   -type d  -exec mkdir -pv ${DPATH}/{}  \;   
 find ${DIR}  -type f -exec  iconv -f GBK -t UTF-8  {} -o  ${DPATH/{} 
\; 
echo “The file Next Listed is not a common file or directory ,please
check.”
find  ${DIR}  ! -type f  -a  ! -type d -ecec  ls -l {} \; 
find  $DPATH -type f -exec sed  -i  -e  ‘s/gb2312/UTF-8/g’  -e
‘s/GB2312/UTF-8/g’  {} \;
echo ‘ ‘
echo “All Done.”

!/bin/bash

direc=”%%1″ #$(pwd)
rm -if $direc/*
for dir2del in $direc/* ; do
if [ -d $dir2del ]; then
rm -rf $dir2del
fi
done

七.读取文件

肆、递归列出最新修改的公文

i=1
sum=0
while [ $i -le 100 ]
do

您大概感兴趣的作品:

  • shell递归输出文件名和目录名的不二等秘书籍
  • shell获取目录下具备文件夹的名号并出口的实例
  • linux
    Shell获取某目录下全数文件夹的名称
  • 使用shell脚本遍历文件夹内全体的文件并作整理计算的艺术
  • 详解shell
    遍历文件夹内全数文件并打字与印刷相对路线
  • shell脚本递归遍历目录及子目录的例证分享
  • shell
    递归遍历目录下的享有文件并统1更名的秘诀

!/bin/sh

柒.1.操作系统暗许编码
cat “%%1” | while read line; do
echo $line;
done

7.2.UTF-8编码
cat “%%1” | while read line; do
echo $line;
done

7.三.分块读取
cat “%%1” | while read line; do
echo $line;
done

八.写入文件

find . -type f -printf ‘%TY-%Tm-%Td %TT %p\n’ | sort 

       sum=`expr $sum + $i`
        i=`expr $i + 1`
done
echo $sum

!/bin/sh

cat > “%%1” << EOF
%%2
EOF

tee “%%1” > /dev/null << EOF
%%2
EOF

5、找到蕴含 pattern
的保有文件,使用vi张开它们并把光标置于第贰个格外的岗位(使用’n’和’:n’举办导航)

二:
i=1
b=0
for i in {1..100}
do
        b=$[$b + $i]
done
echo $b

sed -i ‘$a %%2’ %%2

玖.写入随意文件

find . -type f -exec grep -l pattern {} \; | xargs vi +/pattern

三:
# !/bin/sh
s=0
for((i=1;i<101;i++));do
s=`expr $s + $i`
done
echo $s

!/bin/sh

cat > “%%1” << EOF
%%2
EOF

tee “%%1” > /dev/null << EOF
%%2
EOF

6、删除全体 文件名不为 abc 的文件

四:
# !/bin/sh
i=1
num=0
while [ “$i” != “101” ]
do
num=`expr $i + $num`
i=`expr $i + 1`
done
echo $num

sed -i ‘$a %%2’ %%2

十.读取文件属性

find * -maxdepth 1 -type f ! -name abc -delete 

陆,文件内容为
admin: aa@test.com
body: bb@test.com
admin: cc@test.com 
把相称admin 的行后边丰硕 ;aa@1陆三.com 
sed -r ‘s/(admin)(.*)/\1\2 ;aa@163.com/g’ filename
admin: aa@test.com ;aa@163.com
body: bb@test.com
admin: cc@test.com ;aa@163.com

!/bin/bash

file=%%1
file=${file:?’必须付出参数’}
if [ ! -e $file ]; then
echo “$file 不存在”
exit 1
fi
if [ -d $file ]; then
echo “$file 是三个索引”
if [ -x $file ]shell文件操作大全,Shell脚本遍历目录并批量更改文件编码。; then
echo “可以”
else
echo “不可以”
fi
echo “对此进行搜寻”
elif [ -f $file ]; then
echo “$file 是一个行业内部文件”
else
echo “$file不是叁个正式文件”
fi
if [ -O $file ]; then
echo “你是$file的具有者”
else
echo “你不是$file的具备者”
fi
if [ -r $file ]; then
echo “你对$file拥有”
else
echo “你并不对$file具有”
fi
echo “可读权限”
if [ -w $file ]; then
echo “你对$file拥有”
else
echo “你并不对$file具备”
fi
echo “可写权限”
if [ -x $file -a ! -d $file ]; then
echo “你抱有对$file”
else
echo “你并不具有对$file”
fi
echo “可实行的权能”

11.写入文件属性

七、文件大小求和

-r, –regexp-extended       

!/bin/bash

find . -type f -printf %s\\n | paste -sd+ | bc 

use extended regular expressions in the script.
-r 使sed在本子中应用正则表明式
\1\二即表示后边的(admin)(.*)

修改存放在ext二、ext叁、ext4、xfs、ubifs、reiserfs、jfs等文件系统上的文件或目录属性,使用权限一流用户。

八、删除文件名符合一定格式的同时1四日前的文书

七,文件内容为:
1 aaa 1000
2 bbb 1000
3 aaa 1000
4 aaa 1000
5 ccc 1000
6 bbb 1000
将其产生:
1 aaa 3000
2 bbb 2000
5 ccc 1000
脚本:
# !/bin/sh
for i in `awk ‘{print $2}’ filename |sort|uniq`
do
grep $i filename >$i.txt
sum=`awk ‘{tot+=$3}; END{print tot}’ $i.txt`
three=`sed -n ‘1p’ $i.txt |awk ‘{print $3}’`
sed -i “s/$three/$sum/g” $i.txt
head -n1 $i.txt >>last
rm -f $i.txt
done

局地功效是由Linux内核版本来援助的,假设Linux内核版本低于二.二,那么好些个效果无法促成。一样-D检查压缩文件中的错误的坚守,须求2.伍.1九以上基础本领支撑。别的,通过chattr命令修改属性能够加强系统的安全性,但是它并不适合全体的目录。chattr命令不可能尊敬/、/dev、/tmp、/var目录。

chattr [-RV] [-+=AacDdijsSu] [-v version] 文件或目录
-福特Explorer:递归管理全部的文本及子目录。
-V:详细突显修改内容,并打字与印刷输出。
-:失效属性。
+:激活属性。
= :内定属性。
A:Atime,告诉系统不要改换对那个文件的最终访问时间。
S:Sync,一旦应用程序对这几个文件施行了写操作,使系统及时把修改的结果写到磁盘。
a:Append
Only,系统只同目的在于那个文件从此追加数据,差别意别的进度覆盖或截断那个文件。假设目录具备这些脾气,系统将只允许在那几个目录下创设和改换文件,而不相同意删除任何公文。
i:Immutable,系统不容许对那一个文件举行任何的改变。如果目录具有那个性情,那么其余的历程只好修改目录之下的公文,不容许建设构造和删除文件。
D:检查压缩文件中的错误。
d:No dump,在进行理文件件系统备份时,dump程序将忽略那些文件。
C:Compress,系统以透明的章程减少那几个文件。从这一个文件读取时,重返的是解压之后的数据;而向那一个文件中写入数据时,数据首先被削减之后才写入磁盘。
S:Secure Delete,让系统在剔除那些文件时,使用0填充文件所在的区域。
u:Undelete,当多个应用程序请求删除那个文件,系统会保留其数额块以便以往能够死灰复燃删除这么些文件。

1二.枚举多个目录中的全体文件夹

find /backup/directory -name “FILENAME_*” -mtime +15 | xargs rm -vf 

8,文件内容:
this
is
a
test
script
将其变为:
this is a test script
脚本:
echo `cat filename`

!/bin/bash

OLDIFS=$IFS
IFS=:
for path in $( find “%%1” -type d -printf “%p$IFS”)
do

九、将子目录的享有内容都活动到当前目录

九,相比较字符串大小(主借使用到了sort来比较)
VAR1=abc
VAR2=def
tt=`echo -e “$VAR1\n$VAR2″|sort|head -1`
if [ “$tt” = “$VAR1” ];then
echo $VAR1 relatively large!
else
echo $VAR2 relatively large!
fi

“$path”

done
IFS=$OLDIFS

一3.复制文书夹

find -type f -exec mv {} . \; 

10.联结同样项
[root@test1 tmp]# more file1
DAD|15.0|
JAB|2.0|
JAH|55.0|
HAH|11|
[root@test1 tmp]# more file2
DAD|773.0|
GGC|2.0|
JAB|224.0|
HOH|22|
将其联合成:
DAD     15.0    773.0
JAB     2.0     224.0
GGC     2.0
HOHO    22
JAH     55.0
本子:(以为写的略微笨了)
# !/bin/sh
cat file1 file2 |awk -F’|’ ‘{print $1}’| sort |uniq -c >tmp

!/bin/sh

cp -rf “%%1” “%%2”

1四.复制1个目录下具备的文本夹到另1个索引下

十、在adb 上 安装任何文件夹中的.apk

for i in `awk ‘{if ($1 >=2) print $2}’ tmp`
do
echo `cat file1 file2 |grep $i` | awk -F’|’ ‘{print $1″\t”$2″\t”$4}’
>>last.txt
done
for b in `awk ‘{if ($1==1) print $2}’ tmp`
do
echo `cat file1 file2 |grep $b` | sed ‘s/|/\t/g’ >>last.txt
done
rm -f tmp
简单的:
join -a 1 -a 2 -t “|” file* |sort -t”|” -rk3 |awk -F’|’ ‘{print
$1″\t”$2″\t”$3$4}’

!/bin/bash

direc=”%%1″ #$(pwd)
for dir2cp in $direc/* ; do
if [ -d $dir2cp ]; then
cp $dir2cp “%%2”
fi
done

壹伍.移动文件夹

find ~/path/to/apk/files -name ‘*.apk’ -exec adb install {} \; 

1一,字母分离
将abcdefghijklmnopqrstuvwxy分离成为:
abcde
fghij
klmno
pqrst
uvwxy
用到sed协作正则表明式:
sed
‘s/\(…..\)\(…..\)\(…..\)\(…..\)\(…..\)/\1\n\2\n\3\n\4\n\5/’
filename

!/bin/sh

mv -rf “%%1” “%%2”

16.移动三个目录下具备的文件夹到另三个索引下

1壹、递归修改目录为77柒

1贰.每隔伍秒检查测试另1台服务器上的apache服务,直到其运转后,echo OK
# !/bin/sh
echo | telnet 192.168.2.189 80 >check.txt
grep -i connected check.txt
while [ $? -ne 0 ]         #只要地点grep的结果不为0
do
echo no
sleep 5
echo | telnet 192.168.2.189 80 >check.txt
grep -i connected check.txt
done
echo OK!!!!!!!!!!!

!/bin/bash

direc=”%%1″ #$(pwd)
for dir2mv in $direc/* ; do
if [ -d $dir2mv ]; then
mv $dir2mv “%%2”
fi
done

17.以贰个文本夹的框架在另三个索引下开创文件夹和空文件

find . -exec chmod 777 {} \; 

一三.在/tmp/下建0-255目录,再种种目录再建0-25一个目录,然后在最上边目录上边建玖拾玖个公文
本来写的:
for ((i=0;i<255;i++));do
mkdir -p $i
for ((b=0;b<255;b++));do
mkdir $i/$b
for ((c=0;c<100;c++));do
touch $i/$b/$c
done
done
done
接下去看多个超轻巧的:建五个目录,再各样目录再建多少个目录,然后在最下边目录上面建5个文件
mkdir -p {0..5}/{0..5} && touch {0..5}/{0..5}/{0..5}

!/bin/bash

direc=”%%1″ #$(pwd)
OLDIFS=$IFS
IFS=:
for path in $( find $direc -type d -printf “%p$IFS”)
do
mkdir -p “%%2/${path:${#direc}+1}”
done
IFS=$OLDIFS

1二、带有完整路径ls命令

1四.记录sed的二个用法:
i=1
sed s/2/$i/g file   无需写成 sed ‘s/2/$i/g’ file
那样的补益正是能够选择变量了

cp -a “%%1” “%%2”

表达式 含义
${#string}
{#string}
一,获得字符串长度
string=abc123423四一 //等号二边不要有空格
echo ${#string} //结果11
expr length $string //结果11
expr “$string” : “.” //结果拾一分号贰边要有空格,这里的:根match的用法差不离贰,字符串所在地点
expr index $string ‘1二叁’ //结果肆字符串对应的下标是从0开头的那么些方法让自身想起来了js的indexOf,各个语言对字符串的操作方法大方向都大致,要是有语言基础的话,学习shell会相当的慢的。
三,从字符串开首到子串的最大尺寸
expr match $string ‘abc.
叁’
//结果11人认为那一个函数的用处非常小,为何要从上马起头吧。
肆,字符串截取
echo ${string:四} //2342341 从第7人开首截取前面全数字符串
echo ${string:三:叁} //1二3 从第四人开始截取后边肆人
echo ${string:三:陆} //1234二3 从第1位伊始截取前边伍个人
echo ${string: -四} //23肆一 :左边有空格 截取后二人
echo ${string:(-4)} //2341 同上
expr substr $string 3 三 //1二叁从首个人开首截取后边几个人方面包车型大巴办法让自己记忆了,php的substr函数,后边截取的规则是同样的。
5,匹配展现内容
//例叁中也是有match和这里的match不一致,上边展现的是相称字符的尺寸,而上面的是非常的原委
expr match $string ‘([a-c][0-9])’ //abc12342341
expr $string : ‘([a-c][0-9])’ //abc1
expr $string : ‘.
([0-9][0-9][0-9])’ //341彰显括号中相配的内容这里括号的用法,是还是不是根别的的括号用法有相似之处呢,
陆,截取不协作的内容
echo ${string#a3} //423四一 从$string左侧开端,去掉最短相称子串
echo ${string#c
三} //abc12342341 那样怎么也未尝相配到
echo ${string#c1叁} //423四一 从$string左边起初,去掉最短相配子串
echo ${string##a三} //4一 从$string右侧先河,去掉最长相配子串
echo ${string%3
1} //abc1234二 从$string右侧伊始,去掉最短相称子串
echo ${string%%3*壹} //abc1二从$string右侧开始,去掉最长相配子串这里要专注,必须从字符串的首先个字符开端,或许从最后一个上马,
七,匹配并且替换
echo ${string/23/bb} //abc一bb423四一 替换壹回
echo ${string//23/bb} //abc一bb4bb4一 双斜杠替换全部相配
echo ${string/#abc/bb} //bb12342341
#以什么起始来合作,根php中的^有一些像
echo ${string/%41/bb} //abc1234二3bb %以什么样最后来协作,根php中的$有一点像

find `pwd` -maxdepth 1 -exec ls –color -d {} \; 

原文:

!/bin/bash

direc=$(pwd)
for file in “$(direc)/
do
if [ “${file##
.}” = “sh” ]; then
xterm -e bash $file
elif [ “${file##.}” = “bin” ]; then
xterm -e $file
elif [ “${file##
.}” = “run” ]; then
xterm -e $file
elif [ “${file##.}” = “bundle” ]; then
xterm -e $file
elif [ “${file##
.}” = “pl” ]; then
xterm -e perl $file
elif [ “${file##.}” = “class” ]; then
xterm -e java ${file%.
}
elif [ “${file##.}” = “rpm” ]; then
xterm -e rpm -ivh $file
elif [ “${file##
.}” = “rb” ]; then
xterm -e ruby $file
elif [ “${file##.}” = “py” ]; then
xterm -e python $file
elif [ “${file##
.}” = “jar” ]; then
xterm -e java -jar $file
fi
done
OLDIFS=$IFS
IFS=:
for path in $( find $direc -type d -printf “%p$IFS”)
do
for file in ls $path
do
if [ “${file##.}” = “sh” ]; then
xterm -e bash “”””$path”/”$file””””
elif [ “${file##
.}” = “bin” ]; then
xterm -e “”””$path”/”$file””””
elif [ “${file##.}” = “run” ]; then
xterm -e “”””$path”/”$file””””
elif [ “${file##
.}” = “bundle” ]; then
xterm -e “”””$path”/”$file””””
elif [ “${file##.}” = “pl” ]; then
xterm -e perl “”””$path”/”$file””””
elif [ “${file##
.}” = “class” ]; then
xterm -e java “”””$path”/”${file%.}””””
elif [ “${file##
.}” = “rpm” ]; then
xterm -e rpm -ivh “”””$path”/”$file””””
elif [ “${file##.}” = “rb” ]; then
xterm -e ruby “”””$path”/”$file””””
elif [ “${file##
.}” = “py” ]; then
xterm -e python “”””$path”/”$file””””
elif [ “${file##*.}” = “jar” ]; then
xterm -e java -jar “”””$path”/”$file””””
fi
done
done
IFS=$OLDIFS

1八.复制文本

壹三、当前目录里边文本文件的个数

!/bin/sh

cp %%1 %%2

1玖.复制多个目录下具有的文件到另三个索引

file -i * | grep ‘text/plain’ | wc -l 

!/bin/bash

direc=”%%1″ $(pwd)
for file in “$direc/*”
do
cp “$file” “%%1”
done

20.提取扩充名

1④、将缺乏.md5的文书 自动补上.md伍

!/bin/sh

%%2=${%%1##.}

二一.提取文件名

find . ! -name \*.md5 -exec ‘md5sum “{}” > “{}”.md5’ \;

!/bin/sh

%%2=”$(basename %%1)”

2二.领取文件路线

一5、用find删除文件时候解除特定文件

!/bin/sh

%%2=”$(dirname %%1)”

23.替换扩充名

find . ! -name -delete 

!/bin/sh

%%3=”$(basename %%1)$%%2″

二4.追加门道

1陆、递归删除空目录

!/bin/sh

%%3=”$(dirname %%1)/$%%2″

贰5.活动文件

find . -depth -type d -empty -exec rmdir -v {} + 

!/bin/sh

mv “%%1” “%%2”

2陆.移动2个目录下具备文件到另四个索引

17、把 子目录 添加到 svn ignore 中(忽略)

!/bin/bash

direc=”%%1″ #$(pwd)
OLDIFS=$IFS
IFS=:
for file in “$(direc)/*”
do
mv “$file” “%%1”
done
IFS=$OLDIFS

二七.钦点目录下搜寻文件

find . -type d -not \( -name .svn -prune \) -exec svn propset
svn:ignore ‘*’ {} \; 

!/bin/sh

find -name “%%1”

28.开垦文件对话框

18、寻找main文件 cpp

!/bin/sh

%%1=”$(Xdialog –fselect ‘~/’ 0 0 2>&1)”

2九.文件分割

find . -name “*.cpp” -exec grep -Hn –color=tty -d skip “main” {}
\; 

!/bin/sh

split -b 2k “%%1”

while read f1 f2 f3
do
echo $f1 >> f1
echo $f2 >> f2
echo $f3 >> f3
done

1玖、实践前检查

!/bin/bash

linenum=wc -l httperr8007.log| awk '{print $1}'
n1=1
file=1
while [ $n1 -lt $linenum ]
do
n2=expr $n1 + 999
sed -n “${n1}, ${n2}p” httperr8007.log > file_$file.log
n1=expr $n2 + 1
file=expr $file + 1
done

里面httperr8007.log为您想分割的大文件,file_$file.log
为划分后的文本,最终为file_1.log,file_2.log,file_3.log……,分割完后的每个文件只有1000行(参数能够团结安装)

split 参数:
-b :后边可接欲分割成的档案大小,可加单位,比如 b, k, m 等;
-l :以行数来实行分割;

find /tmp -type f -printf ‘rm “%p”;\n’ 

按每一个文件一千行来划分除

split -l 1000 httperr8007.log httperr

httpaa,httpab,httpac ……..

20、递归的改造增加名

遵照各类文件十0K来划分

split -b 100k httperr8007.log http

httpaa,httpab,httpac ……..

find . -type f -name \*.c | while read f; do mv $f “`basename $f
.c`”.C; done 

!/bin/bash

if [ $# -ne 2 ]; then
echo ‘Usage: split file size(in bytes)’
exit
fi

file=$1
size=$2

if [ ! -f $file ]; then
echo “$file doesn’t exist”
exit
fi

二壹、使用 find sed 批量重命名

TODO: test if $size is a valid integer

filesize=/bin/ls -l $file | awk '{print $5}'
echo filesize: $filesize

let pieces=$filesize/$size
let remain=$filesize-$pieces*$size
if [ $remain -gt 0 ]; then
let pieces=$pieces+1
fi
echo pieces: $pieces

i=0
while [ $i -lt $pieces ];
do
echo split: $file.$i:
dd if=$file of=$file.$i bs=$size count=1 skip=$i
let i=$i+1
done

echo “#!/bin/bash” > merge

echo “i=0” >> merge
echo “while [ $i -lt $pieces ];” >> merge
echo “do” >> merge
echo ” echo merge: $file.$i” >> merge
echo ” if [ ! -f $file.$i ]; then” >> merge
echo ” echo merge: $file.$i missed” >> merge
echo ” rm -f $file.merged” >> merge
echo ” exit” >> merge
echo ” fi” >> merge
echo ” dd if=$file.$i of=$file.merged bs=$size count=1 seek=$i” >>
merge
echo ” let i=$i+1″ >> merge
echo “done” >> merge
chmod u+x merge’

30.文书合并

find . -exec bash -c “mv ‘{}’ ‘\`echo {} |sed -e ‘s/foo/bar/g’\`”‘
\; 

!/bin/sh

cp “%%1″+”%%2” “%%3”

exec 3<f1
exec 4<f2
while read f1 <&3 && read f2 <&4
do
echo $f1 $f2 >> join.txt
done

2二、查找文件并图谋md伍

!/bin/bash

if [ $# -ne 2 ]; then
echo ‘Usage: split file size(in bytes)’
exit
fi

file=$1
size=$2

if [ ! -f $file ]; then
echo “$file doesn’t exist”
exit
fi

find -type f | grep -v “^./.git” | xargs md5sum | md5sum 

TODO: test if $size is a valid integer

filesize=/bin/ls -l $file | awk '{print $5}'
echo filesize: $filesize

let pieces=$filesize/$size
let remain=$filesize-$pieces*$size
if [ $remain -gt 0 ]; then
let pieces=$pieces+1
fi
echo pieces: $pieces

i=0
while [ $i -lt $pieces ];
do
echo split: $file.$i:
dd if=$file of=$file.$i bs=$size count=1 skip=$i
let i=$i+1
done

echo “#!/bin/bash” > merge

echo “i=0” >> merge
echo “while [ $i -lt $pieces ];” >> merge
echo “do” >> merge
echo ” echo merge: $file.$i” >> merge
echo ” if [ ! -f $file.$i ]; then” >> merge
echo ” echo merge: $file.$i missed” >> merge
echo ” rm -f $file.merged” >> merge
echo ” exit” >> merge
echo ” fi” >> merge
echo ” dd if=$file.$i of=$file.merged bs=$size count=1 seek=$i” >>
merge
echo ” let i=$i+1″ >> merge
echo “done” >> merge
chmod u+x merge’

3一.文本轻松加密

23、 模拟DOS 的 tree

!/bin/bash

find . -print | sed -e ‘s;[^/]*/;|____;g;s;____|; |;g’ 

make test && make strings && sudo make install

shc -r -f %%1.sh

24、运转多少个本子

%%1.x

find /var/scripts -name ‘backup*’ -exec {} ‘;’ 

%%1.x.c

3二.文本简单解密

二5、列出用户目录下全体钦点格式后缀的文本,然后移除文件后缀

!/bin/bash

find /home -print -exec rename -v ‘s/_2009-09-04.suffix$//’ {} \; 

make test && make strings && sudo make install

shc -r -f %%1.sh

26、计算钦命扩大名的有着文件的总大小,单位为MB

%%1.x

find . -type f -iname ‘*.msh’ -exec ls -lG {} \; | awk ‘{total = total

%%1.x.c

3叁.读取ini文件属性

  • $4}END{print “scale=2;” total “/2^20”}’ | bc 

!/bin/bash

if [ “$%%3” = “” ];then
sed -n “/[$%%2]/,/[.]/{
/^[.
]/d
/^[ ]$/d
s/;.
$//
p
}” $1
elif [ “$%%4” = “” ];then
sed -n “/[$%%2]/,/[.]/{
/^[.
]/d
/^[ ]$/d
s/;.
$//
s/^[ | ]$%%3[ | ]=[ | ](.)[ | ]/\1/p
}” $1
else
if [ “$%%4” = “#” ];then
sed “/[$%%2]/,/[.
]/{
s/^[ | ]$%%3[ | ]=./ /
}p” $1 > /tmp/sed$$
mv /tmp/sed$$ $1
else
sed “/[$2]/,/[.
]/{
s/^[ | ]$%%3[ | ]=.*/$%%3=$%%4/
}p” $1 > /tmp/sed$$
mv /tmp/sed$$ $%%1
fi
fi

3肆.合并三个文本下具备的文本

二七、修改当前目录中保有目录的权杖

!/bin/sh

cat $(ls |grep -E ‘%%1.’) > %%1

find ./ -type d | xargs sudo chmod 755 

!/bin/bash

OLDIFS=$IFS
IFS=:
for path in $( find %%1 -type d -printf “%p$IFS”)
do
for file in $path/.c $path/.cpp
do
if [[ ! “$file” =~ *.[A-Za-z]+ ]]; then

28、总括代码行数,再次回到总和

“$(path)/$(file)”

fi
done
done
IFS=$OLDIFS

find . \( -iname ‘*.cpp’ -o -iname ‘*.h’ \) -exec wc -l {} \; |
sort -n | cut –delimiter=.  -f 1 | awk ‘{s+=$1} END {print s}’ 

!/bin/bash

cat <<‘EOF’> combine.c

2九、递归的在当前目录中具有的c++文件中找找

include<stdio.h>

int main()
{
FILE f1,f2,f3;
f1=fopen(“a1.txt”,”r”);
f2=fopen(“a2.txt”,”r”);
f3=fopen(“a3.txt”,”w”);
int a,b;
a=getw(f1); /
从a一.txt和a2.txt中分别取最小的数a和b/
b=getw(f2);
while(!feof(f1)&&!feof(f2)) /
五个文件都没完工作时间,施行循环、相比较/
{
if(a<=b)
{
putw(a,f3);
a=getw(f1);
}
else
{putw(b,f3);
b=getw(f2);
}
}
if(feof(f1)) /
文件a一.txt甘休时,把a2.txt中的数方方面面输入a3.txt/
{putw(b,f3);
while((b=getw(f2))!=EOF)
putw(b,f3);
}
if(feof(f2)) /
同上*/
{
putw(a,f3);
while((a=getw(f1))!=EOF)
putw(a,f3);
}
fclose(f1);
fclose(f2);
fclose(f3);
printf(“已完成!”);
return 0;
}
EOF
gcc -o combine combine.c
if [ $? -eq 0 ]; then
./combine
else
echo ‘Compile ERROR’
fi

3五.写入ini文件属性

find . -name ‘*.?pp’ | xargs grep -H “string” 

!/bin/bash

if [ “$%%3” = “” ];then
sed -n “/[$%%2]/,/[.]/{
/^[.
]/d
/^[ ]$/d
s/;.
$//
p
}” $1
elif [ “$%%4” = “” ];then
sed -n “/[$%%2]/,/[.]/{
/^[.
]/d
/^[ ]$/d
s/;.
$//
s/^[ | ]$%%3[ | ]=[ | ](.)[ | ]/\1/p
}” $1
else
if [ “$%%4” = “#” ];then
sed “/[$%%2]/,/[.
]/{
s/^[ | ]$%%3[ | ]=./ /
}p” $1 > /tmp/sed$$
mv /tmp/sed$$ $%%1
else
sed “/[$%%2]/,/[.
]/{
s/^[ | ]$%%3[ | ]=.*/$%%3=$%%4/
}p” $1 > /tmp/sed$$
mv /tmp/sed$$ $%%1
fi
fi

3六.拿走当前路径

30、递归的打字与印刷职业目录内的全部硬链接

!/bin/sh

%%1=$(pwd)

37.读取XML数据库

怎么样通过shell命令行读取xml文件中有个别属性所对应的值?
例如:
<key>BuildVersion</key> <string>5</string>
本人期望能够通过Unix
shell命令对属性键的名称BuildVersion举办询问,再次回到的结果是5,怎样贯彻啊?

find . -type f -a \! -links 1 

!/bin/bash

grep BuildVersion|sed ‘s/.<.>([^<].)<.>.*/\1/’

结果重返的是“BuildVersion”,而不是“伍”,倘诺要查询BuildVersion自动回到数值伍应有怎么样写?

有道是科学的。试一下: echo “<key>BuildVersion</key>
<string>伍</string>”|grep BuildVersion|sed
‘s/.<.>([^<].)<.>.*/\1/’本人在SL的顶点里试,再次来到值是伍

近日内需从xml文件提取数额,想做一个xmlparser.sh
xml 类似那样
<result>
<shareinfo hostip=”192.168.0.1″ sharename=”abcd”
password=”abc123″></shareinfo>
</result>

可望输入 xmlparser.sh a.xml hostip能够再次回到192.16八.0.壹

3一、制作3个zip压缩包,将.svn目录排除在

!/bin/sh

if [ $# -ne 2 ];then
echo “Usage: $0 <xmlfile> <key>”
exit 0
fi

grep $2 $1|awk ‘{print $2}’|grep -o “[0-9.]*”


grep $2 $1|awk ‘{print $2}’|grep -o “[0-9.]*”
改成
grep $2 $1|awk ‘{print $2}’|grep -Eo “[0-9.]+”
楼上这么些有标题,即使自己要得到的是
<result>
<shareinfo hostip=”192.168.0.1″ sharename=”abcd”
password=”abc123″></shareinfo>
</result>
中的sharename,那么,呵呵,就错了

本身以为应该先固定到第3个参数“$贰”的职分,然后再领取“=”后边的原委

此间有个总体的贯彻:
Parse Simple XML Files using Bash – Extract Name Value Pairs and
Attributes
http://www.humbug.in/2010/parse-simple-xml-files-using-bash-extract-name-value-pairs-and-attributes/

唯独须求安装xmllint.

设计到对多少个xml文件举行element的读取和列表。有人做过么?
举例,
三个xml文件之中都有
<article>
<title>xxx</titlel>
</article>

透过shell读取,然后合并到叁头,再生成八个新的xml,不过其余因素不改变。
<article>
<title>aaa</titlel>
</article>
<article>
<title>bbb</titlel>
</article>

一旦格式万分轻松,没有特例,那么能够用shell实现
假诺有望格式复杂,因为shell的授命所使用的正则表明式都不协理跨行相称,所以用shell来消除那些标题就绕圈子了。
用perl来作这些工作最直接、简单。perl的XML:DOM模块是非常管理XML文件的。

偶倒是以为,用PHP写Scripts也很有益,效用庞大,而且,跨平台,

find . -not \( -name .svn -prune \) -type f | xargs zip XXXXX.zip 

!/bin/sh

sed -n ‘/<article>/{

N;

/\n[[:space:]]*<title>/{

N;

/<article>.*<\/article>/p

}

D;

n

}’

那小段代码能把二个xml文件中,你要的东西拿出来.
您能够用for file in $*把那一个音信都>>tmpfile中.
然后用sed 在钦定文件的钦赐地点用r命令把tmpfile粘贴进来~~~~

大思路如此\_
小编想有那么些东西(只要能科学的跑出结果)后面就轻便了吧…

Name
xmllint — command line XML tool

Synopsis
xmllint [[–version] | [–debug] | [–shell] | [–debugent] |
[–copy] | [–recover] | [–noent] | [–noout] | [–nonet] |
[–htmlout] | [–nowrap] | [–valid] | [–postvalid] |
[–dtdvalid URL] | [–dtdvalidfpi FPI] | [–timing] | [–output
file] | [–repeat] | [–insert] | [–compress] | [–html] |
[–xmlout] | [–push] | [–memory] | [–maxmem nbbytes] |
[–nowarning] | [–noblanks] | [–nocdata] | [–format] |
[–encode encoding] | [–dropdtd] | [–nsclean] | [–testIO] |
[–catalogs] | [–nocatalogs] | [–auto] | [–xinclude] |
[–noxincludenode] | [–loaddtd] | [–dtdattr] | [–stream] |
[–walker] | [–pattern patternvalue] | [–chkregister] |
[–relaxng] | [–schema] | [–c14n]] [xmlfile]

Introduction
The xmllint program parses one or more XML files, specified on the
command line as xmlfile. It prints various types of output, depending
upon the options selected. It is useful for detecting errors both in XML
code and in the XML parser itself.

It is included in libxml2.

Options
–version
Display the version of libxml2 used.
–debug
Parse a file and output an annotated tree of the in-memory version of
the document.
–shell
Run a navigating shell. Details on available commands in shell mode are
below.
–debugent
Debug the entities defined in the document.
–copy
Test the internal copy implementation.
–recover
Output any parsable portions of an invalid document.
–noent
Substitute entity values for entity references. By default, xmllint
leaves entity references in place.
–nocdata
Substitute CDATA section by equivalent text nodes.
–nsclean
Remove redundant namespace declarations.
–noout
Suppress output. By default, xmllint outputs the result tree.
–htmlout
Output results as an HTML file. This causes xmllint to output the
necessary HTML tags surrounding the result tree output so the results
can be displayed in a browser.
–nowrap
Do not output HTML doc wrapper.
–valid
Determine if the document is a valid instance of the included Document
Type Definition (DTD). A DTD to be validated against also can be
specified at the command line using the –dtdvalid option. By default,
xmllint also checks to determine if the document is well-formed.
–postvalid
Validate after parsing is completed.
–dtdvalid URL
Use the DTD specified by URL for validation.
–dtdvalidfpi FPI
Use the DTD specified by the Public Identifier FPI for validation, note
that this will require a Catalog exporting that Public Identifier to
work.
–timing
Output information about the time it takes xmllint to perform the
various steps.
–output file
Define a file path where xmllint will save the result of parsing.
Usually the programs build a tree and save it on stdout, with this
option the result XML instance will be saved onto a file.
–repeat
Repeat 100 times, for timing or profiling.
–insert
Test for valid insertions.
–compress
Turn on gzip compression of output.
–html
Use the HTML parser.
–xmlout
Used in conjunction with –html. Usually when HTML is parsed the
document is saved with the HTML serializer, but with this option the
resulting document is saved with the XML serializer. This is primarily
used to generate XHTML from HTML input.
–push
Use the push mode of the parser.
–memory
Parse from memory.
–maxmem nnbytes
Test the parser memory support. nnbytes is the maximum number of bytes
the library is allowed to allocate. This can also be used to make sure
batch processing of XML files will not exhaust the virtual memory of the
server running them.
–nowarning
Do not emit warnings from the parser and/or validator.
–noblanks
Drop ignorable blank spaces.
–format
Reformat and reindent the output. The $XMLLINT_INDENT environment
variable controls the indentation (default value is two spaces ” “).
–testIO
Test user input/output support.
–encode encoding
澳门金沙国际 ,Output in the given encoding.
–catalogs
Use the catalogs from $SGML_CATALOG_FILES. Otherwise /etc/xml/catalog
is used by default.
–nocatalogs
Do not use any catalogs.
–auto
Generate a small document for testing purposes.
–xinclude
Do XInclude processing.
–noxincludenode
Do XInclude processing but do not generate XInclude start and end
nodes.
–loaddtd
Fetch external DTD.
–dtdattr
Fetch external DTD and populate the tree with inherited attributes.
–dropdtd
Remove DTD from output.
–stream
Use streaming API – useful when used in combination with –relaxng or
–valid options for validation of files that are too large to be held in
memory.
–walker
Test the walker module, which is a reader interface but for a document
tree, instead of using the reader API on an unparsed document it works
on a existing in-memory tree. Used in debugging.
–chkregister
Turn on node registration. Useful for developers testing libxml2 node
tracking code.
–pattern patternvalue
Used to exercise the pattern recognition engine, which can be used with
the reader interface to the parser. It allows to select some nodes in
the document based on an XPath (subset) expression. Used for
debugging.
–relaxng schema
Use RelaxNG file named schema for validation.
–schema schema
Use a W3C XML Schema file named schema for validation.
–c14n
Use the W3C XML Canonicalisation (C14N) to serialize the result of
parsing to stdout. It keeps comments in the result.
Shell
xmllint offers an interactive shell mode invoked with the –shell
command. Available commands in shell mode include:

base
display XML base of the node
bye
leave shell
cat node
Display node if given or current node.
cd path
Change the current node to path (if given and unique) or root if no
argument given.
dir path
Dumps information about the node (namespace, attributes, content).
du path
Show the structure of the subtree under path or the current node.
exit
Leave the shell.
help
Show this help.
free
Display memory usage.
load name
Load a new document with the given name.
ls path
List contents of path (if given) or the current directory.
pwd
Display the path to the current node.
quit
Leave the shell.
save name
Saves the current document to name if given or to the original name.
validate
Check the document for error.
write name
Write the current node to the given filename.
Catalogs
Catalog behavior can be changed by redirecting queries to the user’s own
set of catalogs. This can be done by setting the XML_CATALOG_FILES
environment variable to a list of catalogs. An empty one should
deactivate loading the default /etc/xml/catalog default catalog.

Debugging Catalogs
Setting the environment variable XML_DEBUG_CATALOG using the command
“export XML_DEBUG_CATALOG=” outputs debugging information related to
catalog operations.

Error Return Codes
On the completion of execution, Xmllint returns the following error
codes:

0
No error
1
Unclassified
2
Error in DTD
3
Validation error
4
Validation error
5
Error in schema compilation
6
Error writing output
7
Error in pattern (generated when [–pattern] option is used)
8
Error in Reader registration (generated when [–chkregister] option is
used)
9
Out of memory error

Parse Simple XML Files using Bash – Extract Name Value Pairs and
Attributes

2 Comments
1
Tweet

Pratik Sinha | July 31, 2010

I have written up a simple routine parML to parse simple XML files to
extract unique name values pairs and their attributes. The script
extracts all xml tags of the format <abc
arg1=”hello”>xyz</abc> and dynamically creates bash variables
which hold values of the attributes as well as the elements. This is a
good solution, if you don’t wish to use xpath for some simple xml files.
However you will need xmllint installed on your system to use the
script. Here’s a sample script which uses the par
ML function

32、递归给.sh加权限

!/bin/bash

xmlFile=$1

function par**ML() {
elemList=( $(cat $xmlFile | tr ‘\n’ ‘ ‘ | XMLLINT_INDENT=”” xmllint
–format – | /bin/grep -e “</.
>$” | while read line; do
echo $line | sed -e ‘s/^.*<///’ | cut -d ‘>’ -f 1;
done) )

totalNoOfTags=${#elemList[@]}; ((totalNoOfTags–))
suffix=$(echo ${elemList[$totalNoOfTags]} | tr -d ‘</>’)
suffix=”${suffix}_”

for (( i = 0 ; i < ${#elemList[@]} ; i++ )); do
elem=${elemList[$i]}
elemLine=$(cat $xmlFile | tr ‘\n’ ‘ ‘ | XMLLINT_INDENT=”” xmllint
–format – | /bin/grep “</$elem>”)
echo $elemLine | grep -e “</\[ ]>$” 1>/dev/null
2>&1
if [ “0” = “$?” ]; then
continue
fi
elemVal=$(echo $elemLine | tr ‘\011’ ‘\040’| sed -e ‘s/^[ ]
//’ -e
‘s/<.\*>(\[<].)<.>$/\1/’ | sed -e ‘s/^[
]//’ | sed -e ‘s/[ ]$//’)
xmlElem=”${suffix}$(echo $elem | sed ‘s/-/_/g’)”
eval ${xmlElem}=echo -ne \""${elemVal}"\"
attrList=($(cat $xmlFile | tr ‘\n’ ‘ ‘ | XMLLINT_INDENT=”” xmllint
–format – | /bin/grep “</$elem>” | tr ‘\011’ ‘\040’ | sed -e
‘s/^[ ]//’ | cut -d ‘>’ -f 1 | sed -e ‘s/<\[ ]//’
| tr “‘” ‘”‘ | tr ‘”‘ ‘\n’ | tr ‘=’ ‘\n’ | sed -e ‘s/^[ ]*//’ | sed
‘/^$/d’ | tr ‘\011’ ‘\040’ | tr ‘ ‘ ‘>’))
for (( j = 0 ; j < ${#attrList[@]} ; j++ )); do
attr=${attrList[$j]}
((j++))
attrVal=$(echo ${attrList[$j]} | tr ‘>’ ‘ ‘)
attrName=echo -ne ${xmlElem}_${attr}
eval ${attrName}=echo -ne \""${attrVal}"\"
done
done
}

par***ML
echo “$status_xyz | $status_abc | $status_pqr” #Variables for each
XML ELement
echo “$status_xyz_arg1 | $status_abc_arg2 | $status_pqr_arg3 |
$status_pqr_arg4” #Variables for each XML Attribute
echo “”

find ./ -name “*.sh” -exec chmod +x {} \; 

All the variables that were produced by the par***ML function

set | /bin/grep -e “^$suffix”

The XML File used for the above script example is:
<?xml version=”1.0″?>
<status>
<xyz arg1=”1″> a </xyz>
<abc arg2=”2″> p </abc>
<pqr arg3=”3″ arg4=”a phrase”> x </pqr>
</status>

The root tag, which in this case is “status”, is used as a suffix for
all variables. Once the XML file is passed to the function, it
dynamically creates the variables $status_xyz, $status_abc,
$status_pqr, $status_xyz_arg1, $status_abc_arg2, $status_pqr_arg3
and $status_pqr_arg4.

The output when the script is ran with the xml file as an argument is
@$ bash par***ML.sh
test.xml
a | p | x
1 | 2 | 3 | a phrase

status_abc=p
status_abc_arg2=2
status_pqr=x
status_pqr_arg3=3
status_pqr_arg4=’a phrase’
status_xyz=a
status_xyz_arg1=1

This script won’t work for XML files like the one below with duplicate
element names.
<?xml version=”1.0″?>
<status>
<test arg1=”1″> a </test>
<test arg2=”2″> p </test>
<test arg3=”3″ arg4=”a phrase”> x </test>
</status>

This script also won’t be able to extract attributes of elements without
any CDATA. For eg, the script won’t be able to create variables
corresponding to <test arg1=”1″>. It will only create the
variables corresponding to <test1 arg2=”2″>abc</test1>.
<?xml version=”1.0″?>
<status>
<test arg1=”1″>
<test1 arg2=”2″>abc</test1>
</test>
</status>

38.写入XML数据库

33、显示排种类表文件的轻重抢先1MB的当前目录

!/bin/bash

3玖.ZIP压缩文件

find . -maxdepth 1 -type f -size +1M -printf “%f:%s\n” | sort -t”:”
-k2 

!/bin/sh

zip -r “/%%1” “%%2”

40.ZIP解压缩

34、使用file查看设备音讯(man file查看越来越多关于file的音讯)

!/bin/sh

unzip -x “/%%1” “%%2”

四壹.赢得应用程序完整路线

file -s /dev/sd* 

!/bin/bash

4二.ZIP压缩文件夹

3伍、搜索超越设置尺寸的具有文件同时按设置的格式展现

!/bin/bash

四3.递归删除目录下的文本

find / -type f -size +512000 | xargs ls -lh | awk ‘{ print $5 ” ” $6$7
“: ” $9 }’ 

!/bin/bash

rm -if “%%1/
OLDIFS=$IFS
IFS=:
for path in $( find %%1 -type d -printf “%p$IFS”)
do
for file in $path/
.c $path/*.cpp
do
if [[ ! “$file” =~ *.[A-Za-z]+ ]]; then

3陆、批量编码调换

“$(path)/$(file)”

fi
done
done
IFS=$OLDIFS

44.IDEA加密算法

find . -iname *.java -type f -exec bash -c “iconv -f GBK -t UTF-8 {} 
> {}.tmp ” \; -exec mv {}.tmp {} \;

!/bin/bash

45.RC6算法

37、清理 ._ 文件 (OS X)

!/bin/bash

cat <<‘EOF’> rc6.c

find . -name ._\* -exec rm -f {} \; 

include<stdio.h>

/* Timing data for RC6 (rc6.c)

128 bit key:
Key Setup: 1632 cycles
Encrypt: 270 cycles = 94.8 mbits/sec
Decrypt: 226 cycles = 113.3 mbits/sec
Mean: 248 cycles = 103.2 mbits/sec

192 bit key:
Key Setup: 1885 cycles
Encrypt: 267 cycles = 95.9 mbits/sec
Decrypt: 235 cycles = 108.9 mbits/sec
Mean: 251 cycles = 102.0 mbits/sec

256 bit key:
Key Setup: 1877 cycles
Encrypt: 270 cycles = 94.8 mbits/sec
Decrypt: 227 cycles = 112.8 mbits/sec
Mean: 249 cycles = 103.0 mbits/sec

*/

3八、选用性的grep

include “../std_defs.h”

static char *alg_name[] = { “rc6”, “rc6.c”, “rc6” };

char **cipher_name()
{
return alg_name;
}

find /path -name \*.php -user nobody -exec grep -nH whatever {} \;
grep selectively 

define f_rnd(i,a,b,c,d) \

    u = rotl(d * (d + d + 1), 5);       \
    t = rotl(b * (b + b + 1), 5);       \
    a = rotl(a ^ t, u) + l_key;      \
    c = rotl(c ^ u, t) + l_key[i + 1]

3九、搜索文件同时根据修改时间排序

define i_rnd(i,a,b,c,d) \

    u = rotl(d * (d + d + 1), 5);       \
    t = rotl(b * (b + b + 1), 5);       \
    c = rotr(c - l_key[i + 1], t) ^ u;  \
    a = rotr(a - l_key, u) ^ t

u4byte l_key[44]; /* storage for the key schedule */

/* initialise the key schedule from the user supplied key */

u4byte *set_key(const u4byte in_key[], const u4byte key_len)
{ u4byte i, j, k, a, b, l[8], t;

l_key[0] = 0xb7e15163;

for(k = 1; k < 44; ++k)

    l_key[k] = l_key[k - 1] + 0x9e3779b9;

for(k = 0; k < key_len / 32; ++k)

    l[k] = in_key[k];

t = (key_len / 32) - 1; // t = (key_len / 32);

a = b = i = j = 0;

for(k = 0; k < 132; ++k)
{   a = rotl(l_key + a + b, 3); b += a;
    b = rotl(l[j] + b, b);
    l_key = a; l[j] = b;
    i = (i == 43 ? 0 : i + 1); // i = (i + 1) % 44; 
    j = (j == t ? 0 : j + 1);  // j = (j + 1) % t;
}

return l_key;

};

/* encrypt a block of text */

void encrypt(const u4byte in_blk[4], u4byte out_blk[4])
{ u4byte a,b,c,d,t,u;

a = in_blk[0]; b = in_blk[1] + l_key[0];
c = in_blk[2]; d = in_blk[3] + l_key[1];

f_rnd( 2,a,b,c,d); f_rnd( 4,b,c,d,a);
f_rnd( 6,c,d,a,b); f_rnd( 8,d,a,b,c);
f_rnd(10,a,b,c,d); f_rnd(12,b,c,d,a);
f_rnd(14,c,d,a,b); f_rnd(16,d,a,b,c);
f_rnd(18,a,b,c,d); f_rnd(20,b,c,d,a);
f_rnd(22,c,d,a,b); f_rnd(24,d,a,b,c);
f_rnd(26,a,b,c,d); f_rnd(28,b,c,d,a);
f_rnd(30,c,d,a,b); f_rnd(32,d,a,b,c);
f_rnd(34,a,b,c,d); f_rnd(36,b,c,d,a);
f_rnd(38,c,d,a,b); f_rnd(40,d,a,b,c);

out_blk[0] = a + l_key[42]; out_blk[1] = b;
out_blk[2] = c + l_key[43]; out_blk[3] = d;

};

/* decrypt a block of text */

void decrypt(const u4byte in_blk[4], u4byte out_blk[4])
{ u4byte a,b,c,d,t,u;

d = in_blk[3]; c = in_blk[2] - l_key[43];
b = in_blk[1]; a = in_blk[0] - l_key[42];

i_rnd(40,d,a,b,c); i_rnd(38,c,d,a,b);
i_rnd(36,b,c,d,a); i_rnd(34,a,b,c,d);
i_rnd(32,d,a,b,c); i_rnd(30,c,d,a,b);
i_rnd(28,b,c,d,a); i_rnd(26,a,b,c,d);
i_rnd(24,d,a,b,c); i_rnd(22,c,d,a,b);
i_rnd(20,b,c,d,a); i_rnd(18,a,b,c,d);
i_rnd(16,d,a,b,c); i_rnd(14,c,d,a,b);
i_rnd(12,b,c,d,a); i_rnd(10,a,b,c,d);
i_rnd( 8,d,a,b,c); i_rnd( 6,c,d,a,b);
i_rnd( 4,b,c,d,a); i_rnd( 2,a,b,c,d);

out_blk[3] = d - l_key[1]; out_blk[2] = c;
out_blk[1] = b - l_key[0]; out_blk[0] = a;

};
int main()
{

return 0;
}
EOF
gcc -o rc6 rc6.c
if [ $? -eq 0 ]; then
./combine
else
echo ‘Compile ERROR’
fi

46.Grep

find -type f | xargs ls -1tr 

!/bin/bash

grep -qE %%1 %%2

四七.从来开立多级目录

!/bin/bash

mkdir -p %%1

4八.批量重命名

!/bin/bash

find $PWD -type f -name ‘*.cpp’ |sed s/’.cpp’//g|awk ‘{MV = “mv”};{C =
“.c”};{ CPP=”.cpp”}; {print MV, $1 CPP , $1 C}’|sh
ls | awk -F ‘-‘ ‘{print “mv “$0” “$2}’ #去掉带’-‘的前缀

4玖.文本查找替换

!/bin/bash

sed -e ‘s:%%2:%%3:g’ %%1

sed -e ‘s/%%2/%%3/g’ %%1

50.文书涉及

!/bin/bash

5一.批量转移编码从GB2312到Unicode

!/bin/bash

scode=”gbk”
dcode=”ucs2″
for FILE in $(find $(pwd) -type f)
do
TMP_file=$(mktemp -p $(pwd))
if [ -f $FILE ]; then
Fright=$(stat -c %a $FILE)
Fuser=$(stat -c %U $FILE)
Fgrp=$(stat -c %G $FILE)
iconv -f $scode -t $dcode $FILE -o $TMP_file
mv $TMP_file $FILE
chmod $Fright $FILE
chown $Fuser.$Fgrp $FILE
fi
done

52.设置JDK情形变量

!/bin/bash

find “$PWD” -type f ( -iname ‘.bin’ ) -print0 | xargs -0 chmod +x
find -type f ( -iname ‘
.bin’ ) -print |
while read filename
do
case “$filename” in
.bin)
xterm -e “$filename” && rm -if “$filename”
;;
esac
done
OLDIFS=$IFS
IFS=$’\n’
for line in cat ~/.bashrc
do
if [[ “$line” =~ .
export.* ]]; then
if [[ “$line” =~ .JAVA_HOME=. ]]; then
if [[ “$line” =~ =(/([0-9a-zA-Z._]+))+ ]]; then
javahome=$line
fi
fi
fi
if [[ “$line” =~ export\
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin$ ]];then
javapath=$line
fi
if [[ “$line” =~ export\
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib$ ]];then
classpath=$line
fi
done
if [ ! -n “$javahome” ]; then
sed -i ‘$a export JAVA_HOME=’$(pwd)’/jdk1.6.0_25’ ~/.bashrc
else
sed -i ‘s:’${javahome//\/\\}’:export
JAVA_HOME=’$(pwd)’/jdk1.6.0_32:g’ ~/.bashrc
fi
if [ ! -n “$javapath” ]; then
sed -i ‘$a export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin’
~/.bashrc
fi
if [ ! -n “$classpath” ]; then
sed -i ‘$a export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib’
~/.bashrc
fi
IFS=$OLDIFS

!/bin/bash

shift
OLDIFS=$IFS
IFS=$’\n’
for line in cat ~/TestBash.txt #~/.bashrc
do
if [[ “$line” =~ .export. ]]; then
if [[ “$line” =~ export\
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib$ ]]; then
classpath=$line
elif [[ “$line” =~ export\ PATH=$PATH:$CATALINA_HOME/bin$ ]];
then
jbosspath=$line
fi
if [[ “$line” =~ .JAVA_HOME=. ]]; then
if [[ “$line” =~ =(/([0-9a-zA-Z.]+))+ ]];then
javahome=$line
fi
elif [[ “$line” =~ .
CATALINA_HOME=. ]];then
if [[ “$line” =~ =(/([0-9a-zA-Z.
]+))+ ]];then
catalinahome=$line
fi
elif [[ “$line” =~ .TOMCAT_HOME=. ]];then
if [[ “$line” =~ =(/([0-9a-zA-Z.]+))+ ]];then
tomcathome=$line
fi
elif [[ “$line” =~ .
CATALINA_BASE=. ]];then
if [[ “$line” =~ =(/([0-9a-zA-Z.
]+))+ ]];then
catalinabase=$line
fi
elif [[ “$line” =~ .JBOSS_HOME=. ]];then
if [[ “$line” =~ =(/([0-9a-zA-Z._]+))+ ]];then
jbosshome=$line
fi
fi
elif [[ “$line” =~ ^PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin$
]];then
javapath=$line
fi
if [[ “$line” =~ export\
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib$ ]];then
classpath=$line
fi
if [[ “$line” =~ export\ PATH=$PATH:$JBOSS_HOME/bin$ ]];then
jbosspath=$line
fi
done
if [ ! -n “$javahome” ]; then
sed -i ‘$a export JAVA_HOME=’$(pwd)’/jdk1.6.0_24’ ~/TestBash.txt
#~/.bashrc
else
sed -i ‘s:’${javahome//\/\\}’:export
JAVA_HOME=’$(pwd)’/jdk1.6.0_24:g’ ~/TestBash.txt
fi
if [ ! -n “$javapath” ]; then
sed -i ‘$a PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin’
~/TestBash.txt #~/.bashrc
fi
if [ ! -n “$classpath” ]; then
sed -i ‘$a export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib’
~/TestBash.txt #~/.bashrc
fi
if [ ! -n “$catalinahome” ]; then
sed -i ‘$a export CATALINA_HOME=’$(pwd) ~/TestBash.txt #~/.bashrc
else
sed -i ‘s:’${catalinahome//\/\\}’:export CATALINA_HOME=’$(pwd)’:g’
~/TestBash.txt
fi
if [ ! -n “$tomcathome” ]; then
sed -i ‘$a export TOMCAT_HOME=’$(pwd) ~/TestBash.txt #~/.bashrc
else
sed -i ‘s:’${tomcathome//\/\\}’:export TOMCAT_HOME=’$(pwd)’:g’
~/TestBash.txt
fi
if [ ! -n “$catalinabase” ]; then
sed -i ‘$a export CATALINA_BASE=’$(pwd) ~/TestBash.txt #~/.bashrc
else
sed -i ‘s:’${catalinabase//\/\\}’:export CATALINA_BASE=’$(pwd)’:g’
~/TestBash.txt
fi
if [ ! -n “$jbosshome” ]; then
sed -i ‘$a export JBOSS_HOME=’$(pwd) ~/TestBash.txt #~/.bashrc
else
sed -i ‘s:’${jbosshome//\/\\}’:export JBOSS_HOME=’$(pwd)’:g’
~/TestBash.txt
fi
if [ ! -n “$jbosspath” ]; then
sed -i ‘$a export PATH=$PATH:$CATALINA_HOME/bin’ ~/TestBash.txt
#~/.bashrc
fi
IFS=$OLDIFS

五3.批量改变编码从Unicode到GB2312

!/bin/bash

scode=”ucs2″
dcode=”gbk”
for FILE in $(find $(pwd) -type f)
do
TMP_file=$(mktemp -p $(pwd))
if [ -f $FILE ]; then
Fright=$(stat -c %a $FILE)
Fuser=$(stat -c %U $FILE)
Fgrp=$(stat -c %G $FILE)
iconv -f $scode -t $dcode $FILE -o $TMP_file
mv $TMP_file $FILE
chmod $Fright $FILE
chown $Fuser.$Fgrp $FILE
fi
done

5四.删除空文件夹

!/bin/bash

rmdir -p %%1

55.GB2312文件转UTF-8格式

!/bin/bash

iconv -f gbk -t utf8 %%1 -o %%2

56.UTF-8文件转GB2312格式

!/bin/bash

iconv -f utf8 -t gbk %%1 -o %%2

五七.赢得文件路线的父路线

!/bin/bash

%%1=basename $PWD

58.Unicode文件转UTF-8格式

!/bin/bash

iconv -f ucs2 -t utf-8 %%1 -o %%2

59.C奥迪Q7C循环冗余校验

!/bin/bash

cat <<‘EOF’> crc.c

include<stdio.h>

unsigned long int crc32_table[256];

unsigned long int ulPolynomial = 0x04c11db7;

unsigned long int Reflect(unsigned long int ref, char ch)

{ unsigned long int value(0);

    // 交换bit0和bit7,bit1和bit6,类推 

    for(int i = 1; i < (ch + 1); i++) 

     {            if(ref & 1) 

                  value |= 1 << (ch - i); 

               ref >>= 1;      } 

    return value; 

}

init_crc32_table()

{ unsigned long int crc,temp;

    // 256个值 

    for(int i = 0; i <= 0xFF; i++) 

     {   temp=Reflect(i, 8); 

           crc32_table[i]= temp<< 24; 

            for (int j = 0; j < 8; j++){ 

         unsigned long int t1,t2; 

unsigned long int flag=crc32_table[i]&0x80000000;

            t1=(crc32_table[i] << 1); 

            if(flag==0) 

              t2=0; 

            else 

              t2=ulPolynomial; 

            crc32_table[i] =t1^t2 ;        } 

           crc=crc32_table[i]; 

           crc32_table[i] = Reflect(crc32_table[i], 32); 
    }

}
unsigned long GenerateCRC32(char xdata * DataBuf,unsigned long len)

{

    unsigned long oldcrc32; 

    unsigned long crc32; 

    unsigned long oldcrc; 

    unsigned  int charcnt; 

     char c,t; 

    oldcrc32 = 0x00000000; //初值为0 

 charcnt=0; 

     while (len--) { 

             t= (oldcrc32 >> 24) & 0xFF;   //要移出的字节的值 

 oldcrc=crc_32_tab[t];         //根据移出的字节的值查表 

             c=DataBuf[charcnt];          //新移进来的字节值 

             oldcrc32= (oldcrc32 << 8) | c;   //将新移进来的字节值添在寄存器末字节中 

             oldcrc32=oldcrc32^oldcrc;     //将寄存器与查出的值进行xor运算 

             charcnt++; 

    } 

     crc32=oldcrc32; 

     return crc32; 

}

参数表能够先在PC机上算出来,也可在先后开始化时做到。上面是用以计算参数表的c语言子程序,在Visual
C++ 6.0下编写翻译通过。

include <stdio.h>

unsigned long int crc32_table[256];

unsigned long int ulPolynomial = 0x04c11db7;

unsigned long int Reflect(unsigned long int ref, char ch)

{ unsigned long int value(0);

    // 交换bit0和bit7,bit1和bit6,类推 

    for(int i = 1; i < (ch + 1); i++) 

     {            if(ref & 1) 

                  value |= 1 << (ch - i); 

               ref >>= 1;      } 

    return value; 

}
int main()
{
unsigned long int crc,temp;

    // 256个值 

    for(int i = 0; i <= 0xFF; i++) 

     {

temp=Reflect(i, 8);
crc32_table[i]= temp<< 24;

            for (int j = 0; j < 8; j++){ 

         unsigned long int t1,t2; 

unsigned long int flag=crc32_table[i]&0x80000000;
t1=(crc32_table[i] << 1);

            if(flag==0) 

              t2=0; 

            else 

              t2=ulPolynomial; 

            crc32_table[i] =t1^t2 ;       

}

           crc=crc32_table[i];
           crc32_table[i] = Reflect(crc32_table[i], 32);
    }

return 0;
}
EOF
gcc -o crc crc.c
if [ $? -eq 0 ]; then
./combine
else
echo ‘Compile ERROR’
fi

60.料定是还是不是为空文件

!/bin/bash

陆1.终止主次

!/bin/sh

kill -KILL pidof %%1 -s

killall %%1

6二.定期关机

!/bin/sh

shutdown -h %%1 & #23:00

shutdown -h now

halt

/sbin/poweroff

init 0

陆三.显得进度列表

!/bin/sh

ps aux

fuser -l

64.遍历文件夹列出文件大小

!/bin/sh

du -sH “%%1/*”

65.GOST算法

!/bin/bash

6陆.对目的压缩文件解压缩到钦定文件夹

!/bin/bash

67.保留文件时重名自动生成新文件

!/bin/bash

6八.开垦网页

!/bin/sh

lynx %%1

6九.删除空文件夹整合操作

!/bin/bash

70.到手磁盘全数分区

!/bin/sh

df -k

7壹.激活2个顺序或程序关联的文书

!/bin/bash

72.MP3播放

!/bin/sh

amp “%%1”

73.WAV播放

!/bin/sh

amp “%%1”

74.写图像到剪切板

!/bin/bash

7伍.从剪贴板复制图像到窗体

!/bin/bash

7陆.删减文件夹下的有所文件且不删除文件夹下的文件夹

!/bin/sh

rm -if “%%1/*”

77.XML遍历结点属性值

!/bin/bash

78.Unicode文件转GB2312格式

!/bin/sh

iconv -f ucs2 -t gbk %%1 -o %%2

7九.开源程序库Xercesc-C++代码工程中内联80.提取包涵头文件列表

!/bin/bash

81.GB2312文件转Unicode格式

!/bin/sh

iconv -f gbk -t ucs2 %%1 -o %%2

八二.Java程序打包

!/bin/bash

83.UTF-8文件转Unicode格式

!/bin/bash

iconv -f utf8 -t ucs2 %%1 -o %%2

84.创建PDF文档

!/bin/bash

85.创建Word文档

!/bin/bash

八陆.神速高效的文书加密

!/bin/bash

8七.从CSV文件构造XML文书档案

!/bin/bash

8八.从XML文书档案生成CSV文件

!/bin/bash

89.模拟键盘输入字符串

!/bin/bash

90.提取PDF文件中的文本

!/bin/bash

9一.操作内部存款和储蓄器映射文件

!/bin/bash

玖一.壹发送内部存款和储蓄器映射数据

!/bin/bash

九一.二接到内部存款和储蓄器映射数据

!/bin/bash

九二.重定向windows调节台程序的出口新闻

!/bin/bash

九三.基数转序数

!/bin/bash

9四.数字月份转英文

!/bin/bash

玖伍.表格相关

!/bin/bash

九六.依照进度名取得进度ID

!/bin/bash

pidof %%1 -s

96.BCP导入

!/bin/bash

97.BCP导出

!/bin/bash

九八.计算文件MD五值

!/bin/bash

md5sum “%%1”

9玖.计量获取文件夹中文件的MD5值

!/bin/bash

十0.复制二个索引下具有文件到一个文件夹中

!/bin/bash

cp $(find “%%1” -name .) “%%2”

101.平移二个索引下有所文件到三个文书夹中

!/bin/bash

mv $(find “%%1” -name .) “%%2”

十二.文件牧马人SA高等加密
10进制到十6进制
typeset -i16 BASE_16_NUM
BASE_16_NUM=%%1
echo $BASE_16_NUM

8进制到十6进制

!/bin/bash

typeset -i16 BASE_16_NUM
BASE_16_NUM=8#%%1
echo $BASE_16_NUM

十进制到8进制

!/bin/bash

printf %o %%1; echo

10进制到十陆进制

!/bin/bash

printf %x %%1; echo

103.计量文件大小

!/bin/bash

wc “%%1”

十肆.测算文件夹的尺寸

!/sbin/ksh

dir=%%1
(cd $dir;pwd)
find $dir -type d -print | du | awk ‘{print $2, “== (“$1/2″kb)”}’ |sort
-f |
sed -e “s,[^ /]/([^ /]) ==,|–1,” -e”s,[^ /]*/,| ,g”

拾5.飞速获得当前程序的驱动器、路线、文件名和扩充名

10陆.磁盘剩余空间总括

!/bin/bash

df -k

拾7.取稳当前先后进度ID

!/bin/bash

pidof %%1 -s

拾八.一心寻觅文件

!/bin/bash

updatedb

locate %%1

slocate %%1

10九.收获当前登陆的用户名

!/bin/bash

whoami

1十.拿走全数用户名

!/bin/bash

who

11壹.创设MySQL管理用户

!/bin/bash

mysqladmin -u root password %%1

11二.管制MySQL数据库服务器

!/bin/bash

11二.一.开发银行MySQL数据库服务器
mysqld -console

11二.二.登录MySQL数据库服务器
11二.2.一.登入地面MySQL数据库服务器
mysql -uroot -p%%1

11二.2.二.登6远程MySQL数据库服务器
mysql -h %%1 -u %%2 -p%%3

11贰.3.关闭MySQL数据库服务器
mysqladmin -u root shutdown

pkill -9 mysql

11二.4.测试MySQL数据库服务器
mysqlshow || mysqlshow -u root mysql || mysqladmin version status ||
mysql test

11三.MySQL实行查询

!/bin/sh

mysqladmin -u %%1 -p%%2 SELECT * INTO OUTFILE ‘./bestlovesky.xls’ FROM
bestlovesky WHERE 1 ORDER BY id DESC LIMIT 0, 50;

mysql -u %%1 -p%%2 -e “SELECT * INTO OUTFILE ‘./bestlovesky.xls’ FROM
bestlovesky WHERE 1 ORDER BY id DESC LIMIT 0, 50;”

114.创制Oracle管理用户

!/bin/sh

11四.1.成立新用户
create user test identified by test default tablespace ts_test
temporary
tablespace temp;

11四.二.给用户剧中人物特权
grant connect,resource to test;

115.登录Oracle数据库

!/bin/bash

sqlplusw
sqlplus /nolog
conn username/password@Oranet
conn system/systempwd@whfc
conn sys/syspwd@whfc as sysdba

115.创建Oracle表空间

!/bin/bash

conn system@whfc01
create tablespace ts_test datafile ‘/data2/oradata/ciis/ts_test01.dbf’
size

11六.增多Oracle数据文件

!/bin/bash

alter tablespace ts_test add datafile
‘/data2/oradata/ciis/ts_test02.dbf’ size

1一七.查看Oracle表空间尺寸

!/bin/bash

desc DBA_DATA_FILES

11捌.查看Oracle剩余表空间尺寸

!/bin/bash

desc DBA_FREE_SPACE

11玖.查看Oracle当前用户表名

!/bin/bash

select * from tab;

120.Oracle创设索引

!/bin/bash

CREATE INDEX idx_book_bookid ON book(bookname);

1二一.Oracle创设主键约束

!/bin/bash

ALTER TABLE book ADD CONSTRAINT pk_book_bookid PRIMARY KEY (bookid);

12二.Oracle显示表结构

!/bin/bash

desc book

1二3.Oracle查看表的目录

!/bin/bash

column index_name format a30
select table_name, index_name from user_indexes;

1二四.Oracle查看索引列

!/bin/bash

select table_name, index_name, column_name, column_position from
user_ind_columns;

1二伍.Oracle查看数据段占空间大小

!/bin/bash

desc user_segments

1二陆.Oracle查看表占空间大小

!/bin/bash

select segment_name,segment_type,bytes from user_segments where
segment_type=’TABLE’;

1二7.有惊无险删除USB

!/bin/bash

rundll32.exe shell32.dll,Control_RunDLL hotplug.dll

128.打开SQL Server Management Studio

!/bin/bash

sqlwb %%1.sql

12玖.MySQL数据库导出备份

!/bin/bash

mysqldump -u %%1 -p %%2 %%3>%%4.sql
mysqldump –opt test > mysql.test
//将数据库test导出到mysql.test文件,前面是二个文件文件
mysqldump -u root -p12345陆 –databases dbname > mysql.dbname
//正是把数据库dbname导出到文件mysql.dbname中。

130.MySQL数据库数据导入
mysql -u %%1 -p %%2 %%3<%%4.sql
mysqlimport -u root -p123456 < mysql.dbname
将文件数据导入数据库:
文本数据的字段之间用tab键隔离
use test
load data local infile “文件名” into table 表名;
eg: load data local infile “D:/mysql.txt” into table mytable;
导入.sql 文件命令
use database
source d:/mysql.sql;

13一.MySQL数据库检查
mysqlcheck -o %%3 -u %%1 -p %%2

13二.MySQL数据表文件修复
myisamchk -B -o %%1.myd

一,查看数据库状态 及运营甘休
/etc/init.d/mysqld status
/etc/init.d/mysqld start
/etc/init.d/mysqld stop

二,给用户配置早先密码123456:
mysqladmin -u root -password 123456

3,修改root用户密码为 abc1贰叁
mysqladmin -u root -p123456 password abc123

4,假设想去掉密码:
mysqladmin -u root -pabc123 password “”

5,root连接数据库有密码和无密码:
mysql -u root(-uroot) -p
mysql

6,扩张用户 test1 密码
abc,让它能够在别的主机上登入,并对具有数据库有询问,插入,修改,删除的权杖:
格式: grant select on 数据库.* to 用户名@登入主机 identified by
“密码”
grant select,insert,update,delete on . to test1@”%” Identified by
“abc”;

八,扩充二个用户test贰,让它只好够在localhost上登入,并得以对数据库mydb实行询问,插入,修改,删除的操作,
那般用户便是选择知道test二的密码,他也无力回天从internet
上一向访问数据库,只可以通过mysql主机上的web页面来拜访。
grant select,insert,update,delete on mydb.* to test2@localhost
identified by “abc”;
grant select,insert,update,delete on mydb.* to test二@localhost
identified by “”; 设置无密码

九,展现数据库列表:
show databases;
use mysql 打开库
show tables;

10,表的操作
describle 表名; 展现数据表的构造
create database 库名;
drop database 库名;
create table 表名(字段设定列表)
drop table 表名;
delete from 表名;清空表记录
select * from 表名; 突显表中的笔录
insert into 表名 values(, ,)

alter table 表名 add column <字段名><字段选项>

133.反省端口占用

!/bin/bash

netstat -ano

13四.Linux下检查Apache是还是不是安装

!/bin/bash

rpm -qa | grep httpd

135.Linux下启动Apache服务

!/bin/bash

service httpd start

136.Linux下停止Apache服务

!/bin/bash

service httpd stop

1三七.Linux下重新起动Apache服务

!/bin/bash

service httpd restart

13八.Linux下自行加载Apache 服务

!/bin/bash

chkconfig – level 3 httpd on

13玖.Linux下不自行加载Apache 服务

!/bin/bash

chkconfig – level 3 httpd off

140.Linux下检查VSFTP是不是安装

!/bin/bash

rpm -qa | grep vsftpd

141.Linux下启动VSFTP服务

!/bin/bash

service vsftpd start

142.Linux下停止VSFTP服务

!/bin/bash

service vsftpd stop

14三.Linux下重新起动VSFTP服务

!/bin/bash

service vsftpd restart

14四.Linux下检查VSFTP是还是不是被运维

!/bin/bash

pstree | grep vsftpd

1四五.Linux下检查Sendmail是不是安装

!/bin/bash

rpm -qa | grep sendmail

146.Linux下启动Sendmail服务

!/bin/bash

service sendmail start

147.Linux下停止Sendmail服务

!/bin/bash

service sendma stop

148.Linux下重新起动Sendmail服务

!/bin/bash

service sendmail restart

149.Linux下自行加载Sendmail 服务

!/bin/bash

chkconfig – level 3 sendmail on

150.Linux下不自动加载Sendmail 服务

!/bin/bash

chkconfig – level 3 sendmail off

15一.Linux下文件图形分界面配置运转服务

!/bin/bash

ntsysv

15二.以数组的艺术删除文件夹

壹伍三.GCC批量编写翻译

!/bin/bash

find -type f ( -iname ‘.c’ -o -iname ‘.cpp’ ) -print |
while read filename
do
case “$filename” in
*.c)
gcc “$filename” -o “$(dirname “$filename”)”/”$(basename “$filename”
.c)”
;;
*.cpp)
gcc “$filename” -o “$(dirname “$filename”)”/”$(basename “$filename”
.cpp)”
;;
esac
done

154.批量予以可实行权限

!/bin/bash

find “$PWD” -type f ( -iname ‘.sh’ -o -iname ‘.csh’ -o -iname ‘.ksh’
-o -iname ‘
.pl’ -o -iname ‘.bin’ -o -iname ‘.run’ -o -iname
.bundle’ -o -iname ‘.rb’ -o -iname ‘*.py’ ) -print0 | xargs -0 chmod
+x

!/bin/bash

for file in .sh .pl .bin .run .bundle .rb .py
do
if [[ ! “$file” =~ \
.[A-Za-z]+ ]]; then
chmod +x “$(file)”
fi
done
OLDIFS=$IFS
IFS=:
for path in $( find $(pwd) -type d -printf “%p$IFS”)
do
for file in $path/.sh $path/.pl $path/.bin $path/.run $path/.bundle
$path/
.rb $path/.py
do
if [[ ! “$file” =~ \
.[A-Za-z]+ ]]; then
chmod +x “$(path)/$(file)”
fi
done
done
IFS=$OLDIFS

15伍.批量实施

!/bin/bash

find -type f ( -iname ‘.sh’ -o -iname ‘.csh’ -o -iname ‘.ksh’ -o
-iname ‘
.pl’ -o -iname ‘.bin’ -o -iname ‘.run’ -o -iname ‘.bundle’
-o -iname ‘
.bin’ -o -iname ‘.class’ -o -iname ‘.rpm’ -o -iname ‘.rb’
-o -iname ‘
.py’ -o -iname ‘*.jar’ ) -print |
while read filename
do
case “$filename” in
*.sh | *.csh | *.ksh)
if [ ! “./””$(basename $filename)” = $0 ]; then
xterm -e “$filename”
fi
;;
*.pl)
xterm -e perl “$filename”
;;
*.bin | *.run | *.bundle)
xterm -e “$filename”
;;
*.class)
xterm -e java “$(dirname “$filename”)”/”$(basename “$filename”
.class)”
;;
*.rpm)
xterm -e rpm -ivh “$filename”
;;
*.rb)
xterm -e ruby “$filename”
;;
*.py)
xterm -e python “$filename”
;;
*.jar)
xterm -e java -jar “$filename”
;;
esac
done

!/bin/bash

find -maxdepth 1 -type f ( -iname ‘.sh’ -o -iname ‘.pl’ -o -iname
.bin’ -o -iname ‘.run’ -o -iname ‘.bundle’ -o -iname ‘.bin’ -o
-iname ‘.class’ -o -iname ‘.rpm’ -o -iname ‘.rb’ -o -iname ‘.py’ -o
-iname ‘.jar’ ) -print
while read file
do
case “${file##
.}” in
sh ) xterm -e “”””$file””””;;
pl ) xterm -e perl “”””$file””””;;
bin ) xterm -e “”””$file””””;;
run ) xterm -e “”””$file””””;;
bundle ) xterm -e “”””$file””””;;
class ) xterm -e java “”””${file%.*}””””;;
rpm ) xterm -e rpm -ivh “”””$file””””;;
rb ) xterm -e ruby “”””$file””””;;
py ) xterm -e python “”””$file””””;;
jar ) xterm -e java -jar “”””$file””””;;
esac
done

15陆.到手操作系统版本

!/bin/bash

uname -r

uname -a

157.自个儿复制

!/bin/bash

cp $0 “%%1”

15八.GCC批量开立静态库

!/bin/bash

find -type f ( -iname ‘.c’ -o -iname ‘.cpp’ ) -print |
while read filename
do
case “$filename” in
.c)
g++ -c -o “$(dirname “$filename”)”/”$(basename “$filename” .c)”.o””
“$filename”
;;
.cpp)
g++ -c -o “$(dirname “$filename”)”/”$(basename “$filename” .cpp)”.o””
“$filename”
;;
esac
done
OLDIFS=$IFS
IFS=:
for path in $( find $(pwd) -type d -printf “%p$IFS”)
do
ar ru $path”.a” $path”/.o” && ranlib $path”.a”
done
IFS=$OLDIFS
find “$PWD” -type f ( -iname ‘
.o’ ) -print0 | xargs -0 rm -if

15九.Java批量打包EJB

!/bin/bash

find “$PWD” -type f ( -iname ‘.java’ ) -print0 | xargs -0 javac
OLDIFS=$IFS
IFS=:
for path in $( find $(pwd) -type d -printf “%p$IFS”)
do
jar -cvf “$(path”.jar”)” “$(path”/
.*”)” && cp “$(path”.jar”)”
“$(JBOSS_HOME”/server/default/deploy”)”
done
IFS=$OLDIFS

find “$PWD” -type f ( -iname ‘*.class’ ) -print0 | xargs -0 rm -if

160.收获环境变量

161.dd

!/bin/bash

dd

16二.出示唯有小写字母的公文

!/bin/bash

ls -1|awk ‘/^[[:lower:]].*/’

1陆三.Zip压缩目录中的全部文件

!/bin/bash

direc=”%%1″ #$(pwd)
targetpath=”%%2″
OLDIFS=$IFS
IFS=:
for path in $( find $direc -type d -printf “%p$IFS”)
do
mkdir -p “$targetpath/${path:${#direc}+1}”
for file in $path/*
do
if [ -f $file ]; then
zip -j “$targetpath/${path:${#direc}+1}/${file:${#path}+1}.zip”
“$file”
fi
done
done
IFS=$OLDIFS

16肆.Zip解压缩目录中的全数文件

!/bin/bash

direc=”%%1″ #$(pwd)
targetpath=”%%2″
OLDIFS=$IFS
IFS=:
for path in $( find $direc -type d -printf “%p$IFS”)
do
mkdir -p “$targetpath/${path:${#direc}+1}”
unzip -x “$path/*.zip” -d “$targetpath/${path:${#direc}+1}”
done
IFS=$OLDIFS

1陆5.布满式复制文件夹

!/bin/bash

direc=”%%1″ #$(pwd)
targetpath=”%%2″
OLDIFS=$IFS
IFS=:
for path in $( find $direc -type d -printf “%p$IFS”)
do
mkdir -p “$targetpath/${path:${#direc}+1}”
rm -if “$targetpath/${path:${#direc}+1}/.tmp”
for file in $path/

do
if [ -f $file ]; then
cp “$file” “$targetpath/${path:${#direc}+1}/${file:${#path}+1}.tmp”
mv “$targetpath/${path:${#direc}+1}/${file:${#path}+1}.tmp”
“$targetpath/${path:${#direc}+1}/${file:${#path}+1}”
fi
done
done
IFS=$OLDIFS

16六.登记反注册组件

!/bin/bash

regsvr32 “%%1”

167.LZMA

!/bin/bash

16八.CAB压缩文件

!/bin/bash

16玖.CAB解压缩文件

!/bin/bash

170.锁定荧屏

!/bin/sh

RUNDLL32.exe USER32,LockWorkStation

17一.以任何用户的身份运行程序

!/bin/bash

17贰.增加体系用户

!/bin/sh

useradd “%%1”

17三.删减系统用户

!/bin/sh

userdel “%%1”

17肆.增多用户组

!/bin/sh

groupadd -g 2000 “%%1”

17伍.刨除用户组

!/bin/sh

groupdel “%%1”

17陆.予以管理员权限

!/bin/bash

17七.打消管理员权限

!/bin/bash

17八.遍历目录爆发删除文件的剧本

!/bin/bash

17九.LZW压缩文件

!/bin/bash

z

180.LZW解压缩文件

!/bin/bash

z

1八1.递归予以目录权限

!/bin/bash

direc=”%%1″ #$(pwd)
OLDIFS=$IFS
IFS=:
for path in $( find $direc -type d -printf “%p$IFS”)
do
chown -R root.root “$path”
done
IFS=$OLDIFS

182.卸载RPM包

!/bin/sh

rpm -e “%%1”

183.删除源文件中的注释

!/bin/sh

1八四.安装目录下全数文件属性为可写

!/bin/sh

185.总括目录下有所文件的累计行数

!/bin/sh

cat * |wc
ls |xargs wc -l
find ./ -name “
c” | xargs wc -l

186.去除自个儿

!/bin/rm

exit 65

rm $0

1八柒.开采终端

!/bin/bash -l

188.弹出光驱

!/bin/sh

eject

18九.收回光驱

!/bin/sh

eject -t

190.磁盘总空间总结

191.解析CSV文件

192.按行保存文件为数组

193.MySQL执行SQL文件
mysqladmin -u %%1 -p%%2 < %%3.sql

mysql -u %%1 -p%%2 -e “SOURCE %%3.sql”

相关文章