shell 文件操作大全 193条命令

1.创建文件夹
#!/bin/sh
mkdir -m 777 "%%1"

2.创建文件
#!/bin/sh
touch "%%1"

3.删除文件
#!/bin/sh
rm -if "%%1"

4.删除文件夹
#!/bin/sh
rm -rf "%%1"

5.删除一个目录下所有的文件夹
#!/bin/bash
direc="%%1" #$(pwd)
for dir2del in $direc/* ; do
if [ -d $dir2del ]; then
  rm -rf $dir2del
fi
done

6.清空文件夹
#!/bin/bash
direc="%%1" #$(pwd)
rm -if $direc/*
for dir2del in $direc/* ; do
if [ -d $dir2del ]; then
  rm -rf $dir2del
fi
done

7.读取文件
#!/bin/sh
7.1.操作系统默认编码
cat "%%1" | while read line; do
echo $line;
done

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

7.3.分块读取
cat "%%1" | while read line; do
echo $line;
done

8.写入文件
#!/bin/sh
cat > "%%1" << EOF
%%2
EOF

tee "%%1" > /dev/null << EOF
%%2
EOF

#sed -i '$a %%2' %%2

9.写入随机文件
#!/bin/sh
cat > "%%1" << EOF
%%2
EOF

tee "%%1" > /dev/null << EOF
%%2
EOF

#sed -i '$a %%2' %%2

10.读取文件属性
#!/bin/bash
file=%%1
file=${file:?'必须给出参数'}
if [ ! -e $file ]; then
    echo "$file 不存在"
    exit 1
fi
if [ -d $file ]; then
    echo "$file 是一个目录"
    if [ -x $file ]; 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.写入文件属性
#!/bin/bash
#修改存放在ext2、ext3、ext4、xfs、ubifs、reiserfs、jfs等文件系统上的文件或目录属性,使用权限超级用户。
#一些功能是由Linux内核版本来支持的,如果Linux内核版本低于2.2,那么许多功能不能实现。同样-D检查压缩文件中的错误的功能,需要2.5.19以上内核才能支持。另外,通过chattr命令修改属性能够提高系统的安全性,但是它并不适合所有的目录。chattr命令不能保护/、/dev、/tmp、/var目录。
chattr [-RV] [-+=AacDdijsSu] [-v version] 文件或目录
  -R:递归处理所有的文件及子目录。
  -V:详细显示修改内容,并打印输出。
  -:失效属性。
  +:激活属性。
  = :指定属性。
  A:Atime,告诉系统不要修改对这个文件的最后访问时间。
  S:Sync,一旦应用程序对这个文件执行了写操作,使系统立刻把修改的结果写到磁盘。
  a:Append Only,系统只允许在这个文件之后追加数据,不允许任何进程覆盖或截断这个文件。如果目录具有这个属性,系统将只允许在这个目录下建立和修改文件,而不允许删除任何文件。
  i:Immutable,系统不允许对这个文件进行任何的修改。如果目录具有这个属性,那么任何的进程只能修改目录之下的文件,不允许建立和删除文件。
  D:检查压缩文件中的错误。
  d:No dump,在进行文件系统备份时,dump程序将忽略这个文件。
  C:Compress,系统以透明的方式压缩这个文件。从这个文件读取时,返回的是解压之后的数据;而向这个文件中写入数据时,数据首先被压缩之后才写入磁盘。
  S:Secure Delete,让系统在删除这个文件时,使用0填充文件所在的区域。
  u:Undelete,当一个应用程序请求删除这个文件,系统会保留其数据块以便以后能够恢复删除这个文件。

12.枚举一个目录中的所有文件夹
#!/bin/bash
OLDIFS=$IFS
IFS=:
for path in $( find "%%1" -type d -printf "%p$IFS")
do
#"$path"
done
IFS=$OLDIFS

13.复制文件夹
#!/bin/sh
cp -rf "%%1" "%%2"

14.复制一个目录下所有的文件夹到另一个目录下
#!/bin/bash
direc="%%1" #$(pwd)
for dir2cp in $direc/* ; do
if [ -d $dir2cp ]; then
  cp $dir2cp "%%2"
fi
done

15.移动文件夹
#!/bin/sh
mv -rf "%%1" "%%2"

16.移动一个目录下所有的文件夹到另一个目录下
#!/bin/bash
direc="%%1" #$(pwd)
for dir2mv in $direc/* ; do
if [ -d $dir2mv ]; then
  mv $dir2mv "%%2"
fi
done

17.以一个文件夹的框架在另一个目录下创建文件夹和空文件
#!/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
#cp -a "%%1" "%%2"

表达式 含义
${#string}
{#string}
1,取得字符串长度
string=abc12342341          //等号二边不要有空格
echo ${#string}             //结果11
expr length $string         //结果11
expr "$string" : ".*"       //结果11 分号二边要有空格,这里的:根match的用法差不多2,字符串所在位置
expr index $string '123'    //结果4 字符串对应的下标是从0开始的这个方法让我想起来了js的indexOf,各种语言对字符串的操作方法大方向都差不多,如果有语言基础的话,学习shell会很快的。
3,从字符串开头到子串的最大长度
expr match $string 'abc.*3' //结果9个人觉得这个函数的用处不大,为什么要从开头开始呢。
4,字符串截取
echo ${string:4}      //2342341  从第4位开始截取后面所有字符串
echo ${string:3:3}    //123      从第3位开始截取后面3位
echo ${string:3:6}    //123423   从第3位开始截取后面6位
echo ${string: -4}    //2341  :右边有空格   截取后4位
echo ${string:(-4)}   //2341  同上
expr substr $string 3 3   //123  从第3位开始截取后面3位上面的方法让我想起了,php的substr函数,后面截取的规则是一样的。
5,匹配显示内容
//例3中也有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 显示括号中匹配的内容这里括号的用法,是不是根其他的括号用法有相似之处呢,
6,截取不匹配的内容
echo ${string#a*3}     //42341  从$string左边开始,去掉最短匹配子串
echo ${string#c*3}     //abc12342341  这样什么也没有匹配到
echo ${string#*c1*3}   //42341  从$string左边开始,去掉最短匹配子串
echo ${string##a*3}    //41     从$string左边开始,去掉最长匹配子串
echo ${string%3*1}     //abc12342  从$string右边开始,去掉最短匹配子串
echo ${string%%3*1}    //abc12     从$string右边开始,去掉最长匹配子串这里要注意,必须从字符串的第一个字符开始,或者从最后一个开始,
7,匹配并且替换
echo ${string/23/bb}   //abc1bb42341  替换一次
echo ${string//23/bb}  //abc1bb4bb41  双斜杠替换所有匹配
echo ${string/#abc/bb} //bb12342341   #以什么开头来匹配,根php中的^有点像
echo ${string/%41/bb}  //abc123423bb  %以什么结尾来匹配,根php中的$有点像

#!/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

18.复制文件
#!/bin/sh
cp %%1 %%2

19.复制一个目录下所有的文件到另一个目录
#!/bin/bash
direc="%%1" $(pwd)
for file in "$direc/*"
do
cp "$file" "%%1"
done

20.提取扩展名
#!/bin/sh
%%2=${%%1##.}

21.提取文件名
#!/bin/sh
%%2="$(basename %%1)"

22.提取文件路径
#!/bin/sh
%%2="$(dirname %%1)"

23.替换扩展名
#!/bin/sh
%%3="$(basename %%1)$%%2"

24.追加路径
#!/bin/sh
%%3="$(dirname %%1)/$%%2"

25.移动文件
#!/bin/sh
mv "%%1" "%%2"

26.移动一个目录下所有文件到另一个目录
#!/bin/bash
direc="%%1" #$(pwd)
OLDIFS=$IFS
IFS=:
for file in "$(direc)/*"
do
mv "$file" "%%1"
done
IFS=$OLDIFS

27.指定目录下搜索文件
#!/bin/sh
find -name "%%1"

28.打开文件对话框
#!/bin/sh
%%1="$(Xdialog --fselect '~/' 0 0 2>&1)"

29.文件分割
#!/bin/sh
split -b 2k "%%1"

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


#!/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  :以行数来进行分割;



#按每个文件1000行来分割除

split -l 1000 httperr8007.log httperr

httpaa,httpab,httpac ........

#按照每个文件100K来分割

split -b 100k httperr8007.log http

httpaa,httpab,httpac ........

#!/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

#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.文件合并
#!/bin/sh
cp "%%1"+"%%2" "%%3"

exec 3 exec 4 while read f1 <&3 && read f2 <&4
do
    echo $f1 $f2 >> join.txt
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

#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'

31.文件简单加密
#!/bin/bash
#make test && make strings && sudo make install
shc -r -f %%1.sh
#%%1.x
#%%1.x.c

32.文件简单解密
#!/bin/bash
#make test && make strings && sudo make install
shc -r -f %%1.sh
#%%1.x
#%%1.x.c

33.读取ini文件属性
#!/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

34.合并一个文件下所有的文件
#!/bin/sh
cat $(ls |grep -E '%%1\.') > %%1

#!/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
#"$(path)/$(file)"
fi
done
done
IFS=$OLDIFS

#!/bin/bash
cat <<'EOF'> combine.c
#include
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);   /*从a1.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))  /*文件a1.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

35.写入ini文件属性
#!/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

36.获得当前路径
#!/bin/sh
%%1=$(pwd)

37.读取XML数据库

如何通过shell命令行读取xml文件中某个属性所对应的值?
例如:
BuildVersion 5
我希望能够通过Unix shell命令对属性键的名称BuildVersion进行查询,返回的结果是5,如何实现呀?
#!/bin/bash
grep BuildVersion|sed 's/.*<.*>\([^<].*\)<.*>.*/\1/'

结果返回的是“BuildVersion”,而不是“5”,如果要查询BuildVersion自动返回数值5应当如何写?

应该没错的。试一下: echo "BuildVersion 5"|grep BuildVersion|sed 's/.*<.*>\([^<].*\)<.*>.*/\1/'我在SL的终端里试,返回值是5

目前需要从xml文件提取数据,想做一个xmlparser.sh
xml 类似这样

  



希望输入 xmlparser.sh a.xml hostip可以返回192.168.0.1


#!/bin/sh

if [ $# -ne 2 ];then
   echo "Usage: $0 "
   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.]+"
楼上这个有问题,如果我要得到的是

  

中的sharename,那么,呵呵,就错了

我觉得应该先定位到第二个参数“$2”的位置,然后再提取“=”后面的内容

这里有个完整的实现:
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文件里面都有

        xxx</titlel><br style="word-wrap:break-word"> </article><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 通过shell读取,然后合并到一起,再生成一个新的xml,但是其他元素不变。<br style="word-wrap:break-word"> <article><br style="word-wrap:break-word">         <title>aaa</titlel><br style="word-wrap:break-word"> </article><br style="word-wrap:break-word"> <article><br style="word-wrap:break-word">         <title>bbb</titlel><br style="word-wrap:break-word"> </article><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 如果格式异常简单,没有特例,那么可以用shell实现<br style="word-wrap:break-word"> 如果有可能格式复杂,因为shell的命令所使用的正则表达式都不支持跨行匹配,所以用shell来解决这个问题就绕圈子了。<br style="word-wrap:break-word"> 用perl来作这个工作最直接、简单。perl的XML:DOM模块是专门处理XML文件的。<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 偶倒是觉得,用PHP写Scripts也很方便,功能强大,而且,跨平台,<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> sed -n '/<article>/{<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> N;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> /\n[[:space:]]*<title>/{<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     N;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     /<article>.*<\/article>/p<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     }<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> D;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> n<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> }'<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 这小段代码能把一个xml文件中,你要的东西拿出来.<br style="word-wrap:break-word"> 你可以用for file in $*把这些信息都>>tmpfile中.<br style="word-wrap:break-word"> 然后用sed 在指定文件的指定位置用r命令把tmpfile粘贴进来~~~~<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 大思路如此^_^  我想有这个东西(只要能正确的跑出结果)后面就不难了吧...<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Name<br style="word-wrap:break-word"> xmllint — command line XML tool<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Synopsis<br style="word-wrap:break-word"> 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]<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Introduction<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> It is included in libxml2.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Options<br style="word-wrap:break-word"> --version<br style="word-wrap:break-word"> Display the version of libxml2 used.<br style="word-wrap:break-word"> --debug<br style="word-wrap:break-word"> Parse a file and output an annotated tree of the in-memory version of the document.<br style="word-wrap:break-word"> --shell<br style="word-wrap:break-word"> Run a navigating shell. Details on available commands in shell mode are below.<br style="word-wrap:break-word"> --debugent<br style="word-wrap:break-word"> Debug the entities defined in the document.<br style="word-wrap:break-word"> --copy<br style="word-wrap:break-word"> Test the internal copy implementation.<br style="word-wrap:break-word"> --recover<br style="word-wrap:break-word"> Output any parsable portions of an invalid document.<br style="word-wrap:break-word"> --noent<br style="word-wrap:break-word"> Substitute entity values for entity references. By default, xmllint leaves entity references in place.<br style="word-wrap:break-word"> --nocdata<br style="word-wrap:break-word"> Substitute CDATA section by equivalent text nodes.<br style="word-wrap:break-word"> --nsclean<br style="word-wrap:break-word"> Remove redundant namespace declarations.<br style="word-wrap:break-word"> --noout<br style="word-wrap:break-word"> Suppress output. By default, xmllint outputs the result tree.<br style="word-wrap:break-word"> --htmlout<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --nowrap<br style="word-wrap:break-word"> Do not output HTML doc wrapper.<br style="word-wrap:break-word"> --valid<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --postvalid<br style="word-wrap:break-word"> Validate after parsing is completed.<br style="word-wrap:break-word"> --dtdvalid URL<br style="word-wrap:break-word"> Use the DTD specified by URL for validation.<br style="word-wrap:break-word"> --dtdvalidfpi FPI<br style="word-wrap:break-word"> Use the DTD specified by the Public Identifier FPI for validation, note that this will require a Catalog exporting that Public Identifier to work.<br style="word-wrap:break-word"> --timing<br style="word-wrap:break-word"> Output information about the time it takes xmllint to perform the various steps.<br style="word-wrap:break-word"> --output file<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --repeat<br style="word-wrap:break-word"> Repeat 100 times, for timing or profiling.<br style="word-wrap:break-word"> --insert<br style="word-wrap:break-word"> Test for valid insertions.<br style="word-wrap:break-word"> --compress<br style="word-wrap:break-word"> Turn on gzip compression of output.<br style="word-wrap:break-word"> --html<br style="word-wrap:break-word"> Use the HTML parser.<br style="word-wrap:break-word"> --xmlout<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --push<br style="word-wrap:break-word"> Use the push mode of the parser.<br style="word-wrap:break-word"> --memory<br style="word-wrap:break-word"> Parse from memory.<br style="word-wrap:break-word"> --maxmem nnbytes<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --nowarning<br style="word-wrap:break-word"> Do not emit warnings from the parser and/or validator.<br style="word-wrap:break-word"> --noblanks<br style="word-wrap:break-word"> Drop ignorable blank spaces.<br style="word-wrap:break-word"> --format<br style="word-wrap:break-word"> Reformat and reindent the output. The $XMLLINT_INDENT environment variable controls the indentation (default value is two spaces " ").<br style="word-wrap:break-word"> --testIO<br style="word-wrap:break-word"> Test user input/output support.<br style="word-wrap:break-word"> --encode encoding<br style="word-wrap:break-word"> Output in the given encoding.<br style="word-wrap:break-word"> --catalogs<br style="word-wrap:break-word"> Use the catalogs from $SGML_CATALOG_FILES. Otherwise /etc/xml/catalog is used by default.<br style="word-wrap:break-word"> --nocatalogs<br style="word-wrap:break-word"> Do not use any catalogs.<br style="word-wrap:break-word"> --auto<br style="word-wrap:break-word"> Generate a small document for testing purposes.<br style="word-wrap:break-word"> --xinclude<br style="word-wrap:break-word"> Do XInclude processing.<br style="word-wrap:break-word"> --noxincludenode<br style="word-wrap:break-word"> Do XInclude processing but do not generate XInclude start and end nodes.<br style="word-wrap:break-word"> --loaddtd<br style="word-wrap:break-word"> Fetch external DTD.<br style="word-wrap:break-word"> --dtdattr<br style="word-wrap:break-word"> Fetch external DTD and populate the tree with inherited attributes.<br style="word-wrap:break-word"> --dropdtd<br style="word-wrap:break-word"> Remove DTD from output.<br style="word-wrap:break-word"> --stream<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --walker<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --chkregister<br style="word-wrap:break-word"> Turn on node registration. Useful for developers testing libxml2 node tracking code.<br style="word-wrap:break-word"> --pattern patternvalue<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --relaxng schema<br style="word-wrap:break-word"> Use RelaxNG file named schema for validation.<br style="word-wrap:break-word"> --schema schema<br style="word-wrap:break-word"> Use a W3C XML Schema file named schema for validation.<br style="word-wrap:break-word"> --c14n<br style="word-wrap:break-word"> Use the W3C XML Canonicalisation (C14N) to serialize the result of parsing to stdout. It keeps comments in the result.<br style="word-wrap:break-word"> Shell<br style="word-wrap:break-word"> xmllint offers an interactive shell mode invoked with the --shell command. Available commands in shell mode include:<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> base<br style="word-wrap:break-word"> display XML base of the node<br style="word-wrap:break-word"> bye<br style="word-wrap:break-word"> leave shell<br style="word-wrap:break-word"> cat node<br style="word-wrap:break-word"> Display node if given or current node.<br style="word-wrap:break-word"> cd path<br style="word-wrap:break-word"> Change the current node to path (if given and unique) or root if no argument given.<br style="word-wrap:break-word"> dir path<br style="word-wrap:break-word"> Dumps information about the node (namespace, attributes, content).<br style="word-wrap:break-word"> du path<br style="word-wrap:break-word"> Show the structure of the subtree under path or the current node.<br style="word-wrap:break-word"> exit<br style="word-wrap:break-word"> Leave the shell.<br style="word-wrap:break-word"> help<br style="word-wrap:break-word"> Show this help.<br style="word-wrap:break-word"> free<br style="word-wrap:break-word"> Display memory usage.<br style="word-wrap:break-word"> load name<br style="word-wrap:break-word"> Load a new document with the given name.<br style="word-wrap:break-word"> ls path<br style="word-wrap:break-word"> List contents of path (if given) or the current directory.<br style="word-wrap:break-word"> pwd<br style="word-wrap:break-word"> Display the path to the current node.<br style="word-wrap:break-word"> quit<br style="word-wrap:break-word"> Leave the shell.<br style="word-wrap:break-word"> save name<br style="word-wrap:break-word"> Saves the current document to name if given or to the original name.<br style="word-wrap:break-word"> validate<br style="word-wrap:break-word"> Check the document for error.<br style="word-wrap:break-word"> write name<br style="word-wrap:break-word"> Write the current node to the given filename.<br style="word-wrap:break-word"> Catalogs<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Debugging Catalogs<br style="word-wrap:break-word"> Setting the environment variable XML_DEBUG_CATALOG using the command "export XML_DEBUG_CATALOG=" outputs debugging information related to catalog operations.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Error Return Codes<br style="word-wrap:break-word"> On the completion of execution, Xmllint returns the following error codes:<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 0<br style="word-wrap:break-word"> No error<br style="word-wrap:break-word"> 1<br style="word-wrap:break-word"> Unclassified<br style="word-wrap:break-word"> 2<br style="word-wrap:break-word"> Error in DTD<br style="word-wrap:break-word"> 3<br style="word-wrap:break-word"> Validation error<br style="word-wrap:break-word"> 4<br style="word-wrap:break-word"> Validation error<br style="word-wrap:break-word"> 5<br style="word-wrap:break-word"> Error in schema compilation<br style="word-wrap:break-word"> 6<br style="word-wrap:break-word"> Error writing output<br style="word-wrap:break-word"> 7<br style="word-wrap:break-word"> Error in pattern (generated when [--pattern] option is used)<br style="word-wrap:break-word"> 8<br style="word-wrap:break-word"> Error in Reader registration (generated when [--chkregister] option is used)<br style="word-wrap:break-word"> 9<br style="word-wrap:break-word"> Out of memory error<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Parse Simple XML Files using Bash – Extract Name Value Pairs and Attributes<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 2 Comments<br style="word-wrap:break-word"> 1<br style="word-wrap:break-word"> Tweet<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Pratik Sinha | July 31, 2010<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> I have written up a simple routine par***ML 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<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> xmlFile=$1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> function par***ML() {<br style="word-wrap:break-word">   elemList=( $(cat $xmlFile | tr '\n' ' ' | XMLLINT_INDENT="" xmllint --format - | /bin/grep -e "</.*>$" | while read line; do \<br style="word-wrap:break-word">     echo $line | sed -e 's/^.*<\///' | cut -d '>' -f 1; \<br style="word-wrap:break-word">   done) )<br style="word-wrap:break-word"> <br style="word-wrap:break-word">   totalNoOfTags=${#elemList[@]}; ((totalNoOfTags--))<br style="word-wrap:break-word">   suffix=$(echo ${elemList[$totalNoOfTags]} | tr -d '</>')<br style="word-wrap:break-word">   suffix="${suffix}_"<br style="word-wrap:break-word"> <br style="word-wrap:break-word">   for (( i = 0 ; i < ${#elemList[@]} ; i++ )); do<br style="word-wrap:break-word">     elem=${elemList[$i]}<br style="word-wrap:break-word">     elemLine=$(cat $xmlFile | tr '\n' ' ' | XMLLINT_INDENT="" xmllint --format - | /bin/grep "</$elem>")<br style="word-wrap:break-word">     echo $elemLine | grep -e "^</[^ ]*>$" 1>/dev/null 2>&1<br style="word-wrap:break-word">     if [ "0" = "$?" ]; then<br style="word-wrap:break-word">       continue<br style="word-wrap:break-word">     fi<br style="word-wrap:break-word">     elemVal=$(echo $elemLine | tr '\011' '\040'| sed -e 's/^[ ]*//' -e 's/^<.*>\([^<].*\)<.*>$/\1/' | sed -e 's/^[ ]*//' | sed -e 's/[ ]*$//')<br style="word-wrap:break-word">     xmlElem="${suffix}$(echo $elem | sed 's/-/_/g')"<br style="word-wrap:break-word">     eval ${xmlElem}=`echo -ne \""${elemVal}"\"`<br style="word-wrap:break-word">     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 ' ' '>'))<br style="word-wrap:break-word">     for (( j = 0 ; j < ${#attrList[@]} ; j++ )); do<br style="word-wrap:break-word">       attr=${attrList[$j]}<br style="word-wrap:break-word">       ((j++))<br style="word-wrap:break-word">       attrVal=$(echo ${attrList[$j]} | tr '>' ' ')<br style="word-wrap:break-word">       attrName=`echo -ne ${xmlElem}_${attr}`<br style="word-wrap:break-word">       eval ${attrName}=`echo -ne \""${attrVal}"\"`<br style="word-wrap:break-word">     done<br style="word-wrap:break-word">   done<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> par***ML<br style="word-wrap:break-word"> echo "$status_xyz |  $status_abc |  $status_pqr" #Variables for each  XML ELement<br style="word-wrap:break-word"> echo "$status_xyz_arg1 |  $status_abc_arg2 |  $status_pqr_arg3 | $status_pqr_arg4" #Variables for each XML Attribute<br style="word-wrap:break-word"> echo ""<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #All the variables that were produced by the par***ML function<br style="word-wrap:break-word"> set | /bin/grep -e "^$suffix"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> The XML File used for the above script example is:<br style="word-wrap:break-word"> <?xml version="1.0"?><br style="word-wrap:break-word"> <status><br style="word-wrap:break-word">   <xyz arg1="1"> a </xyz><br style="word-wrap:break-word">   <abc arg2="2"> p </abc><br style="word-wrap:break-word">   <pqr arg3="3" arg4="a phrase"> x </pqr><br style="word-wrap:break-word"> </status><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> The output when the script is ran with the xml file as an argument is<br style="word-wrap:break-word"> @$ bash  par***ML.sh test.xml<br style="word-wrap:break-word"> a |  p |  x<br style="word-wrap:break-word"> 1 |  2 |  3 | a phrase<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> status_abc=p<br style="word-wrap:break-word"> status_abc_arg2=2<br style="word-wrap:break-word"> status_pqr=x<br style="word-wrap:break-word"> status_pqr_arg3=3<br style="word-wrap:break-word"> status_pqr_arg4='a phrase'<br style="word-wrap:break-word"> status_xyz=a<br style="word-wrap:break-word"> status_xyz_arg1=1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> This script won’t work for XML files like the one below with duplicate element names.<br style="word-wrap:break-word"> <?xml version="1.0"?><br style="word-wrap:break-word"> <status><br style="word-wrap:break-word">   <test arg1="1"> a </test><br style="word-wrap:break-word">   <test arg2="2"> p </test><br style="word-wrap:break-word">   <test arg3="3" arg4="a phrase"> x </test><br style="word-wrap:break-word"> </status><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 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>.<br style="word-wrap:break-word"> <?xml version="1.0"?><br style="word-wrap:break-word"> <status><br style="word-wrap:break-word">   <test arg1="1"><br style="word-wrap:break-word">     <test1 arg2="2">abc</test1><br style="word-wrap:break-word">   </test><br style="word-wrap:break-word"> </status><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 38.写入XML数据库<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 39.ZIP压缩文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> zip -r "/%%1" "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 40.ZIP解压缩<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> unzip -x "/%%1" "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 41.获得应用程序完整路径<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 42.ZIP压缩文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 43.递归删除目录下的文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rm -if "%%1/*"<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find %%1 -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> for file in $path/*.c $path/*.cpp<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [[ ! "$file" =~ \*.[A-Za-z]+ ]]; then<br style="word-wrap:break-word"> #"$(path)/$(file)"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 44.IDEA加密算法<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 45.RC6算法<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> cat <<'EOF'> rc6.c<br style="word-wrap:break-word"> #include<stdio.h><br style="word-wrap:break-word"> /* Timing data for RC6 (rc6.c)<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 128 bit key:<br style="word-wrap:break-word"> Key Setup:    1632 cycles<br style="word-wrap:break-word"> Encrypt:       270 cycles =    94.8 mbits/sec<br style="word-wrap:break-word"> Decrypt:       226 cycles =   113.3 mbits/sec<br style="word-wrap:break-word"> Mean:          248 cycles =   103.2 mbits/sec<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 192 bit key:<br style="word-wrap:break-word"> Key Setup:    1885 cycles<br style="word-wrap:break-word"> Encrypt:       267 cycles =    95.9 mbits/sec<br style="word-wrap:break-word"> Decrypt:       235 cycles =   108.9 mbits/sec<br style="word-wrap:break-word"> Mean:          251 cycles =   102.0 mbits/sec<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 256 bit key:<br style="word-wrap:break-word"> Key Setup:    1877 cycles<br style="word-wrap:break-word"> Encrypt:       270 cycles =    94.8 mbits/sec<br style="word-wrap:break-word"> Decrypt:       227 cycles =   112.8 mbits/sec<br style="word-wrap:break-word"> Mean:          249 cycles =   103.0 mbits/sec<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #include "../std_defs.h"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> static char *alg_name[] = { "rc6", "rc6.c", "rc6" };<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> char **cipher_name()<br style="word-wrap:break-word"> {<br style="word-wrap:break-word">     return alg_name;<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #define f_rnd(i,a,b,c,d)                    \<br style="word-wrap:break-word">         u = rotl(d * (d + d + 1), 5);       \<br style="word-wrap:break-word">         t = rotl(b * (b + b + 1), 5);       \<br style="word-wrap:break-word">         a = rotl(a ^ t, u) + l_key;      \<br style="word-wrap:break-word">         c = rotl(c ^ u, t) + l_key[i + 1]<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #define i_rnd(i,a,b,c,d)                    \<br style="word-wrap:break-word">         u = rotl(d * (d + d + 1), 5);       \<br style="word-wrap:break-word">         t = rotl(b * (b + b + 1), 5);       \<br style="word-wrap:break-word">         c = rotr(c - l_key[i + 1], t) ^ u;  \<br style="word-wrap:break-word">         a = rotr(a - l_key, u) ^ t<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> u4byte  l_key[44];  /* storage for the key schedule         */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> /* initialise the key schedule from the user supplied key   */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> u4byte *set_key(const u4byte in_key[], const u4byte key_len)<br style="word-wrap:break-word"> {   u4byte  i, j, k, a, b, l[8], t;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     l_key[0] = 0xb7e15163;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     for(k = 1; k < 44; ++k)<br style="word-wrap:break-word">        <br style="word-wrap:break-word">         l_key[k] = l_key[k - 1] + 0x9e3779b9;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     for(k = 0; k < key_len / 32; ++k)<br style="word-wrap:break-word"> <br style="word-wrap:break-word">         l[k] = in_key[k];<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     t = (key_len / 32) - 1; // t = (key_len / 32);<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     a = b = i = j = 0;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     for(k = 0; k < 132; ++k)<br style="word-wrap:break-word">     {   a = rotl(l_key + a + b, 3); b += a;<br style="word-wrap:break-word">         b = rotl(l[j] + b, b);<br style="word-wrap:break-word">         l_key = a; l[j] = b;<br style="word-wrap:break-word">         i = (i == 43 ? 0 : i + 1); // i = (i + 1) % 44; <br style="word-wrap:break-word">         j = (j == t ? 0 : j + 1);  // j = (j + 1) % t;<br style="word-wrap:break-word">     }<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     return l_key;<br style="word-wrap:break-word"> };<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> /* encrypt a block of text  */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> void encrypt(const u4byte in_blk[4], u4byte out_blk[4])<br style="word-wrap:break-word"> {   u4byte  a,b,c,d,t,u;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     a = in_blk[0]; b = in_blk[1] + l_key[0];<br style="word-wrap:break-word">     c = in_blk[2]; d = in_blk[3] + l_key[1];<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     f_rnd( 2,a,b,c,d); f_rnd( 4,b,c,d,a);<br style="word-wrap:break-word">     f_rnd( 6,c,d,a,b); f_rnd( 8,d,a,b,c);<br style="word-wrap:break-word">     f_rnd(10,a,b,c,d); f_rnd(12,b,c,d,a);<br style="word-wrap:break-word">     f_rnd(14,c,d,a,b); f_rnd(16,d,a,b,c);<br style="word-wrap:break-word">     f_rnd(18,a,b,c,d); f_rnd(20,b,c,d,a);<br style="word-wrap:break-word">     f_rnd(22,c,d,a,b); f_rnd(24,d,a,b,c);<br style="word-wrap:break-word">     f_rnd(26,a,b,c,d); f_rnd(28,b,c,d,a);<br style="word-wrap:break-word">     f_rnd(30,c,d,a,b); f_rnd(32,d,a,b,c);<br style="word-wrap:break-word">     f_rnd(34,a,b,c,d); f_rnd(36,b,c,d,a);<br style="word-wrap:break-word">     f_rnd(38,c,d,a,b); f_rnd(40,d,a,b,c);<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     out_blk[0] = a + l_key[42]; out_blk[1] = b;<br style="word-wrap:break-word">     out_blk[2] = c + l_key[43]; out_blk[3] = d;<br style="word-wrap:break-word"> };<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> /* decrypt a block of text  */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> void decrypt(const u4byte in_blk[4], u4byte out_blk[4])<br style="word-wrap:break-word"> {   u4byte  a,b,c,d,t,u;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     d = in_blk[3]; c = in_blk[2] - l_key[43];<br style="word-wrap:break-word">     b = in_blk[1]; a = in_blk[0] - l_key[42];<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     i_rnd(40,d,a,b,c); i_rnd(38,c,d,a,b);<br style="word-wrap:break-word">     i_rnd(36,b,c,d,a); i_rnd(34,a,b,c,d);<br style="word-wrap:break-word">     i_rnd(32,d,a,b,c); i_rnd(30,c,d,a,b);<br style="word-wrap:break-word">     i_rnd(28,b,c,d,a); i_rnd(26,a,b,c,d);<br style="word-wrap:break-word">     i_rnd(24,d,a,b,c); i_rnd(22,c,d,a,b);<br style="word-wrap:break-word">     i_rnd(20,b,c,d,a); i_rnd(18,a,b,c,d);<br style="word-wrap:break-word">     i_rnd(16,d,a,b,c); i_rnd(14,c,d,a,b);<br style="word-wrap:break-word">     i_rnd(12,b,c,d,a); i_rnd(10,a,b,c,d);<br style="word-wrap:break-word">     i_rnd( 8,d,a,b,c); i_rnd( 6,c,d,a,b);<br style="word-wrap:break-word">     i_rnd( 4,b,c,d,a); i_rnd( 2,a,b,c,d);<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     out_blk[3] = d - l_key[1]; out_blk[2] = c;<br style="word-wrap:break-word">     out_blk[1] = b - l_key[0]; out_blk[0] = a;<br style="word-wrap:break-word"> };<br style="word-wrap:break-word"> int main()<br style="word-wrap:break-word"> {<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> return 0;<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> EOF<br style="word-wrap:break-word"> gcc -o rc6 rc6.c<br style="word-wrap:break-word"> if [ $? -eq 0 ]; then<br style="word-wrap:break-word"> ./combine<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> echo 'Compile ERROR'<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 46.Grep<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> grep -qE %%1 %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 47.直接创建多级目录<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> mkdir -p %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 48.批量重命名<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find $PWD -type f -name '*\.cpp' |sed s/'\.cpp'//g|awk '{MV = "mv"};{C = "\.c"};{ CPP="\.cpp"}; {print MV, $1 CPP , $1 C}'|sh<br style="word-wrap:break-word"> ls | awk -F '-' '{print "mv "$0" "$2}' #去掉带'-'的前缀<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 49.文本查找替换<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> sed -e 's:%%2:%%3:g' %%1<br style="word-wrap:break-word"> #sed -e 's/%%2/%%3/g' %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 50.文件关联<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 51.批量转换编码从GB2312到Unicode<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> scode="gbk"<br style="word-wrap:break-word"> dcode="ucs2"<br style="word-wrap:break-word"> for FILE in $(find $(pwd) -type f)<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> TMP_file=$(mktemp -p $(pwd))<br style="word-wrap:break-word"> if [ -f $FILE ]; then<br style="word-wrap:break-word"> Fright=$(stat -c %a $FILE)<br style="word-wrap:break-word"> Fuser=$(stat -c %U $FILE)<br style="word-wrap:break-word"> Fgrp=$(stat -c %G $FILE)<br style="word-wrap:break-word"> iconv -f $scode -t $dcode $FILE -o $TMP_file<br style="word-wrap:break-word"> mv $TMP_file $FILE<br style="word-wrap:break-word"> chmod $Fright $FILE<br style="word-wrap:break-word"> chown $Fuser.$Fgrp $FILE<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 52.设置JDK环境变量<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find "$PWD" -type f \( -iname '*.bin' \) -print0 | xargs -0 chmod +x<br style="word-wrap:break-word"> find -type f \( -iname '*.bin' \) -print |<br style="word-wrap:break-word"> while read filename<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "$filename" in<br style="word-wrap:break-word">     *.bin)<br style="word-wrap:break-word">         xterm -e "$filename" && rm -if "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=$'\n'<br style="word-wrap:break-word"> for line in `cat ~/.bashrc`<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [[ "$line" =~ .*export.* ]]; then<br style="word-wrap:break-word">     if [[ "$line" =~ .*JAVA_HOME=.* ]]; then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]]; then<br style="word-wrap:break-word">        javahome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     fi<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [[ "$line" =~ export\ PATH=\$PATH:\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin$ ]];then<br style="word-wrap:break-word">     javapath=$line<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [[ "$line" =~ export\ CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib$ ]];then<br style="word-wrap:break-word">     classpath=$line<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> if [ ! -n "$javahome" ]; then<br style="word-wrap:break-word"> sed -i '$a export JAVA_HOME='$(pwd)'/jdk1.6.0_25' ~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${javahome//\\/\\\\}':export JAVA_HOME='$(pwd)'/jdk1.6.0_32:g' ~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$javapath" ]; then<br style="word-wrap:break-word"> sed -i '$a export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin' ~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$classpath" ]; then<br style="word-wrap:break-word"> sed -i '$a export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib' ~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> shift<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=$'\n'<br style="word-wrap:break-word"> for line in `cat ~/TestBash.txt` #~/.bashrc<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">   if [[ "$line" =~ .*export.* ]]; then<br style="word-wrap:break-word">     if [[ "$line" =~ export\ CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib$ ]]; then<br style="word-wrap:break-word">       classpath=$line<br style="word-wrap:break-word">     elif [[ "$line" =~ export\ PATH=\$PATH:\$CATALINA_HOME/bin$ ]]; then<br style="word-wrap:break-word">       jbosspath=$line<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word">     if [[ "$line" =~ .*JAVA_HOME=.* ]]; then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        javahome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     elif [[ "$line" =~ .*CATALINA_HOME=.* ]];then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        catalinahome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     elif [[ "$line" =~ .*TOMCAT_HOME=.* ]];then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        tomcathome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     elif [[ "$line" =~ .*CATALINA_BASE=.* ]];then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        catalinabase=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     elif [[ "$line" =~ .*JBOSS_HOME=.* ]];then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        jbosshome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     fi<br style="word-wrap:break-word">   elif [[ "$line" =~ ^PATH=\$PATH:\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin$ ]];then<br style="word-wrap:break-word">     javapath=$line<br style="word-wrap:break-word">   fi<br style="word-wrap:break-word">   if [[ "$line" =~ export\ CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib$ ]];then<br style="word-wrap:break-word">     classpath=$line<br style="word-wrap:break-word">   fi<br style="word-wrap:break-word">   if [[ "$line" =~ export\ PATH=\$PATH:\$JBOSS_HOME/bin$ ]];then<br style="word-wrap:break-word">     jbosspath=$line<br style="word-wrap:break-word">   fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> if [ ! -n "$javahome" ]; then<br style="word-wrap:break-word"> sed -i '$a export JAVA_HOME='$(pwd)'/jdk1.6.0_24' ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${javahome//\\/\\\\}':export JAVA_HOME='$(pwd)'/jdk1.6.0_24:g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$javapath" ]; then<br style="word-wrap:break-word"> sed -i '$a PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin' ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$classpath" ]; then<br style="word-wrap:break-word"> sed -i '$a export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib' ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$catalinahome" ]; then<br style="word-wrap:break-word"> sed -i '$a export CATALINA_HOME='$(pwd) ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${catalinahome//\\/\\\\}':export CATALINA_HOME='$(pwd)':g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$tomcathome" ]; then<br style="word-wrap:break-word"> sed -i '$a export TOMCAT_HOME='$(pwd) ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${tomcathome//\\/\\\\}':export TOMCAT_HOME='$(pwd)':g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$catalinabase" ]; then<br style="word-wrap:break-word"> sed -i '$a export CATALINA_BASE='$(pwd) ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${catalinabase//\\/\\\\}':export CATALINA_BASE='$(pwd)':g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$jbosshome" ]; then<br style="word-wrap:break-word"> sed -i '$a export JBOSS_HOME='$(pwd) ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${jbosshome//\\/\\\\}':export JBOSS_HOME='$(pwd)':g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$jbosspath" ]; then<br style="word-wrap:break-word"> sed -i '$a export PATH=$PATH:$CATALINA_HOME/bin' ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 53.批量转换编码从Unicode到GB2312<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> scode="ucs2"<br style="word-wrap:break-word"> dcode="gbk"<br style="word-wrap:break-word"> for FILE in $(find $(pwd) -type f)<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> TMP_file=$(mktemp -p $(pwd))<br style="word-wrap:break-word"> if [ -f $FILE ]; then<br style="word-wrap:break-word"> Fright=$(stat -c %a $FILE)<br style="word-wrap:break-word"> Fuser=$(stat -c %U $FILE)<br style="word-wrap:break-word"> Fgrp=$(stat -c %G $FILE)<br style="word-wrap:break-word"> iconv -f $scode -t $dcode $FILE -o $TMP_file<br style="word-wrap:break-word"> mv $TMP_file $FILE<br style="word-wrap:break-word"> chmod $Fright $FILE<br style="word-wrap:break-word"> chown $Fuser.$Fgrp $FILE<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 54.删除空文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rmdir -p %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 55.GB2312文件转UTF-8格式<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> iconv -f gbk -t utf8 %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 56.UTF-8文件转GB2312格式<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> iconv -f utf8 -t  gbk %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 57.获取文件路径的父路径<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> %%1=basename $PWD<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 58.Unicode文件转UTF-8格式<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> iconv -f ucs2 -t  utf-8 %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 59.CRC循环冗余校验<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> cat <<'EOF'> crc.c<br style="word-wrap:break-word"> #include<stdio.h><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int crc32_table[256]; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int ulPolynomial = 0x04c11db7; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int Reflect(unsigned long int ref, char ch) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   {     unsigned long int value(0); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         // 交换bit0和bit7,bit1和bit6,类推 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         for(int i = 1; i < (ch + 1); i++) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          {            if(ref & 1) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                       value |= 1 << (ch - i); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                    ref >>= 1;      } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         return value; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> } <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> init_crc32_table() <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   {     unsigned long int crc,temp; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         // 256个值 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         for(int i = 0; i <= 0xFF; i++) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          {   temp=Reflect(i, 8); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                crc32_table[i]= temp<< 24; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 for (int j = 0; j < 8; j++){ <br style="word-wrap:break-word"> <br style="word-wrap:break-word">              unsigned long int t1,t2; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   unsigned long int flag=crc32_table[i]&0x80000000; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 t1=(crc32_table[i] << 1); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 if(flag==0) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                   t2=0; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 else <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                   t2=ulPolynomial; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 crc32_table[i] =t1^t2 ;        } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                crc=crc32_table[i]; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                crc32_table[i] = Reflect(crc32_table[i], 32); <br style="word-wrap:break-word">         }<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> unsigned long GenerateCRC32(char xdata * DataBuf,unsigned long  len) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   { <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         unsigned long oldcrc32; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         unsigned long crc32; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         unsigned long oldcrc; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         unsigned  int charcnt; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          char c,t; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         oldcrc32 = 0x00000000; //初值为0 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">      charcnt=0; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          while (len--) { <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  t= (oldcrc32 >> 24) & 0xFF;   //要移出的字节的值 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">      oldcrc=crc_32_tab[t];         //根据移出的字节的值查表 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  c=DataBuf[charcnt];          //新移进来的字节值 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  oldcrc32= (oldcrc32 << 8) | c;   //将新移进来的字节值添在寄存器末字节中 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  oldcrc32=oldcrc32^oldcrc;     //将寄存器与查出的值进行xor运算 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  charcnt++; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          crc32=oldcrc32; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          return crc32; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> } <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 参数表可以先在PC机上算出来,也可在程序初始化时完成。下面是用于计算参数表的c语言子程序,在Visual C++ 6.0下编译通过。 <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #include <stdio.h> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int crc32_table[256]; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int ulPolynomial = 0x04c11db7; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int Reflect(unsigned long int ref, char ch) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   {     unsigned long int value(0); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         // 交换bit0和bit7,bit1和bit6,类推 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         for(int i = 1; i < (ch + 1); i++) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          {            if(ref & 1) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                       value |= 1 << (ch - i); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                    ref >>= 1;      } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         return value; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> int main()<br style="word-wrap:break-word"> {<br style="word-wrap:break-word">      unsigned long int crc,temp; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         // 256个值 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         for(int i = 0; i <= 0xFF; i++) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          {<br style="word-wrap:break-word"> temp=Reflect(i, 8);<br style="word-wrap:break-word">                crc32_table[i]= temp<< 24; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 for (int j = 0; j < 8; j++){ <br style="word-wrap:break-word"> <br style="word-wrap:break-word">              unsigned long int t1,t2; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   unsigned long int flag=crc32_table[i]&0x80000000;<br style="word-wrap:break-word">                 t1=(crc32_table[i] << 1); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 if(flag==0) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                   t2=0; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 else <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                   t2=ulPolynomial; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 crc32_table[i] =t1^t2 ;       <br style="word-wrap:break-word"> } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                crc=crc32_table[i];<br style="word-wrap:break-word">                crc32_table[i] = Reflect(crc32_table[i], 32);<br style="word-wrap:break-word">         }<br style="word-wrap:break-word"> return 0;<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> EOF<br style="word-wrap:break-word"> gcc -o crc crc.c<br style="word-wrap:break-word"> if [ $? -eq 0 ]; then<br style="word-wrap:break-word"> ./combine<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> echo 'Compile ERROR'<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 60.判断是否为空文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 61.终止程序<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> kill -KILL pidof %%1 -s<br style="word-wrap:break-word"> #killall %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 62.定时关机<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> shutdown -h %%1 & #23:00<br style="word-wrap:break-word"> #shutdown -h now<br style="word-wrap:break-word"> #halt<br style="word-wrap:break-word"> #/sbin/poweroff<br style="word-wrap:break-word"> #init 0<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 63.显示进程列表<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> ps aux<br style="word-wrap:break-word"> #fuser -l<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 64.遍历文件夹列出文件大小<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> du -sH "%%1/*"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 65.GOST算法<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 66.对目标压缩文件解压缩到指定文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 67.保存文件时重名自动生成新文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 68.打开网页<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> lynx %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 69.删除空文件夹整合操作<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 70.获取磁盘所有分区<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> df -k<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 71.激活一个程序或程序关联的文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 72.MP3播放<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> amp "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 73.WAV播放<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> amp "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 74.写图像到剪切板<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 75.从剪贴板复制图像到窗体<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 76.删除文件夹下的所有文件且不删除文件夹下的文件夹<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> rm -if "%%1/*"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 77.XML遍历结点属性值<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 78.Unicode文件转GB2312格式<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> iconv -f ucs2 -t  gbk %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 79.开源程序库Xercesc-C++代码工程中内联80.提取包含头文件列表<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 81.GB2312文件转Unicode格式<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> iconv -f gbk -t  ucs2 %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 82.Java程序打包<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 83.UTF-8文件转Unicode格式<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> iconv -f utf8 -t  ucs2 %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 84.创建PDF文档<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 85.创建Word文档<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 86.快速高效的文件加密<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 87.从CSV文件构造XML文档<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 88.从XML文档生成CSV文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 89.模拟键盘输入字符串<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 90.提取PDF文件中的文本<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 91.操作内存映射文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 91.1发送内存映射数据<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 91.2接收内存映射数据<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 92.重定向windows控制台程序的输出信息<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 93.基数转序数<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 94.数字月份转英文<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 95.报表相关<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 96.根据进程名获取进程ID<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> pidof %%1 -s<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 96.BCP导入<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 97.BCP导出<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 98.计算文件MD5值<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> md5sum "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 99.计算获取文件夹中文件的MD5值<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 100.复制一个目录下所有文件到一个文件夹中<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> cp $(find "%%1" -name *.*) "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 101.移动一个目录下所有文件到一个文件夹中<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> mv $(find "%%1" -name *.*) "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 102.文件RSA高级加密<br style="word-wrap:break-word"> 十进制到十六进制<br style="word-wrap:break-word"> typeset -i16 BASE_16_NUM<br style="word-wrap:break-word"> BASE_16_NUM=%%1<br style="word-wrap:break-word"> echo $BASE_16_NUM<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 八进制到十六进制<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> typeset -i16 BASE_16_NUM<br style="word-wrap:break-word"> BASE_16_NUM=8#%%1<br style="word-wrap:break-word"> echo $BASE_16_NUM<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 十进制到八进制<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> printf %o %%1; echo<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 十进制到十六进制<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> printf %x %%1; echo<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 103.计算文件大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> wc "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 104.计算文件夹的大小<br style="word-wrap:break-word"> #!/sbin/ksh<br style="word-wrap:break-word"> dir=%%1<br style="word-wrap:break-word"> (cd $dir;pwd)<br style="word-wrap:break-word"> find $dir -type d -print | du | awk '{print $2, "== ("$1/2"kb)"}' |sort -f |<br style="word-wrap:break-word"> sed -e "s,[^ /]*/([^ /]*) ==,|--1," -e"s,[^ /]*/,| ,g"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 105.快速获得当前程序的驱动器、路径、文件名和扩展名<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 106.磁盘剩余空间计算<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> df -k<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 107.获取当前程序进程ID<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> pidof %%1 -s<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 108.全盘搜索文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> #updatedb<br style="word-wrap:break-word"> #locate %%1<br style="word-wrap:break-word"> slocate %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 109.获得当前登录的用户名<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> whoami<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 110.获得所有用户名<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> who<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 111.创建MySQL管理用户<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> mysqladmin -u root password %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.管理MySQL数据库服务器<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 112.1.启动MySQL数据库服务器<br style="word-wrap:break-word"> mysqld -console<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.2.登录MySQL数据库服务器<br style="word-wrap:break-word"> 112.2.1.登录本地MySQL数据库服务器<br style="word-wrap:break-word"> mysql -uroot -p%%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.2.2.登录远程MySQL数据库服务器<br style="word-wrap:break-word"> mysql -h %%1 -u %%2 -p%%3<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.3.关闭MySQL数据库服务器<br style="word-wrap:break-word"> mysqladmin -u root shutdown<br style="word-wrap:break-word"> #pkill -9 mysql<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.4.测试MySQL数据库服务器<br style="word-wrap:break-word"> mysqlshow || mysqlshow -u root mysql || mysqladmin version status || mysql test<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 113.MySQL执行查询<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> mysqladmin -u %%1 -p%%2 SELECT * INTO OUTFILE './bestlovesky.xls' FROM bestlovesky WHERE 1 ORDER BY id DESC  LIMIT 0, 50;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> mysql -u %%1 -p%%2 -e "SELECT * INTO OUTFILE './bestlovesky.xls' FROM bestlovesky WHERE 1 ORDER BY id DESC  LIMIT 0, 50;"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 114.创建Oracle管理用户<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> 114.1.创建新用户<br style="word-wrap:break-word"> create user test identified by test default tablespace ts_test temporary<br style="word-wrap:break-word"> tablespace temp;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 114.2.给用户角色特权<br style="word-wrap:break-word"> grant connect,resource to test;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 115.登录Oracle数据库<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> sqlplusw<br style="word-wrap:break-word"> sqlplus /nolog<br style="word-wrap:break-word"> conn username/password@Oranet<br style="word-wrap:break-word"> conn system/systempwd@whfc<br style="word-wrap:break-word"> conn sys/syspwd@whfc as sysdba<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 115.创建Oracle表空间<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> conn system@whfc01<br style="word-wrap:break-word"> create tablespace ts_test datafile '/data2/oradata/ciis/ts_test01.dbf' size<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 116.添加Oracle数据文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> alter tablespace ts_test add datafile '/data2/oradata/ciis/ts_test02.dbf' size<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 117.查看Oracle表空间大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> desc DBA_DATA_FILES<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 118.查看Oracle剩余表空间大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> desc DBA_FREE_SPACE<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 119.查看Oracle当前用户表名<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> select * from tab;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 120.Oracle创建索引<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> CREATE INDEX idx_book_bookid ON book(bookname);<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 121.Oracle创建主键约束<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> ALTER TABLE book ADD CONSTRAINT pk_book_bookid PRIMARY KEY (bookid);<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 122.Oracle显示表结构<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> desc book<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 123.Oracle查看表的索引<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> column index_name format a30<br style="word-wrap:break-word"> select table_name, index_name from user_indexes;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 124.Oracle查看索引列<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> select table_name, index_name, column_name, column_position from user_ind_columns;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 125.Oracle查看数据段占空间大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> desc user_segments<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 126.Oracle查看表占空间大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> select segment_name,segment_type,bytes from user_segments where segment_type='TABLE';<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 127.安全删除USB<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rundll32.exe shell32.dll,Control_RunDLL hotplug.dll<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 128.打开SQL Server Management Studio<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> sqlwb %%1.sql<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 129.MySQL数据库导出备份<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> mysqldump -u %%1 -p %%2 %%3>%%4.sql<br style="word-wrap:break-word"> mysqldump --opt test > mysql.test //将数据库test导出到mysql.test文件,后面是一个文本文件<br style="word-wrap:break-word"> mysqldump -u root -p123456 --databases dbname > mysql.dbname //就是把数据库dbname导出到文件mysql.dbname中。<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 130.MySQL数据库数据导入<br style="word-wrap:break-word"> mysql -u %%1 -p %%2 %%3<%%4.sql<br style="word-wrap:break-word"> mysqlimport -u root -p123456 < mysql.dbname<br style="word-wrap:break-word"> 将文本数据导入数据库:<br style="word-wrap:break-word"> 文本数据的字段之间用tab键隔开<br style="word-wrap:break-word"> use test<br style="word-wrap:break-word"> load data local infile "文件名" into table 表名;<br style="word-wrap:break-word"> eg: load data local infile "D:/mysql.txt" into table mytable;<br style="word-wrap:break-word"> 导入.sql 文件命令<br style="word-wrap:break-word"> use database<br style="word-wrap:break-word"> source d:/mysql.sql;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 131.MySQL数据库检查<br style="word-wrap:break-word"> mysqlcheck -o %%3 -u %%1 -p %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 132.MySQL数据表文件修复<br style="word-wrap:break-word"> myisamchk -B -o %%1.myd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 1,查看数据库状态 及启动停止<br style="word-wrap:break-word"> /etc/init.d/mysqld status<br style="word-wrap:break-word"> /etc/init.d/mysqld start<br style="word-wrap:break-word"> /etc/init.d/mysqld stop<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 2,给用户配置初始密码123456:<br style="word-wrap:break-word"> mysqladmin -u root -password 123456<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 3,修改root用户密码为 abc123<br style="word-wrap:break-word"> mysqladmin -u root -p123456 password abc123<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 4,如果想去掉密码:<br style="word-wrap:break-word"> mysqladmin -u root -pabc123 password ""<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 5,root连接数据库有密码和无密码:<br style="word-wrap:break-word"> mysql -u root(-uroot) -p<br style="word-wrap:break-word"> mysql<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 6,增加用户 test1 密码 abc,让它可以在任何主机上登录,并对所有数据库有查询,插入,修改,删除的权限:<br style="word-wrap:break-word"> 格式: grant select on 数据库.* to 用户名@登录主机 identified by "密码"<br style="word-wrap:break-word"> grant select,insert,update,delete on *.* to test1@"%" Identified by "abc";<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 8,增加一个用户test2,让它只可以在localhost上登录,并可以对数据库mydb进行查询,插入,修改,删除的操作,<br style="word-wrap:break-word"> 这样用户即使使用知道test2的密码,他也无法从internet 上直接访问数据库,只能通过mysql主机上的web页面来访问。<br style="word-wrap:break-word"> grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";<br style="word-wrap:break-word"> grant select,insert,update,delete on mydb.* to test2@localhost identified by ""; 设置无密码<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 9,显示数据库列表:<br style="word-wrap:break-word"> show databases;<br style="word-wrap:break-word"> use mysql 打开库<br style="word-wrap:break-word"> show tables;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 10,表的操作<br style="word-wrap:break-word"> describle 表名; 显示数据表的结构<br style="word-wrap:break-word"> create database 库名;<br style="word-wrap:break-word"> drop database 库名;<br style="word-wrap:break-word"> create table 表名(字段设定列表)<br style="word-wrap:break-word"> drop table 表名;<br style="word-wrap:break-word"> delete from 表名;清空表记录<br style="word-wrap:break-word"> select * from 表名; 显示表中的记录<br style="word-wrap:break-word"> insert into 表名 values(, ,)<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> alter table 表名 add column <字段名><字段选项><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 133.检查端口占用<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> netstat -ano<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 134.Linux下检查Apache是否安装<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rpm -qa | grep httpd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 135.Linux下启动Apache服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service httpd start<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 136.Linux下停止Apache服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service httpd stop<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 137.Linux下重新启动Apache服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service httpd restart<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 138.Linux下自动加载Apache 服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> chkconfig - level 3 httpd on<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 139.Linux下不自动加载Apache 服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> chkconfig - level 3 httpd off<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 140.Linux下检查VSFTP是否安装<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rpm -qa | grep vsftpd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 141.Linux下启动VSFTP服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service vsftpd start<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 142.Linux下停止VSFTP服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service vsftpd stop<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 143.Linux下重新启动VSFTP服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service vsftpd restart<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 144.Linux下检查VSFTP是否被启动<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> pstree | grep vsftpd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 145.Linux下检查Sendmail是否安装<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rpm -qa | grep sendmail<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 146.Linux下启动Sendmail服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service sendmail start<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 147.Linux下停止Sendmail服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service sendma stop<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 148.Linux下重新启动Sendmail服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service sendmail restart<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 149.Linux下自动加载Sendmail 服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> chkconfig - level 3 sendmail on<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 150.Linux下不自动加载Sendmail 服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> chkconfig - level 3 sendmail off<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 151.Linux下文本图形界面配置启动服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> ntsysv<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 152.以数组的方式删除文件夹<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 153.GCC批量编译<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find -type f \( -iname '*.c' -o -iname '*.cpp' \) -print |<br style="word-wrap:break-word"> while read filename<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "$filename" in<br style="word-wrap:break-word">     *.c)<br style="word-wrap:break-word">       gcc "$filename" -o "$(dirname "$filename")"/"$(basename "$filename" .c)"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.cpp)<br style="word-wrap:break-word">         gcc "$filename" -o "$(dirname "$filename")"/"$(basename "$filename" .cpp)"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 154.批量赋予可执行权限<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 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<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> for file in *.sh *.pl *.bin *.run *.bundle *.rb *.py<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [[ ! "$file" =~ \*.[A-Za-z]+ ]]; then<br style="word-wrap:break-word"> chmod +x "$(file)"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $(pwd) -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> for file in $path/*.sh $path/*.pl $path/*.bin $path/*.run $path/*.bundle $path/*.rb $path/*.py<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [[ ! "$file" =~ \*.[A-Za-z]+ ]]; then<br style="word-wrap:break-word"> chmod +x "$(path)/$(file)"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 155.批量执行<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 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 |<br style="word-wrap:break-word"> while read filename<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "$filename" in<br style="word-wrap:break-word">     *.sh | *.csh | *.ksh)<br style="word-wrap:break-word"> if [ ! "./""$(basename $filename)" = $0 ]; then<br style="word-wrap:break-word">         xterm -e "$filename"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.pl)<br style="word-wrap:break-word">         xterm -e perl "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.bin | *.run | *.bundle)<br style="word-wrap:break-word">         xterm -e "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.class)<br style="word-wrap:break-word">         xterm -e java "$(dirname "$filename")"/"$(basename "$filename" .class)"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.rpm)<br style="word-wrap:break-word">         xterm -e rpm -ivh "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.rb)<br style="word-wrap:break-word">         xterm -e ruby "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.py)<br style="word-wrap:break-word">         xterm -e python "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.jar)<br style="word-wrap:break-word">         xterm -e java -jar "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 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<br style="word-wrap:break-word"> while read file<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "${file##*.}" in<br style="word-wrap:break-word">         sh ) xterm -e """"$file"""";;<br style="word-wrap:break-word">         pl ) xterm -e perl """"$file"""";;<br style="word-wrap:break-word">         bin ) xterm -e """"$file"""";;<br style="word-wrap:break-word">         run ) xterm -e """"$file"""";;<br style="word-wrap:break-word">         bundle ) xterm -e """"$file"""";;<br style="word-wrap:break-word">         class ) xterm -e java """"${file%.*}"""";;<br style="word-wrap:break-word">         rpm ) xterm -e rpm -ivh """"$file"""";;<br style="word-wrap:break-word">         rb ) xterm -e ruby """"$file"""";;<br style="word-wrap:break-word">         py ) xterm -e python """"$file"""";;<br style="word-wrap:break-word">         jar ) xterm -e java -jar """"$file"""";;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 156.获取操作系统版本<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> uname -r<br style="word-wrap:break-word"> #uname -a<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 157.自身复制<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> cp $0 "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 158.GCC批量创建静态库<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find -type f \( -iname '*.c' -o -iname '*.cpp' \) -print |<br style="word-wrap:break-word"> while read filename<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "$filename" in<br style="word-wrap:break-word">     *.c)<br style="word-wrap:break-word">       g++  -c -o "$(dirname "$filename")"/"$(basename "$filename" .c)".o"" "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.cpp)<br style="word-wrap:break-word">       g++  -c -o "$(dirname "$filename")"/"$(basename "$filename" .cpp)".o"" "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $(pwd) -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> ar ru $path".a" $path"/*.o" && ranlib $path".a"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> find "$PWD" -type f \( -iname '*.o' \) -print0 | xargs -0 rm -if<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 159.Java批量打包EJB<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find "$PWD" -type f \( -iname '*.java' \) -print0 | xargs -0 javac<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $(pwd) -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> jar -cvf "$(path".jar")" "$(path"/*.*")" && cp "$(path".jar")" "$(JBOSS_HOME"/server/default/deploy")"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> find "$PWD" -type f \( -iname '*.class' \) -print0 | xargs -0 rm -if<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 160.获取环境变量<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 161.dd<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> dd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 162.显示只有小写字母的文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> ls -1|awk '/^[[:lower:]].*/'<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 163.Zip压缩目录中的所有文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> targetpath="%%2"<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> mkdir -p "$targetpath/${path:${#direc}+1}"<br style="word-wrap:break-word"> for file in $path/*<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [ -f $file ]; then<br style="word-wrap:break-word"> zip -j "$targetpath/${path:${#direc}+1}/${file:${#path}+1}.zip" "$file"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 164.Zip解压缩目录中的所有文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> targetpath="%%2"<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> mkdir -p "$targetpath/${path:${#direc}+1}"<br style="word-wrap:break-word"> unzip -x "$path/*.zip" -d "$targetpath/${path:${#direc}+1}"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 165.分布式复制文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> targetpath="%%2"<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> mkdir -p "$targetpath/${path:${#direc}+1}"<br style="word-wrap:break-word"> rm -if "$targetpath/${path:${#direc}+1}/*.tmp"<br style="word-wrap:break-word"> for file in $path/*<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [ -f $file ]; then<br style="word-wrap:break-word"> cp "$file" "$targetpath/${path:${#direc}+1}/${file:${#path}+1}.tmp"<br style="word-wrap:break-word"> mv "$targetpath/${path:${#direc}+1}/${file:${#path}+1}.tmp" "$targetpath/${path:${#direc}+1}/${file:${#path}+1}"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 166.注册反注册组件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> regsvr32 "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 167.LZMA<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 168.CAB压缩文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 169.CAB解压缩文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 170.锁定屏幕<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> RUNDLL32.exe USER32,LockWorkStation<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 171.以其它用户的身份运行程序<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 172.添加系统用户<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> useradd "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 173.删除系统用户<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> userdel "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 174.添加用户组<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> groupadd -g 2000 "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 175.删除用户组<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> groupdel "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 176.赋予管理员权限<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 177.收回管理员权限<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 178.遍历目录产生删除文件的脚本<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 179.LZW压缩文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> z<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 180.LZW解压缩文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> z<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 181.递归赋予目录权限<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> chown -R root.root "$path"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 182.卸载RPM包<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> rpm -e  "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 183.删除源文件中的注释<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 184.设置目录下所有文件属性为可写<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 185.统计目录下所有文件的总共行数<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> cat * |wc<br style="word-wrap:break-word"> ls *|xargs wc -l<br style="word-wrap:break-word"> find ./ -name "*c" | xargs wc -l<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 186.删除自身<br style="word-wrap:break-word"> #!/bin/rm<br style="word-wrap:break-word"> exit 65<br style="word-wrap:break-word"> #rm $0<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 187.打开终端<br style="word-wrap:break-word"> #!/bin/bash -l<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 188.弹出光驱<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> eject<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 189.收回光驱<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> eject -t<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 190.磁盘总空间计算<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 191.解析CSV文件<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 192.按行保存文件为数组<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 193.MySQL执行SQL文件<br style="word-wrap:break-word"> mysqladmin -u %%1 -p%%2 < %%3.sql<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> mysql -u %%1 -p%%2 -e "SOURCE %%3.sql"</span> </div> </div> <div class="Blog_con2_1 Blog_con3_2" style="word-wrap:break-word; margin-top:50px; position:relative; line-height:22px"> <div style="word-wrap:break-word; height:30px"> <div class="bdsharebuttonbox bdshare-button-style0-16" style="word-wrap:break-word; zoom:1; height:30px"> </div> </div> </div> <div class="Blog_wz1" style="word-wrap:break-word; font-size:16px"> <div style="word-wrap:break-word"> <span style="word-wrap:break-word; border-collapse:separate; font-family:Tahoma; border-spacing:0px; font-size:14px">1.创建文件夹<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> mkdir -m 777 "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 2.创建文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> touch "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 3.删除文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> rm -if "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 4.删除文件夹<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> rm -rf "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 5.删除一个目录下所有的文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> for dir2del in $direc/* ; do<br style="word-wrap:break-word"> if [ -d $dir2del ]; then<br style="word-wrap:break-word">   rm -rf $dir2del<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 6.清空文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> rm -if $direc/*<br style="word-wrap:break-word"> for dir2del in $direc/* ; do<br style="word-wrap:break-word"> if [ -d $dir2del ]; then<br style="word-wrap:break-word">   rm -rf $dir2del<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 7.读取文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> 7.1.操作系统默认编码<br style="word-wrap:break-word"> cat "%%1" | while read line; do<br style="word-wrap:break-word"> echo $line;<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 7.2.UTF-8编码<br style="word-wrap:break-word"> cat "%%1" | while read line; do<br style="word-wrap:break-word"> echo $line;<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 7.3.分块读取<br style="word-wrap:break-word"> cat "%%1" | while read line; do<br style="word-wrap:break-word"> echo $line;<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 8.写入文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> cat > "%%1" << EOF<br style="word-wrap:break-word"> %%2<br style="word-wrap:break-word"> EOF<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> tee "%%1" > /dev/null << EOF<br style="word-wrap:break-word"> %%2<br style="word-wrap:break-word"> EOF<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #sed -i '$a %%2' %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 9.写入随机文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> cat > "%%1" << EOF<br style="word-wrap:break-word"> %%2<br style="word-wrap:break-word"> EOF<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> tee "%%1" > /dev/null << EOF<br style="word-wrap:break-word"> %%2<br style="word-wrap:break-word"> EOF<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #sed -i '$a %%2' %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 10.读取文件属性<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> file=%%1<br style="word-wrap:break-word"> file=${file:?'必须给出参数'}<br style="word-wrap:break-word"> if [ ! -e $file ]; then<br style="word-wrap:break-word">     echo "$file 不存在"<br style="word-wrap:break-word">     exit 1<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ -d $file ]; then<br style="word-wrap:break-word">     echo "$file 是一个目录"<br style="word-wrap:break-word">     if [ -x $file ]; then<br style="word-wrap:break-word">         echo "可以"<br style="word-wrap:break-word">     else<br style="word-wrap:break-word">         echo "不可以"<br style="word-wrap:break-word">     fi<br style="word-wrap:break-word">     echo "对此进行搜索"  <br style="word-wrap:break-word"> elif [ -f $file ]; then<br style="word-wrap:break-word">     echo "$file 是一个正规文件"<br style="word-wrap:break-word"> else<br style="word-wrap:break-word">     echo "$file不是一个正规文件"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ -O $file ]; then<br style="word-wrap:break-word">     echo "你是$file的拥有者"<br style="word-wrap:break-word"> else<br style="word-wrap:break-word">     echo "你不是$file的拥有者"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ -r $file ]; then<br style="word-wrap:break-word">     echo "你对$file拥有"<br style="word-wrap:break-word"> else<br style="word-wrap:break-word">     echo "你并不对$file拥有"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> echo "可读权限"<br style="word-wrap:break-word"> if [ -w $file ]; then<br style="word-wrap:break-word">     echo "你对$file拥有"<br style="word-wrap:break-word"> else<br style="word-wrap:break-word">     echo "你并不对$file拥有"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> echo "可写权限"<br style="word-wrap:break-word"> if [ -x $file -a ! -d $file ]; then<br style="word-wrap:break-word">     echo "你拥有对$file"<br style="word-wrap:break-word"> else<br style="word-wrap:break-word">     echo "你并不拥有对$file"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> echo "可执行的权限"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 11.写入文件属性<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> #修改存放在ext2、ext3、ext4、xfs、ubifs、reiserfs、jfs等文件系统上的文件或目录属性,使用权限超级用户。<br style="word-wrap:break-word"> #一些功能是由Linux内核版本来支持的,如果Linux内核版本低于2.2,那么许多功能不能实现。同样-D检查压缩文件中的错误的功能,需要2.5.19以上内核才能支持。另外,通过chattr命令修改属性能够提高系统的安全性,但是它并不适合所有的目录。chattr命令不能保护/、/dev、/tmp、/var目录。<br style="word-wrap:break-word"> chattr [-RV] [-+=AacDdijsSu] [-v version] 文件或目录<br style="word-wrap:break-word">   -R:递归处理所有的文件及子目录。<br style="word-wrap:break-word">   -V:详细显示修改内容,并打印输出。<br style="word-wrap:break-word">   -:失效属性。<br style="word-wrap:break-word">   +:激活属性。<br style="word-wrap:break-word">   = :指定属性。<br style="word-wrap:break-word">   A:Atime,告诉系统不要修改对这个文件的最后访问时间。<br style="word-wrap:break-word">   S:Sync,一旦应用程序对这个文件执行了写操作,使系统立刻把修改的结果写到磁盘。<br style="word-wrap:break-word">   a:Append Only,系统只允许在这个文件之后追加数据,不允许任何进程覆盖或截断这个文件。如果目录具有这个属性,系统将只允许在这个目录下建立和修改文件,而不允许删除任何文件。<br style="word-wrap:break-word">   i:Immutable,系统不允许对这个文件进行任何的修改。如果目录具有这个属性,那么任何的进程只能修改目录之下的文件,不允许建立和删除文件。<br style="word-wrap:break-word">   D:检查压缩文件中的错误。<br style="word-wrap:break-word">   d:No dump,在进行文件系统备份时,dump程序将忽略这个文件。<br style="word-wrap:break-word">   C:Compress,系统以透明的方式压缩这个文件。从这个文件读取时,返回的是解压之后的数据;而向这个文件中写入数据时,数据首先被压缩之后才写入磁盘。<br style="word-wrap:break-word">   S:Secure Delete,让系统在删除这个文件时,使用0填充文件所在的区域。<br style="word-wrap:break-word">   u:Undelete,当一个应用程序请求删除这个文件,系统会保留其数据块以便以后能够恢复删除这个文件。<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 12.枚举一个目录中的所有文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find "%%1" -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> #"$path"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 13.复制文件夹<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> cp -rf "%%1" "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 14.复制一个目录下所有的文件夹到另一个目录下<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> for dir2cp in $direc/* ; do<br style="word-wrap:break-word"> if [ -d $dir2cp ]; then<br style="word-wrap:break-word">   cp $dir2cp "%%2"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 15.移动文件夹<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> mv -rf "%%1" "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 16.移动一个目录下所有的文件夹到另一个目录下<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> for dir2mv in $direc/* ; do<br style="word-wrap:break-word"> if [ -d $dir2mv ]; then<br style="word-wrap:break-word">   mv $dir2mv "%%2"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 17.以一个文件夹的框架在另一个目录下创建文件夹和空文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> mkdir -p "%%2/${path:${#direc}+1}"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> #cp -a "%%1" "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 表达式 含义<br style="word-wrap:break-word"> ${#string}<br style="word-wrap:break-word"> {#string}<br style="word-wrap:break-word"> 1,取得字符串长度<br style="word-wrap:break-word"> string=abc12342341          //等号二边不要有空格<br style="word-wrap:break-word"> echo ${#string}             //结果11<br style="word-wrap:break-word"> expr length $string         //结果11<br style="word-wrap:break-word"> expr "$string" : ".*"       //结果11 分号二边要有空格,这里的:根match的用法差不多2,字符串所在位置<br style="word-wrap:break-word"> expr index $string '123'    //结果4 字符串对应的下标是从0开始的这个方法让我想起来了js的indexOf,各种语言对字符串的操作方法大方向都差不多,如果有语言基础的话,学习shell会很快的。<br style="word-wrap:break-word"> 3,从字符串开头到子串的最大长度<br style="word-wrap:break-word"> expr match $string 'abc.*3' //结果9个人觉得这个函数的用处不大,为什么要从开头开始呢。<br style="word-wrap:break-word"> 4,字符串截取<br style="word-wrap:break-word"> echo ${string:4}      //2342341  从第4位开始截取后面所有字符串<br style="word-wrap:break-word"> echo ${string:3:3}    //123      从第3位开始截取后面3位<br style="word-wrap:break-word"> echo ${string:3:6}    //123423   从第3位开始截取后面6位<br style="word-wrap:break-word"> echo ${string: -4}    //2341  :右边有空格   截取后4位<br style="word-wrap:break-word"> echo ${string:(-4)}   //2341  同上<br style="word-wrap:break-word"> expr substr $string 3 3   //123  从第3位开始截取后面3位上面的方法让我想起了,php的substr函数,后面截取的规则是一样的。<br style="word-wrap:break-word"> 5,匹配显示内容<br style="word-wrap:break-word"> //例3中也有match和这里的match不同,上面显示的是匹配字符的长度,而下面的是匹配的内容<br style="word-wrap:break-word"> expr match $string '\([a-c]*[0-9]*\)'  //abc12342341<br style="word-wrap:break-word"> expr $string : '\([a-c]*[0-9]\)'       //abc1<br style="word-wrap:break-word"> expr $string : '.*\([0-9][0-9][0-9]\)' //341 显示括号中匹配的内容这里括号的用法,是不是根其他的括号用法有相似之处呢,<br style="word-wrap:break-word"> 6,截取不匹配的内容<br style="word-wrap:break-word"> echo ${string#a*3}     //42341  从$string左边开始,去掉最短匹配子串<br style="word-wrap:break-word"> echo ${string#c*3}     //abc12342341  这样什么也没有匹配到<br style="word-wrap:break-word"> echo ${string#*c1*3}   //42341  从$string左边开始,去掉最短匹配子串<br style="word-wrap:break-word"> echo ${string##a*3}    //41     从$string左边开始,去掉最长匹配子串<br style="word-wrap:break-word"> echo ${string%3*1}     //abc12342  从$string右边开始,去掉最短匹配子串<br style="word-wrap:break-word"> echo ${string%%3*1}    //abc12     从$string右边开始,去掉最长匹配子串这里要注意,必须从字符串的第一个字符开始,或者从最后一个开始,<br style="word-wrap:break-word"> 7,匹配并且替换<br style="word-wrap:break-word"> echo ${string/23/bb}   //abc1bb42341  替换一次<br style="word-wrap:break-word"> echo ${string//23/bb}  //abc1bb4bb41  双斜杠替换所有匹配<br style="word-wrap:break-word"> echo ${string/#abc/bb} //bb12342341   #以什么开头来匹配,根php中的^有点像<br style="word-wrap:break-word"> echo ${string/%41/bb}  //abc123423bb  %以什么结尾来匹配,根php中的$有点像<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc=$(pwd)<br style="word-wrap:break-word"> for file in "$(direc)/*"<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [ "${file##*.}" = "sh" ]; then<br style="word-wrap:break-word"> xterm -e bash $file<br style="word-wrap:break-word"> elif [ "${file##*.}" = "bin" ]; then<br style="word-wrap:break-word"> xterm -e $file<br style="word-wrap:break-word"> elif [ "${file##*.}" = "run" ]; then<br style="word-wrap:break-word"> xterm -e $file<br style="word-wrap:break-word"> elif [ "${file##*.}" = "bundle" ]; then<br style="word-wrap:break-word"> xterm -e $file<br style="word-wrap:break-word"> elif [ "${file##*.}" = "pl" ]; then<br style="word-wrap:break-word"> xterm -e perl $file<br style="word-wrap:break-word"> elif [ "${file##*.}" = "class" ]; then<br style="word-wrap:break-word"> xterm -e java ${file%.*}<br style="word-wrap:break-word"> elif [ "${file##*.}" = "rpm" ]; then<br style="word-wrap:break-word"> xterm -e rpm -ivh $file<br style="word-wrap:break-word"> elif [ "${file##*.}" = "rb" ]; then<br style="word-wrap:break-word"> xterm -e ruby $file<br style="word-wrap:break-word"> elif [ "${file##*.}" = "py" ]; then<br style="word-wrap:break-word"> xterm -e python $file<br style="word-wrap:break-word"> elif [ "${file##*.}" = "jar" ]; then<br style="word-wrap:break-word"> xterm -e java -jar $file<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> for file in `ls $path`<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [ "${file##*.}" = "sh" ]; then<br style="word-wrap:break-word"> xterm -e bash """"$path"/"$file""""<br style="word-wrap:break-word"> elif [ "${file##*.}" = "bin" ]; then<br style="word-wrap:break-word"> xterm -e """"$path"/"$file""""<br style="word-wrap:break-word"> elif [ "${file##*.}" = "run" ]; then<br style="word-wrap:break-word"> xterm -e """"$path"/"$file""""<br style="word-wrap:break-word"> elif [ "${file##*.}" = "bundle" ]; then<br style="word-wrap:break-word"> xterm -e """"$path"/"$file""""<br style="word-wrap:break-word"> elif [ "${file##*.}" = "pl" ]; then<br style="word-wrap:break-word"> xterm -e perl """"$path"/"$file""""<br style="word-wrap:break-word"> elif [ "${file##*.}" = "class" ]; then<br style="word-wrap:break-word"> xterm -e java """"$path"/"${file%.*}""""<br style="word-wrap:break-word"> elif [ "${file##*.}" = "rpm" ]; then<br style="word-wrap:break-word"> xterm -e rpm -ivh """"$path"/"$file""""<br style="word-wrap:break-word"> elif [ "${file##*.}" = "rb" ]; then<br style="word-wrap:break-word"> xterm -e ruby """"$path"/"$file""""<br style="word-wrap:break-word"> elif [ "${file##*.}" = "py" ]; then<br style="word-wrap:break-word"> xterm -e python """"$path"/"$file""""<br style="word-wrap:break-word"> elif [ "${file##*.}" = "jar" ]; then<br style="word-wrap:break-word"> xterm -e java -jar """"$path"/"$file""""<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 18.复制文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> cp %%1 %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 19.复制一个目录下所有的文件到另一个目录<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" $(pwd)<br style="word-wrap:break-word"> for file in "$direc/*"<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> cp "$file" "%%1"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 20.提取扩展名<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> %%2=${%%1##.}<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 21.提取文件名<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> %%2="$(basename %%1)"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 22.提取文件路径<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> %%2="$(dirname %%1)"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 23.替换扩展名<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> %%3="$(basename %%1)$%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 24.追加路径<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> %%3="$(dirname %%1)/$%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 25.移动文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> mv "%%1" "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 26.移动一个目录下所有文件到另一个目录<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for file in "$(direc)/*"<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> mv "$file" "%%1"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 27.指定目录下搜索文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> find -name "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 28.打开文件对话框<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> %%1="$(Xdialog --fselect '~/' 0 0 2>&1)"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 29.文件分割<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> split -b 2k "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> while read f1 f2 f3<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     echo $f1 >> f1<br style="word-wrap:break-word">     echo $f2 >> f2<br style="word-wrap:break-word">     echo $f3 >> f3<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word">   linenum=`wc   -l   httperr8007.log|   awk   '{print   $1}'`  <br style="word-wrap:break-word">   n1=1  <br style="word-wrap:break-word">   file=1  <br style="word-wrap:break-word">   while   [   $n1   -lt   $linenum   ]  <br style="word-wrap:break-word">   do  <br style="word-wrap:break-word">                   n2=`expr   $n1   +   999`  <br style="word-wrap:break-word">                   sed   -n   "${n1},   ${n2}p"   httperr8007.log >   file_$file.log    <br style="word-wrap:break-word">                   n1=`expr   $n2   +   1`  <br style="word-wrap:break-word">                   file=`expr   $file   +   1`  <br style="word-wrap:break-word">   done  <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 其中httperr8007.log为你想分割的大文件,file_$file.log  为分割后的文件,最后为file_1.log,file_2.log,file_3.log……,分割完后的每个文件只有1000行(参数可以自己设置)<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> split 参数:<br style="word-wrap:break-word"> -b  :后面可接欲分割成的档案大小,可加单位,例如 b, k, m 等;<br style="word-wrap:break-word"> -l  :以行数来进行分割;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #按每个文件1000行来分割除<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> split -l 1000 httperr8007.log httperr<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> httpaa,httpab,httpac ........<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #按照每个文件100K来分割<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> split -b 100k httperr8007.log http<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> httpaa,httpab,httpac ........<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> if [ $# -ne 2 ]; then<br style="word-wrap:break-word"> echo 'Usage: split file size(in bytes)'<br style="word-wrap:break-word"> exit<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> file=$1<br style="word-wrap:break-word"> size=$2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> if [ ! -f $file ]; then<br style="word-wrap:break-word"> echo "$file doesn't exist"<br style="word-wrap:break-word"> exit<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #TODO: test if $size is a valid integer<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> filesize=`/bin/ls -l $file | awk '{print $5}'`<br style="word-wrap:break-word"> echo filesize: $filesize<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> let pieces=$filesize/$size<br style="word-wrap:break-word"> let remain=$filesize-$pieces*$size<br style="word-wrap:break-word"> if [ $remain -gt 0 ]; then<br style="word-wrap:break-word"> let pieces=$pieces+1<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> echo pieces: $pieces<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> i=0<br style="word-wrap:break-word"> while [ $i -lt $pieces ];<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> echo split: $file.$i:<br style="word-wrap:break-word"> dd if=$file of=$file.$i bs=$size count=1 skip=$i<br style="word-wrap:break-word"> let i=$i+1<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> echo "#!/bin/bash" > merge<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> echo "i=0" >> merge<br style="word-wrap:break-word"> echo "while [ $i -lt $pieces ];" >> merge<br style="word-wrap:break-word"> echo "do" >> merge<br style="word-wrap:break-word"> echo " echo merge: $file.$i" >> merge<br style="word-wrap:break-word"> echo " if [ ! -f $file.$i ]; then" >> merge<br style="word-wrap:break-word"> echo " echo merge: $file.$i missed" >> merge<br style="word-wrap:break-word"> echo " rm -f $file.merged" >> merge<br style="word-wrap:break-word"> echo " exit" >> merge<br style="word-wrap:break-word"> echo " fi" >> merge<br style="word-wrap:break-word"> echo " dd if=$file.$i of=$file.merged bs=$size count=1 seek=$i" >> merge<br style="word-wrap:break-word"> echo " let i=$i+1" >> merge<br style="word-wrap:break-word"> echo "done" >> merge<br style="word-wrap:break-word"> chmod u+x merge'<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 30.文件合并<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> cp "%%1"+"%%2" "%%3"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> exec 3<f1<br style="word-wrap:break-word"> exec 4<f2<br style="word-wrap:break-word"> while read f1 <&3 && read f2 <&4<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     echo $f1 $f2 >> join.txt<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> if [ $# -ne 2 ]; then<br style="word-wrap:break-word"> echo 'Usage: split file size(in bytes)'<br style="word-wrap:break-word"> exit<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> file=$1<br style="word-wrap:break-word"> size=$2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> if [ ! -f $file ]; then<br style="word-wrap:break-word"> echo "$file doesn't exist"<br style="word-wrap:break-word"> exit<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #TODO: test if $size is a valid integer<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> filesize=`/bin/ls -l $file | awk '{print $5}'`<br style="word-wrap:break-word"> echo filesize: $filesize<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> let pieces=$filesize/$size<br style="word-wrap:break-word"> let remain=$filesize-$pieces*$size<br style="word-wrap:break-word"> if [ $remain -gt 0 ]; then<br style="word-wrap:break-word"> let pieces=$pieces+1<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> echo pieces: $pieces<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> i=0<br style="word-wrap:break-word"> while [ $i -lt $pieces ];<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> echo split: $file.$i:<br style="word-wrap:break-word"> dd if=$file of=$file.$i bs=$size count=1 skip=$i<br style="word-wrap:break-word"> let i=$i+1<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> echo "#!/bin/bash" > merge<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> echo "i=0" >> merge<br style="word-wrap:break-word"> echo "while [ $i -lt $pieces ];" >> merge<br style="word-wrap:break-word"> echo "do" >> merge<br style="word-wrap:break-word"> echo " echo merge: $file.$i" >> merge<br style="word-wrap:break-word"> echo " if [ ! -f $file.$i ]; then" >> merge<br style="word-wrap:break-word"> echo " echo merge: $file.$i missed" >> merge<br style="word-wrap:break-word"> echo " rm -f $file.merged" >> merge<br style="word-wrap:break-word"> echo " exit" >> merge<br style="word-wrap:break-word"> echo " fi" >> merge<br style="word-wrap:break-word"> echo " dd if=$file.$i of=$file.merged bs=$size count=1 seek=$i" >> merge<br style="word-wrap:break-word"> echo " let i=$i+1" >> merge<br style="word-wrap:break-word"> echo "done" >> merge<br style="word-wrap:break-word"> chmod u+x merge'<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 31.文件简单加密<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> #make test && make strings && sudo make install<br style="word-wrap:break-word"> shc -r -f %%1.sh<br style="word-wrap:break-word"> #%%1.x<br style="word-wrap:break-word"> #%%1.x.c<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 32.文件简单解密<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> #make test && make strings && sudo make install<br style="word-wrap:break-word"> shc -r -f %%1.sh<br style="word-wrap:break-word"> #%%1.x<br style="word-wrap:break-word"> #%%1.x.c<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 33.读取ini文件属性<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> if [ "$%%3" = "" ];then<br style="word-wrap:break-word">    sed -n "/\[$%%2\]/,/\[.*\]/{<br style="word-wrap:break-word">    /^\[.*\]/d<br style="word-wrap:break-word">    /^[ ]*$/d<br style="word-wrap:break-word">    s/;.*$//<br style="word-wrap:break-word">    p<br style="word-wrap:break-word">    }" $1<br style="word-wrap:break-word"> elif [ "$%%4" = "" ];then<br style="word-wrap:break-word">    sed -n "/\[$%%2\]/,/\[.*\]/{<br style="word-wrap:break-word">    /^\[.*\]/d<br style="word-wrap:break-word">    /^[ ]*$/d<br style="word-wrap:break-word">    s/;.*$//<br style="word-wrap:break-word">    s/^[ |        ]*$%%3[ | ]*=[ |   ]*\(.*\)[ |     ]*/\1/p<br style="word-wrap:break-word">    }" $1<br style="word-wrap:break-word"> else<br style="word-wrap:break-word">        if [ "$%%4" = "#" ];then<br style="word-wrap:break-word">             sed "/\[$%%2\]/,/\[.*\]/{<br style="word-wrap:break-word">             s/^[ |        ]*$%%3[ |    ]*=.*/ /<br style="word-wrap:break-word">             }p" $1 > /tmp/sed$$<br style="word-wrap:break-word">             mv /tmp/sed$$ $1<br style="word-wrap:break-word">        else<br style="word-wrap:break-word">             sed "/\[$2\]/,/\[.*\]/{<br style="word-wrap:break-word">             s/^[ |        ]*$%%3[ |    ]*=.*/$%%3=$%%4/<br style="word-wrap:break-word">             }p" $1 > /tmp/sed$$<br style="word-wrap:break-word">             mv /tmp/sed$$ $%%1<br style="word-wrap:break-word">        fi<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 34.合并一个文件下所有的文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> cat $(ls |grep -E '%%1\.') > %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find %%1 -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> for file in $path/*.c $path/*.cpp<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [[ ! "$file" =~ \*.[A-Za-z]+ ]]; then<br style="word-wrap:break-word"> #"$(path)/$(file)"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> cat <<'EOF'> combine.c<br style="word-wrap:break-word"> #include<stdio.h><br style="word-wrap:break-word"> int main()<br style="word-wrap:break-word"> {<br style="word-wrap:break-word"> FILE *f1,*f2,*f3;<br style="word-wrap:break-word"> f1=fopen("a1.txt","r");<br style="word-wrap:break-word"> f2=fopen("a2.txt","r");<br style="word-wrap:break-word"> f3=fopen("a3.txt","w");<br style="word-wrap:break-word"> int a,b;<br style="word-wrap:break-word"> a=getw(f1);   /*从a1.txt和a2.txt中分别取最小的数a和b*/<br style="word-wrap:break-word"> b=getw(f2);<br style="word-wrap:break-word"> while(!feof(f1)&&!feof(f2))  /*两个文件都没结束时,执行循环、比较*/<br style="word-wrap:break-word"> {<br style="word-wrap:break-word"> if(a<=b)<br style="word-wrap:break-word"> {<br style="word-wrap:break-word"> putw(a,f3);<br style="word-wrap:break-word"> a=getw(f1);<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> {putw(b,f3);<br style="word-wrap:break-word"> b=getw(f2);<br style="word-wrap:break-word"> }<br style="word-wrap:break-word">    }<br style="word-wrap:break-word"> if(feof(f1))  /*文件a1.txt结束时,把a2.txt中的数全部输入a3.txt*/<br style="word-wrap:break-word"> {putw(b,f3);<br style="word-wrap:break-word"> while((b=getw(f2))!=EOF)<br style="word-wrap:break-word"> putw(b,f3);<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> if(feof(f2))   /*同上*/<br style="word-wrap:break-word"> {<br style="word-wrap:break-word"> putw(a,f3);<br style="word-wrap:break-word"> while((a=getw(f1))!=EOF)<br style="word-wrap:break-word"> putw(a,f3);<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> fclose(f1);<br style="word-wrap:break-word"> fclose(f2);<br style="word-wrap:break-word"> fclose(f3);<br style="word-wrap:break-word"> printf("已完成!");<br style="word-wrap:break-word"> return 0;<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> EOF<br style="word-wrap:break-word"> gcc -o combine combine.c<br style="word-wrap:break-word"> if [ $? -eq 0 ]; then<br style="word-wrap:break-word"> ./combine<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> echo 'Compile ERROR'<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 35.写入ini文件属性<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> if [ "$%%3" = "" ];then<br style="word-wrap:break-word">    sed -n "/\[$%%2\]/,/\[.*\]/{<br style="word-wrap:break-word">    /^\[.*\]/d<br style="word-wrap:break-word">    /^[ ]*$/d<br style="word-wrap:break-word">    s/;.*$//<br style="word-wrap:break-word">    p<br style="word-wrap:break-word">    }" $1<br style="word-wrap:break-word"> elif [ "$%%4" = "" ];then<br style="word-wrap:break-word">    sed -n "/\[$%%2\]/,/\[.*\]/{<br style="word-wrap:break-word">    /^\[.*\]/d<br style="word-wrap:break-word">    /^[ ]*$/d<br style="word-wrap:break-word">    s/;.*$//<br style="word-wrap:break-word">    s/^[ |        ]*$%%3[ | ]*=[ |   ]*\(.*\)[ |     ]*/\1/p<br style="word-wrap:break-word">    }" $1<br style="word-wrap:break-word"> else<br style="word-wrap:break-word">        if [ "$%%4" = "#" ];then<br style="word-wrap:break-word">             sed "/\[$%%2\]/,/\[.*\]/{<br style="word-wrap:break-word">             s/^[ |        ]*$%%3[ |    ]*=.*/ /<br style="word-wrap:break-word">             }p" $1 > /tmp/sed$$<br style="word-wrap:break-word">             mv /tmp/sed$$ $%%1<br style="word-wrap:break-word">        else<br style="word-wrap:break-word">             sed "/\[$%%2\]/,/\[.*\]/{<br style="word-wrap:break-word">             s/^[ |        ]*$%%3[ |    ]*=.*/$%%3=$%%4/<br style="word-wrap:break-word">             }p" $1 > /tmp/sed$$<br style="word-wrap:break-word">             mv /tmp/sed$$ $%%1<br style="word-wrap:break-word">        fi<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 36.获得当前路径<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> %%1=$(pwd)<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 37.读取XML数据库<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 如何通过shell命令行读取xml文件中某个属性所对应的值?<br style="word-wrap:break-word"> 例如:<br style="word-wrap:break-word"> <key>BuildVersion</key> <string>5</string><br style="word-wrap:break-word"> 我希望能够通过Unix shell命令对属性键的名称BuildVersion进行查询,返回的结果是5,如何实现呀?<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> grep BuildVersion|sed 's/.*<.*>\([^<].*\)<.*>.*/\1/'<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 结果返回的是“BuildVersion”,而不是“5”,如果要查询BuildVersion自动返回数值5应当如何写?<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 应该没错的。试一下: echo "<key>BuildVersion</key> <string>5</string>"|grep BuildVersion|sed 's/.*<.*>\([^<].*\)<.*>.*/\1/'我在SL的终端里试,返回值是5<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 目前需要从xml文件提取数据,想做一个xmlparser.sh<br style="word-wrap:break-word"> xml 类似这样<br style="word-wrap:break-word"> <result><br style="word-wrap:break-word">    <shareinfo hostip="192.168.0.1" sharename="abcd" password="abc123"></shareinfo><br style="word-wrap:break-word"> </result><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 希望输入 xmlparser.sh a.xml hostip可以返回192.168.0.1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> if [ $# -ne 2 ];then<br style="word-wrap:break-word">    echo "Usage: $0 <xmlfile> <key>"<br style="word-wrap:break-word">    exit 0<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> grep $2 $1|awk '{print $2}'|grep -o "[0-9.]*"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 把<br style="word-wrap:break-word"> grep $2 $1|awk '{print $2}'|grep -o "[0-9.]*"<br style="word-wrap:break-word"> 改成<br style="word-wrap:break-word"> grep $2 $1|awk '{print $2}'|grep -Eo "[0-9.]+"<br style="word-wrap:break-word"> 楼上这个有问题,如果我要得到的是<br style="word-wrap:break-word"> <result><br style="word-wrap:break-word">    <shareinfo hostip="192.168.0.1" sharename="abcd" password="abc123"></shareinfo><br style="word-wrap:break-word"> </result><br style="word-wrap:break-word"> 中的sharename,那么,呵呵,就错了<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 我觉得应该先定位到第二个参数“$2”的位置,然后再提取“=”后面的内容<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 这里有个完整的实现:<br style="word-wrap:break-word"> Parse Simple XML Files using Bash – Extract Name Value Pairs and Attributes<br style="word-wrap:break-word"> http://www.humbug.in/2010/parse-simple-xml-files-using-bash-extract-name-value-pairs-and-attributes/<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 不过需要安装xmllint.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 设计到对多个xml文件进行element的读取和列表。有人做过么?<br style="word-wrap:break-word"> 举个例子,<br style="word-wrap:break-word"> 多个xml文件里面都有<br style="word-wrap:break-word"> <article><br style="word-wrap:break-word">         <title>xxx</titlel><br style="word-wrap:break-word"> </article><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 通过shell读取,然后合并到一起,再生成一个新的xml,但是其他元素不变。<br style="word-wrap:break-word"> <article><br style="word-wrap:break-word">         <title>aaa</titlel><br style="word-wrap:break-word"> </article><br style="word-wrap:break-word"> <article><br style="word-wrap:break-word">         <title>bbb</titlel><br style="word-wrap:break-word"> </article><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 如果格式异常简单,没有特例,那么可以用shell实现<br style="word-wrap:break-word"> 如果有可能格式复杂,因为shell的命令所使用的正则表达式都不支持跨行匹配,所以用shell来解决这个问题就绕圈子了。<br style="word-wrap:break-word"> 用perl来作这个工作最直接、简单。perl的XML:DOM模块是专门处理XML文件的。<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 偶倒是觉得,用PHP写Scripts也很方便,功能强大,而且,跨平台,<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> sed -n '/<article>/{<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> N;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> /\n[[:space:]]*<title>/{<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     N;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     /<article>.*<\/article>/p<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     }<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> D;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> n<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> }'<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 这小段代码能把一个xml文件中,你要的东西拿出来.<br style="word-wrap:break-word"> 你可以用for file in $*把这些信息都>>tmpfile中.<br style="word-wrap:break-word"> 然后用sed 在指定文件的指定位置用r命令把tmpfile粘贴进来~~~~<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 大思路如此^_^  我想有这个东西(只要能正确的跑出结果)后面就不难了吧...<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Name<br style="word-wrap:break-word"> xmllint — command line XML tool<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Synopsis<br style="word-wrap:break-word"> 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]<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Introduction<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> It is included in libxml2.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Options<br style="word-wrap:break-word"> --version<br style="word-wrap:break-word"> Display the version of libxml2 used.<br style="word-wrap:break-word"> --debug<br style="word-wrap:break-word"> Parse a file and output an annotated tree of the in-memory version of the document.<br style="word-wrap:break-word"> --shell<br style="word-wrap:break-word"> Run a navigating shell. Details on available commands in shell mode are below.<br style="word-wrap:break-word"> --debugent<br style="word-wrap:break-word"> Debug the entities defined in the document.<br style="word-wrap:break-word"> --copy<br style="word-wrap:break-word"> Test the internal copy implementation.<br style="word-wrap:break-word"> --recover<br style="word-wrap:break-word"> Output any parsable portions of an invalid document.<br style="word-wrap:break-word"> --noent<br style="word-wrap:break-word"> Substitute entity values for entity references. By default, xmllint leaves entity references in place.<br style="word-wrap:break-word"> --nocdata<br style="word-wrap:break-word"> Substitute CDATA section by equivalent text nodes.<br style="word-wrap:break-word"> --nsclean<br style="word-wrap:break-word"> Remove redundant namespace declarations.<br style="word-wrap:break-word"> --noout<br style="word-wrap:break-word"> Suppress output. By default, xmllint outputs the result tree.<br style="word-wrap:break-word"> --htmlout<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --nowrap<br style="word-wrap:break-word"> Do not output HTML doc wrapper.<br style="word-wrap:break-word"> --valid<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --postvalid<br style="word-wrap:break-word"> Validate after parsing is completed.<br style="word-wrap:break-word"> --dtdvalid URL<br style="word-wrap:break-word"> Use the DTD specified by URL for validation.<br style="word-wrap:break-word"> --dtdvalidfpi FPI<br style="word-wrap:break-word"> Use the DTD specified by the Public Identifier FPI for validation, note that this will require a Catalog exporting that Public Identifier to work.<br style="word-wrap:break-word"> --timing<br style="word-wrap:break-word"> Output information about the time it takes xmllint to perform the various steps.<br style="word-wrap:break-word"> --output file<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --repeat<br style="word-wrap:break-word"> Repeat 100 times, for timing or profiling.<br style="word-wrap:break-word"> --insert<br style="word-wrap:break-word"> Test for valid insertions.<br style="word-wrap:break-word"> --compress<br style="word-wrap:break-word"> Turn on gzip compression of output.<br style="word-wrap:break-word"> --html<br style="word-wrap:break-word"> Use the HTML parser.<br style="word-wrap:break-word"> --xmlout<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --push<br style="word-wrap:break-word"> Use the push mode of the parser.<br style="word-wrap:break-word"> --memory<br style="word-wrap:break-word"> Parse from memory.<br style="word-wrap:break-word"> --maxmem nnbytes<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --nowarning<br style="word-wrap:break-word"> Do not emit warnings from the parser and/or validator.<br style="word-wrap:break-word"> --noblanks<br style="word-wrap:break-word"> Drop ignorable blank spaces.<br style="word-wrap:break-word"> --format<br style="word-wrap:break-word"> Reformat and reindent the output. The $XMLLINT_INDENT environment variable controls the indentation (default value is two spaces " ").<br style="word-wrap:break-word"> --testIO<br style="word-wrap:break-word"> Test user input/output support.<br style="word-wrap:break-word"> --encode encoding<br style="word-wrap:break-word"> Output in the given encoding.<br style="word-wrap:break-word"> --catalogs<br style="word-wrap:break-word"> Use the catalogs from $SGML_CATALOG_FILES. Otherwise /etc/xml/catalog is used by default.<br style="word-wrap:break-word"> --nocatalogs<br style="word-wrap:break-word"> Do not use any catalogs.<br style="word-wrap:break-word"> --auto<br style="word-wrap:break-word"> Generate a small document for testing purposes.<br style="word-wrap:break-word"> --xinclude<br style="word-wrap:break-word"> Do XInclude processing.<br style="word-wrap:break-word"> --noxincludenode<br style="word-wrap:break-word"> Do XInclude processing but do not generate XInclude start and end nodes.<br style="word-wrap:break-word"> --loaddtd<br style="word-wrap:break-word"> Fetch external DTD.<br style="word-wrap:break-word"> --dtdattr<br style="word-wrap:break-word"> Fetch external DTD and populate the tree with inherited attributes.<br style="word-wrap:break-word"> --dropdtd<br style="word-wrap:break-word"> Remove DTD from output.<br style="word-wrap:break-word"> --stream<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --walker<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --chkregister<br style="word-wrap:break-word"> Turn on node registration. Useful for developers testing libxml2 node tracking code.<br style="word-wrap:break-word"> --pattern patternvalue<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> --relaxng schema<br style="word-wrap:break-word"> Use RelaxNG file named schema for validation.<br style="word-wrap:break-word"> --schema schema<br style="word-wrap:break-word"> Use a W3C XML Schema file named schema for validation.<br style="word-wrap:break-word"> --c14n<br style="word-wrap:break-word"> Use the W3C XML Canonicalisation (C14N) to serialize the result of parsing to stdout. It keeps comments in the result.<br style="word-wrap:break-word"> Shell<br style="word-wrap:break-word"> xmllint offers an interactive shell mode invoked with the --shell command. Available commands in shell mode include:<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> base<br style="word-wrap:break-word"> display XML base of the node<br style="word-wrap:break-word"> bye<br style="word-wrap:break-word"> leave shell<br style="word-wrap:break-word"> cat node<br style="word-wrap:break-word"> Display node if given or current node.<br style="word-wrap:break-word"> cd path<br style="word-wrap:break-word"> Change the current node to path (if given and unique) or root if no argument given.<br style="word-wrap:break-word"> dir path<br style="word-wrap:break-word"> Dumps information about the node (namespace, attributes, content).<br style="word-wrap:break-word"> du path<br style="word-wrap:break-word"> Show the structure of the subtree under path or the current node.<br style="word-wrap:break-word"> exit<br style="word-wrap:break-word"> Leave the shell.<br style="word-wrap:break-word"> help<br style="word-wrap:break-word"> Show this help.<br style="word-wrap:break-word"> free<br style="word-wrap:break-word"> Display memory usage.<br style="word-wrap:break-word"> load name<br style="word-wrap:break-word"> Load a new document with the given name.<br style="word-wrap:break-word"> ls path<br style="word-wrap:break-word"> List contents of path (if given) or the current directory.<br style="word-wrap:break-word"> pwd<br style="word-wrap:break-word"> Display the path to the current node.<br style="word-wrap:break-word"> quit<br style="word-wrap:break-word"> Leave the shell.<br style="word-wrap:break-word"> save name<br style="word-wrap:break-word"> Saves the current document to name if given or to the original name.<br style="word-wrap:break-word"> validate<br style="word-wrap:break-word"> Check the document for error.<br style="word-wrap:break-word"> write name<br style="word-wrap:break-word"> Write the current node to the given filename.<br style="word-wrap:break-word"> Catalogs<br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Debugging Catalogs<br style="word-wrap:break-word"> Setting the environment variable XML_DEBUG_CATALOG using the command "export XML_DEBUG_CATALOG=" outputs debugging information related to catalog operations.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Error Return Codes<br style="word-wrap:break-word"> On the completion of execution, Xmllint returns the following error codes:<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 0<br style="word-wrap:break-word"> No error<br style="word-wrap:break-word"> 1<br style="word-wrap:break-word"> Unclassified<br style="word-wrap:break-word"> 2<br style="word-wrap:break-word"> Error in DTD<br style="word-wrap:break-word"> 3<br style="word-wrap:break-word"> Validation error<br style="word-wrap:break-word"> 4<br style="word-wrap:break-word"> Validation error<br style="word-wrap:break-word"> 5<br style="word-wrap:break-word"> Error in schema compilation<br style="word-wrap:break-word"> 6<br style="word-wrap:break-word"> Error writing output<br style="word-wrap:break-word"> 7<br style="word-wrap:break-word"> Error in pattern (generated when [--pattern] option is used)<br style="word-wrap:break-word"> 8<br style="word-wrap:break-word"> Error in Reader registration (generated when [--chkregister] option is used)<br style="word-wrap:break-word"> 9<br style="word-wrap:break-word"> Out of memory error<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Parse Simple XML Files using Bash – Extract Name Value Pairs and Attributes<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 2 Comments<br style="word-wrap:break-word"> 1<br style="word-wrap:break-word"> Tweet<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> Pratik Sinha | July 31, 2010<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> I have written up a simple routine par***ML 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<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> xmlFile=$1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> function par***ML() {<br style="word-wrap:break-word">   elemList=( $(cat $xmlFile | tr '\n' ' ' | XMLLINT_INDENT="" xmllint --format - | /bin/grep -e "</.*>$" | while read line; do \<br style="word-wrap:break-word">     echo $line | sed -e 's/^.*<\///' | cut -d '>' -f 1; \<br style="word-wrap:break-word">   done) )<br style="word-wrap:break-word"> <br style="word-wrap:break-word">   totalNoOfTags=${#elemList[@]}; ((totalNoOfTags--))<br style="word-wrap:break-word">   suffix=$(echo ${elemList[$totalNoOfTags]} | tr -d '</>')<br style="word-wrap:break-word">   suffix="${suffix}_"<br style="word-wrap:break-word"> <br style="word-wrap:break-word">   for (( i = 0 ; i < ${#elemList[@]} ; i++ )); do<br style="word-wrap:break-word">     elem=${elemList[$i]}<br style="word-wrap:break-word">     elemLine=$(cat $xmlFile | tr '\n' ' ' | XMLLINT_INDENT="" xmllint --format - | /bin/grep "</$elem>")<br style="word-wrap:break-word">     echo $elemLine | grep -e "^</[^ ]*>$" 1>/dev/null 2>&1<br style="word-wrap:break-word">     if [ "0" = "$?" ]; then<br style="word-wrap:break-word">       continue<br style="word-wrap:break-word">     fi<br style="word-wrap:break-word">     elemVal=$(echo $elemLine | tr '\011' '\040'| sed -e 's/^[ ]*//' -e 's/^<.*>\([^<].*\)<.*>$/\1/' | sed -e 's/^[ ]*//' | sed -e 's/[ ]*$//')<br style="word-wrap:break-word">     xmlElem="${suffix}$(echo $elem | sed 's/-/_/g')"<br style="word-wrap:break-word">     eval ${xmlElem}=`echo -ne \""${elemVal}"\"`<br style="word-wrap:break-word">     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 ' ' '>'))<br style="word-wrap:break-word">     for (( j = 0 ; j < ${#attrList[@]} ; j++ )); do<br style="word-wrap:break-word">       attr=${attrList[$j]}<br style="word-wrap:break-word">       ((j++))<br style="word-wrap:break-word">       attrVal=$(echo ${attrList[$j]} | tr '>' ' ')<br style="word-wrap:break-word">       attrName=`echo -ne ${xmlElem}_${attr}`<br style="word-wrap:break-word">       eval ${attrName}=`echo -ne \""${attrVal}"\"`<br style="word-wrap:break-word">     done<br style="word-wrap:break-word">   done<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> par***ML<br style="word-wrap:break-word"> echo "$status_xyz |  $status_abc |  $status_pqr" #Variables for each  XML ELement<br style="word-wrap:break-word"> echo "$status_xyz_arg1 |  $status_abc_arg2 |  $status_pqr_arg3 | $status_pqr_arg4" #Variables for each XML Attribute<br style="word-wrap:break-word"> echo ""<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #All the variables that were produced by the par***ML function<br style="word-wrap:break-word"> set | /bin/grep -e "^$suffix"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> The XML File used for the above script example is:<br style="word-wrap:break-word"> <?xml version="1.0"?><br style="word-wrap:break-word"> <status><br style="word-wrap:break-word">   <xyz arg1="1"> a </xyz><br style="word-wrap:break-word">   <abc arg2="2"> p </abc><br style="word-wrap:break-word">   <pqr arg3="3" arg4="a phrase"> x </pqr><br style="word-wrap:break-word"> </status><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 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.<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> The output when the script is ran with the xml file as an argument is<br style="word-wrap:break-word"> @$ bash  par***ML.sh test.xml<br style="word-wrap:break-word"> a |  p |  x<br style="word-wrap:break-word"> 1 |  2 |  3 | a phrase<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> status_abc=p<br style="word-wrap:break-word"> status_abc_arg2=2<br style="word-wrap:break-word"> status_pqr=x<br style="word-wrap:break-word"> status_pqr_arg3=3<br style="word-wrap:break-word"> status_pqr_arg4='a phrase'<br style="word-wrap:break-word"> status_xyz=a<br style="word-wrap:break-word"> status_xyz_arg1=1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> This script won’t work for XML files like the one below with duplicate element names.<br style="word-wrap:break-word"> <?xml version="1.0"?><br style="word-wrap:break-word"> <status><br style="word-wrap:break-word">   <test arg1="1"> a </test><br style="word-wrap:break-word">   <test arg2="2"> p </test><br style="word-wrap:break-word">   <test arg3="3" arg4="a phrase"> x </test><br style="word-wrap:break-word"> </status><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 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>.<br style="word-wrap:break-word"> <?xml version="1.0"?><br style="word-wrap:break-word"> <status><br style="word-wrap:break-word">   <test arg1="1"><br style="word-wrap:break-word">     <test1 arg2="2">abc</test1><br style="word-wrap:break-word">   </test><br style="word-wrap:break-word"> </status><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 38.写入XML数据库<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 39.ZIP压缩文件<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> zip -r "/%%1" "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 40.ZIP解压缩<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> unzip -x "/%%1" "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 41.获得应用程序完整路径<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 42.ZIP压缩文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 43.递归删除目录下的文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rm -if "%%1/*"<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find %%1 -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> for file in $path/*.c $path/*.cpp<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [[ ! "$file" =~ \*.[A-Za-z]+ ]]; then<br style="word-wrap:break-word"> #"$(path)/$(file)"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 44.IDEA加密算法<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 45.RC6算法<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> cat <<'EOF'> rc6.c<br style="word-wrap:break-word"> #include<stdio.h><br style="word-wrap:break-word"> /* Timing data for RC6 (rc6.c)<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 128 bit key:<br style="word-wrap:break-word"> Key Setup:    1632 cycles<br style="word-wrap:break-word"> Encrypt:       270 cycles =    94.8 mbits/sec<br style="word-wrap:break-word"> Decrypt:       226 cycles =   113.3 mbits/sec<br style="word-wrap:break-word"> Mean:          248 cycles =   103.2 mbits/sec<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 192 bit key:<br style="word-wrap:break-word"> Key Setup:    1885 cycles<br style="word-wrap:break-word"> Encrypt:       267 cycles =    95.9 mbits/sec<br style="word-wrap:break-word"> Decrypt:       235 cycles =   108.9 mbits/sec<br style="word-wrap:break-word"> Mean:          251 cycles =   102.0 mbits/sec<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 256 bit key:<br style="word-wrap:break-word"> Key Setup:    1877 cycles<br style="word-wrap:break-word"> Encrypt:       270 cycles =    94.8 mbits/sec<br style="word-wrap:break-word"> Decrypt:       227 cycles =   112.8 mbits/sec<br style="word-wrap:break-word"> Mean:          249 cycles =   103.0 mbits/sec<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #include "../std_defs.h"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> static char *alg_name[] = { "rc6", "rc6.c", "rc6" };<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> char **cipher_name()<br style="word-wrap:break-word"> {<br style="word-wrap:break-word">     return alg_name;<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #define f_rnd(i,a,b,c,d)                    \<br style="word-wrap:break-word">         u = rotl(d * (d + d + 1), 5);       \<br style="word-wrap:break-word">         t = rotl(b * (b + b + 1), 5);       \<br style="word-wrap:break-word">         a = rotl(a ^ t, u) + l_key;      \<br style="word-wrap:break-word">         c = rotl(c ^ u, t) + l_key[i + 1]<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #define i_rnd(i,a,b,c,d)                    \<br style="word-wrap:break-word">         u = rotl(d * (d + d + 1), 5);       \<br style="word-wrap:break-word">         t = rotl(b * (b + b + 1), 5);       \<br style="word-wrap:break-word">         c = rotr(c - l_key[i + 1], t) ^ u;  \<br style="word-wrap:break-word">         a = rotr(a - l_key, u) ^ t<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> u4byte  l_key[44];  /* storage for the key schedule         */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> /* initialise the key schedule from the user supplied key   */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> u4byte *set_key(const u4byte in_key[], const u4byte key_len)<br style="word-wrap:break-word"> {   u4byte  i, j, k, a, b, l[8], t;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     l_key[0] = 0xb7e15163;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     for(k = 1; k < 44; ++k)<br style="word-wrap:break-word">        <br style="word-wrap:break-word">         l_key[k] = l_key[k - 1] + 0x9e3779b9;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     for(k = 0; k < key_len / 32; ++k)<br style="word-wrap:break-word"> <br style="word-wrap:break-word">         l[k] = in_key[k];<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     t = (key_len / 32) - 1; // t = (key_len / 32);<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     a = b = i = j = 0;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     for(k = 0; k < 132; ++k)<br style="word-wrap:break-word">     {   a = rotl(l_key + a + b, 3); b += a;<br style="word-wrap:break-word">         b = rotl(l[j] + b, b);<br style="word-wrap:break-word">         l_key = a; l[j] = b;<br style="word-wrap:break-word">         i = (i == 43 ? 0 : i + 1); // i = (i + 1) % 44; <br style="word-wrap:break-word">         j = (j == t ? 0 : j + 1);  // j = (j + 1) % t;<br style="word-wrap:break-word">     }<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     return l_key;<br style="word-wrap:break-word"> };<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> /* encrypt a block of text  */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> void encrypt(const u4byte in_blk[4], u4byte out_blk[4])<br style="word-wrap:break-word"> {   u4byte  a,b,c,d,t,u;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     a = in_blk[0]; b = in_blk[1] + l_key[0];<br style="word-wrap:break-word">     c = in_blk[2]; d = in_blk[3] + l_key[1];<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     f_rnd( 2,a,b,c,d); f_rnd( 4,b,c,d,a);<br style="word-wrap:break-word">     f_rnd( 6,c,d,a,b); f_rnd( 8,d,a,b,c);<br style="word-wrap:break-word">     f_rnd(10,a,b,c,d); f_rnd(12,b,c,d,a);<br style="word-wrap:break-word">     f_rnd(14,c,d,a,b); f_rnd(16,d,a,b,c);<br style="word-wrap:break-word">     f_rnd(18,a,b,c,d); f_rnd(20,b,c,d,a);<br style="word-wrap:break-word">     f_rnd(22,c,d,a,b); f_rnd(24,d,a,b,c);<br style="word-wrap:break-word">     f_rnd(26,a,b,c,d); f_rnd(28,b,c,d,a);<br style="word-wrap:break-word">     f_rnd(30,c,d,a,b); f_rnd(32,d,a,b,c);<br style="word-wrap:break-word">     f_rnd(34,a,b,c,d); f_rnd(36,b,c,d,a);<br style="word-wrap:break-word">     f_rnd(38,c,d,a,b); f_rnd(40,d,a,b,c);<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     out_blk[0] = a + l_key[42]; out_blk[1] = b;<br style="word-wrap:break-word">     out_blk[2] = c + l_key[43]; out_blk[3] = d;<br style="word-wrap:break-word"> };<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> /* decrypt a block of text  */<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> void decrypt(const u4byte in_blk[4], u4byte out_blk[4])<br style="word-wrap:break-word"> {   u4byte  a,b,c,d,t,u;<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     d = in_blk[3]; c = in_blk[2] - l_key[43];<br style="word-wrap:break-word">     b = in_blk[1]; a = in_blk[0] - l_key[42];<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     i_rnd(40,d,a,b,c); i_rnd(38,c,d,a,b);<br style="word-wrap:break-word">     i_rnd(36,b,c,d,a); i_rnd(34,a,b,c,d);<br style="word-wrap:break-word">     i_rnd(32,d,a,b,c); i_rnd(30,c,d,a,b);<br style="word-wrap:break-word">     i_rnd(28,b,c,d,a); i_rnd(26,a,b,c,d);<br style="word-wrap:break-word">     i_rnd(24,d,a,b,c); i_rnd(22,c,d,a,b);<br style="word-wrap:break-word">     i_rnd(20,b,c,d,a); i_rnd(18,a,b,c,d);<br style="word-wrap:break-word">     i_rnd(16,d,a,b,c); i_rnd(14,c,d,a,b);<br style="word-wrap:break-word">     i_rnd(12,b,c,d,a); i_rnd(10,a,b,c,d);<br style="word-wrap:break-word">     i_rnd( 8,d,a,b,c); i_rnd( 6,c,d,a,b);<br style="word-wrap:break-word">     i_rnd( 4,b,c,d,a); i_rnd( 2,a,b,c,d);<br style="word-wrap:break-word"> <br style="word-wrap:break-word">     out_blk[3] = d - l_key[1]; out_blk[2] = c;<br style="word-wrap:break-word">     out_blk[1] = b - l_key[0]; out_blk[0] = a;<br style="word-wrap:break-word"> };<br style="word-wrap:break-word"> int main()<br style="word-wrap:break-word"> {<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> return 0;<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> EOF<br style="word-wrap:break-word"> gcc -o rc6 rc6.c<br style="word-wrap:break-word"> if [ $? -eq 0 ]; then<br style="word-wrap:break-word"> ./combine<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> echo 'Compile ERROR'<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 46.Grep<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> grep -qE %%1 %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 47.直接创建多级目录<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> mkdir -p %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 48.批量重命名<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find $PWD -type f -name '*\.cpp' |sed s/'\.cpp'//g|awk '{MV = "mv"};{C = "\.c"};{ CPP="\.cpp"}; {print MV, $1 CPP , $1 C}'|sh<br style="word-wrap:break-word"> ls | awk -F '-' '{print "mv "$0" "$2}' #去掉带'-'的前缀<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 49.文本查找替换<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> sed -e 's:%%2:%%3:g' %%1<br style="word-wrap:break-word"> #sed -e 's/%%2/%%3/g' %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 50.文件关联<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 51.批量转换编码从GB2312到Unicode<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> scode="gbk"<br style="word-wrap:break-word"> dcode="ucs2"<br style="word-wrap:break-word"> for FILE in $(find $(pwd) -type f)<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> TMP_file=$(mktemp -p $(pwd))<br style="word-wrap:break-word"> if [ -f $FILE ]; then<br style="word-wrap:break-word"> Fright=$(stat -c %a $FILE)<br style="word-wrap:break-word"> Fuser=$(stat -c %U $FILE)<br style="word-wrap:break-word"> Fgrp=$(stat -c %G $FILE)<br style="word-wrap:break-word"> iconv -f $scode -t $dcode $FILE -o $TMP_file<br style="word-wrap:break-word"> mv $TMP_file $FILE<br style="word-wrap:break-word"> chmod $Fright $FILE<br style="word-wrap:break-word"> chown $Fuser.$Fgrp $FILE<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 52.设置JDK环境变量<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find "$PWD" -type f \( -iname '*.bin' \) -print0 | xargs -0 chmod +x<br style="word-wrap:break-word"> find -type f \( -iname '*.bin' \) -print |<br style="word-wrap:break-word"> while read filename<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "$filename" in<br style="word-wrap:break-word">     *.bin)<br style="word-wrap:break-word">         xterm -e "$filename" && rm -if "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=$'\n'<br style="word-wrap:break-word"> for line in `cat ~/.bashrc`<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [[ "$line" =~ .*export.* ]]; then<br style="word-wrap:break-word">     if [[ "$line" =~ .*JAVA_HOME=.* ]]; then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]]; then<br style="word-wrap:break-word">        javahome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     fi<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [[ "$line" =~ export\ PATH=\$PATH:\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin$ ]];then<br style="word-wrap:break-word">     javapath=$line<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [[ "$line" =~ export\ CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib$ ]];then<br style="word-wrap:break-word">     classpath=$line<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> if [ ! -n "$javahome" ]; then<br style="word-wrap:break-word"> sed -i '$a export JAVA_HOME='$(pwd)'/jdk1.6.0_25' ~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${javahome//\\/\\\\}':export JAVA_HOME='$(pwd)'/jdk1.6.0_32:g' ~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$javapath" ]; then<br style="word-wrap:break-word"> sed -i '$a export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin' ~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$classpath" ]; then<br style="word-wrap:break-word"> sed -i '$a export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib' ~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> shift<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=$'\n'<br style="word-wrap:break-word"> for line in `cat ~/TestBash.txt` #~/.bashrc<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">   if [[ "$line" =~ .*export.* ]]; then<br style="word-wrap:break-word">     if [[ "$line" =~ export\ CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib$ ]]; then<br style="word-wrap:break-word">       classpath=$line<br style="word-wrap:break-word">     elif [[ "$line" =~ export\ PATH=\$PATH:\$CATALINA_HOME/bin$ ]]; then<br style="word-wrap:break-word">       jbosspath=$line<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word">     if [[ "$line" =~ .*JAVA_HOME=.* ]]; then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        javahome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     elif [[ "$line" =~ .*CATALINA_HOME=.* ]];then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        catalinahome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     elif [[ "$line" =~ .*TOMCAT_HOME=.* ]];then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        tomcathome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     elif [[ "$line" =~ .*CATALINA_BASE=.* ]];then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        catalinabase=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     elif [[ "$line" =~ .*JBOSS_HOME=.* ]];then<br style="word-wrap:break-word">       if [[ "$line" =~ =(\/([0-9a-zA-Z._]+))+ ]];then<br style="word-wrap:break-word">        jbosshome=$line<br style="word-wrap:break-word">       fi<br style="word-wrap:break-word">     fi<br style="word-wrap:break-word">   elif [[ "$line" =~ ^PATH=\$PATH:\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin$ ]];then<br style="word-wrap:break-word">     javapath=$line<br style="word-wrap:break-word">   fi<br style="word-wrap:break-word">   if [[ "$line" =~ export\ CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib$ ]];then<br style="word-wrap:break-word">     classpath=$line<br style="word-wrap:break-word">   fi<br style="word-wrap:break-word">   if [[ "$line" =~ export\ PATH=\$PATH:\$JBOSS_HOME/bin$ ]];then<br style="word-wrap:break-word">     jbosspath=$line<br style="word-wrap:break-word">   fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> if [ ! -n "$javahome" ]; then<br style="word-wrap:break-word"> sed -i '$a export JAVA_HOME='$(pwd)'/jdk1.6.0_24' ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${javahome//\\/\\\\}':export JAVA_HOME='$(pwd)'/jdk1.6.0_24:g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$javapath" ]; then<br style="word-wrap:break-word"> sed -i '$a PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin' ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$classpath" ]; then<br style="word-wrap:break-word"> sed -i '$a export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib' ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$catalinahome" ]; then<br style="word-wrap:break-word"> sed -i '$a export CATALINA_HOME='$(pwd) ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${catalinahome//\\/\\\\}':export CATALINA_HOME='$(pwd)':g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$tomcathome" ]; then<br style="word-wrap:break-word"> sed -i '$a export TOMCAT_HOME='$(pwd) ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${tomcathome//\\/\\\\}':export TOMCAT_HOME='$(pwd)':g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$catalinabase" ]; then<br style="word-wrap:break-word"> sed -i '$a export CATALINA_BASE='$(pwd) ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${catalinabase//\\/\\\\}':export CATALINA_BASE='$(pwd)':g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$jbosshome" ]; then<br style="word-wrap:break-word"> sed -i '$a export JBOSS_HOME='$(pwd) ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> sed -i 's:'${jbosshome//\\/\\\\}':export JBOSS_HOME='$(pwd)':g' ~/TestBash.txt<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> if [ ! -n "$jbosspath" ]; then<br style="word-wrap:break-word"> sed -i '$a export PATH=$PATH:$CATALINA_HOME/bin' ~/TestBash.txt #~/.bashrc<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 53.批量转换编码从Unicode到GB2312<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> scode="ucs2"<br style="word-wrap:break-word"> dcode="gbk"<br style="word-wrap:break-word"> for FILE in $(find $(pwd) -type f)<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> TMP_file=$(mktemp -p $(pwd))<br style="word-wrap:break-word"> if [ -f $FILE ]; then<br style="word-wrap:break-word"> Fright=$(stat -c %a $FILE)<br style="word-wrap:break-word"> Fuser=$(stat -c %U $FILE)<br style="word-wrap:break-word"> Fgrp=$(stat -c %G $FILE)<br style="word-wrap:break-word"> iconv -f $scode -t $dcode $FILE -o $TMP_file<br style="word-wrap:break-word"> mv $TMP_file $FILE<br style="word-wrap:break-word"> chmod $Fright $FILE<br style="word-wrap:break-word"> chown $Fuser.$Fgrp $FILE<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 54.删除空文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rmdir -p %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 55.GB2312文件转UTF-8格式<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> iconv -f gbk -t utf8 %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 56.UTF-8文件转GB2312格式<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> iconv -f utf8 -t  gbk %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 57.获取文件路径的父路径<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> %%1=basename $PWD<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 58.Unicode文件转UTF-8格式<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> iconv -f ucs2 -t  utf-8 %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 59.CRC循环冗余校验<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> cat <<'EOF'> crc.c<br style="word-wrap:break-word"> #include<stdio.h><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int crc32_table[256]; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int ulPolynomial = 0x04c11db7; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int Reflect(unsigned long int ref, char ch) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   {     unsigned long int value(0); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         // 交换bit0和bit7,bit1和bit6,类推 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         for(int i = 1; i < (ch + 1); i++) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          {            if(ref & 1) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                       value |= 1 << (ch - i); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                    ref >>= 1;      } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         return value; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> } <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> init_crc32_table() <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   {     unsigned long int crc,temp; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         // 256个值 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         for(int i = 0; i <= 0xFF; i++) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          {   temp=Reflect(i, 8); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                crc32_table[i]= temp<< 24; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 for (int j = 0; j < 8; j++){ <br style="word-wrap:break-word"> <br style="word-wrap:break-word">              unsigned long int t1,t2; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   unsigned long int flag=crc32_table[i]&0x80000000; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 t1=(crc32_table[i] << 1); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 if(flag==0) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                   t2=0; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 else <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                   t2=ulPolynomial; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 crc32_table[i] =t1^t2 ;        } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                crc=crc32_table[i]; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                crc32_table[i] = Reflect(crc32_table[i], 32); <br style="word-wrap:break-word">         }<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> unsigned long GenerateCRC32(char xdata * DataBuf,unsigned long  len) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   { <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         unsigned long oldcrc32; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         unsigned long crc32; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         unsigned long oldcrc; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         unsigned  int charcnt; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          char c,t; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         oldcrc32 = 0x00000000; //初值为0 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">      charcnt=0; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          while (len--) { <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  t= (oldcrc32 >> 24) & 0xFF;   //要移出的字节的值 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">      oldcrc=crc_32_tab[t];         //根据移出的字节的值查表 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  c=DataBuf[charcnt];          //新移进来的字节值 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  oldcrc32= (oldcrc32 << 8) | c;   //将新移进来的字节值添在寄存器末字节中 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  oldcrc32=oldcrc32^oldcrc;     //将寄存器与查出的值进行xor运算 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                  charcnt++; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          crc32=oldcrc32; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          return crc32; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> } <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 参数表可以先在PC机上算出来,也可在程序初始化时完成。下面是用于计算参数表的c语言子程序,在Visual C++ 6.0下编译通过。 <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #include <stdio.h> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int crc32_table[256]; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int ulPolynomial = 0x04c11db7; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> unsigned long int Reflect(unsigned long int ref, char ch) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   {     unsigned long int value(0); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         // 交换bit0和bit7,bit1和bit6,类推 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         for(int i = 1; i < (ch + 1); i++) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          {            if(ref & 1) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                       value |= 1 << (ch - i); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                    ref >>= 1;      } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         return value; <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> int main()<br style="word-wrap:break-word"> {<br style="word-wrap:break-word">      unsigned long int crc,temp; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         // 256个值 <br style="word-wrap:break-word"> <br style="word-wrap:break-word">         for(int i = 0; i <= 0xFF; i++) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">          {<br style="word-wrap:break-word"> temp=Reflect(i, 8);<br style="word-wrap:break-word">                crc32_table[i]= temp<< 24; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 for (int j = 0; j < 8; j++){ <br style="word-wrap:break-word"> <br style="word-wrap:break-word">              unsigned long int t1,t2; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">   unsigned long int flag=crc32_table[i]&0x80000000;<br style="word-wrap:break-word">                 t1=(crc32_table[i] << 1); <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 if(flag==0) <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                   t2=0; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 else <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                   t2=ulPolynomial; <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                 crc32_table[i] =t1^t2 ;       <br style="word-wrap:break-word"> } <br style="word-wrap:break-word"> <br style="word-wrap:break-word">                crc=crc32_table[i];<br style="word-wrap:break-word">                crc32_table[i] = Reflect(crc32_table[i], 32);<br style="word-wrap:break-word">         }<br style="word-wrap:break-word"> return 0;<br style="word-wrap:break-word"> }<br style="word-wrap:break-word"> EOF<br style="word-wrap:break-word"> gcc -o crc crc.c<br style="word-wrap:break-word"> if [ $? -eq 0 ]; then<br style="word-wrap:break-word"> ./combine<br style="word-wrap:break-word"> else<br style="word-wrap:break-word"> echo 'Compile ERROR'<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 60.判断是否为空文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 61.终止程序<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> kill -KILL pidof %%1 -s<br style="word-wrap:break-word"> #killall %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 62.定时关机<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> shutdown -h %%1 & #23:00<br style="word-wrap:break-word"> #shutdown -h now<br style="word-wrap:break-word"> #halt<br style="word-wrap:break-word"> #/sbin/poweroff<br style="word-wrap:break-word"> #init 0<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 63.显示进程列表<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> ps aux<br style="word-wrap:break-word"> #fuser -l<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 64.遍历文件夹列出文件大小<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> du -sH "%%1/*"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 65.GOST算法<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 66.对目标压缩文件解压缩到指定文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 67.保存文件时重名自动生成新文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 68.打开网页<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> lynx %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 69.删除空文件夹整合操作<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 70.获取磁盘所有分区<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> df -k<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 71.激活一个程序或程序关联的文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 72.MP3播放<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> amp "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 73.WAV播放<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> amp "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 74.写图像到剪切板<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 75.从剪贴板复制图像到窗体<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 76.删除文件夹下的所有文件且不删除文件夹下的文件夹<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> rm -if "%%1/*"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 77.XML遍历结点属性值<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 78.Unicode文件转GB2312格式<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> iconv -f ucs2 -t  gbk %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 79.开源程序库Xercesc-C++代码工程中内联80.提取包含头文件列表<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 81.GB2312文件转Unicode格式<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> iconv -f gbk -t  ucs2 %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 82.Java程序打包<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 83.UTF-8文件转Unicode格式<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> iconv -f utf8 -t  ucs2 %%1 -o %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 84.创建PDF文档<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 85.创建Word文档<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 86.快速高效的文件加密<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 87.从CSV文件构造XML文档<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 88.从XML文档生成CSV文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 89.模拟键盘输入字符串<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 90.提取PDF文件中的文本<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 91.操作内存映射文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 91.1发送内存映射数据<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 91.2接收内存映射数据<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 92.重定向windows控制台程序的输出信息<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 93.基数转序数<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 94.数字月份转英文<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 95.报表相关<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 96.根据进程名获取进程ID<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> pidof %%1 -s<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 96.BCP导入<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 97.BCP导出<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 98.计算文件MD5值<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> md5sum "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 99.计算获取文件夹中文件的MD5值<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 100.复制一个目录下所有文件到一个文件夹中<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> cp $(find "%%1" -name *.*) "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 101.移动一个目录下所有文件到一个文件夹中<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> mv $(find "%%1" -name *.*) "%%2"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 102.文件RSA高级加密<br style="word-wrap:break-word"> 十进制到十六进制<br style="word-wrap:break-word"> typeset -i16 BASE_16_NUM<br style="word-wrap:break-word"> BASE_16_NUM=%%1<br style="word-wrap:break-word"> echo $BASE_16_NUM<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 八进制到十六进制<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> typeset -i16 BASE_16_NUM<br style="word-wrap:break-word"> BASE_16_NUM=8#%%1<br style="word-wrap:break-word"> echo $BASE_16_NUM<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 十进制到八进制<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> printf %o %%1; echo<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 十进制到十六进制<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> printf %x %%1; echo<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 103.计算文件大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> wc "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 104.计算文件夹的大小<br style="word-wrap:break-word"> #!/sbin/ksh<br style="word-wrap:break-word"> dir=%%1<br style="word-wrap:break-word"> (cd $dir;pwd)<br style="word-wrap:break-word"> find $dir -type d -print | du | awk '{print $2, "== ("$1/2"kb)"}' |sort -f |<br style="word-wrap:break-word"> sed -e "s,[^ /]*/([^ /]*) ==,|--1," -e"s,[^ /]*/,| ,g"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 105.快速获得当前程序的驱动器、路径、文件名和扩展名<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 106.磁盘剩余空间计算<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> df -k<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 107.获取当前程序进程ID<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> pidof %%1 -s<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 108.全盘搜索文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> #updatedb<br style="word-wrap:break-word"> #locate %%1<br style="word-wrap:break-word"> slocate %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 109.获得当前登录的用户名<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> whoami<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 110.获得所有用户名<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> who<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 111.创建MySQL管理用户<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> mysqladmin -u root password %%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.管理MySQL数据库服务器<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 112.1.启动MySQL数据库服务器<br style="word-wrap:break-word"> mysqld -console<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.2.登录MySQL数据库服务器<br style="word-wrap:break-word"> 112.2.1.登录本地MySQL数据库服务器<br style="word-wrap:break-word"> mysql -uroot -p%%1<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.2.2.登录远程MySQL数据库服务器<br style="word-wrap:break-word"> mysql -h %%1 -u %%2 -p%%3<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.3.关闭MySQL数据库服务器<br style="word-wrap:break-word"> mysqladmin -u root shutdown<br style="word-wrap:break-word"> #pkill -9 mysql<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 112.4.测试MySQL数据库服务器<br style="word-wrap:break-word"> mysqlshow || mysqlshow -u root mysql || mysqladmin version status || mysql test<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 113.MySQL执行查询<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> mysqladmin -u %%1 -p%%2 SELECT * INTO OUTFILE './bestlovesky.xls' FROM bestlovesky WHERE 1 ORDER BY id DESC  LIMIT 0, 50;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> mysql -u %%1 -p%%2 -e "SELECT * INTO OUTFILE './bestlovesky.xls' FROM bestlovesky WHERE 1 ORDER BY id DESC  LIMIT 0, 50;"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 114.创建Oracle管理用户<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> 114.1.创建新用户<br style="word-wrap:break-word"> create user test identified by test default tablespace ts_test temporary<br style="word-wrap:break-word"> tablespace temp;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 114.2.给用户角色特权<br style="word-wrap:break-word"> grant connect,resource to test;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 115.登录Oracle数据库<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> sqlplusw<br style="word-wrap:break-word"> sqlplus /nolog<br style="word-wrap:break-word"> conn username/password@Oranet<br style="word-wrap:break-word"> conn system/systempwd@whfc<br style="word-wrap:break-word"> conn sys/syspwd@whfc as sysdba<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 115.创建Oracle表空间<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> conn system@whfc01<br style="word-wrap:break-word"> create tablespace ts_test datafile '/data2/oradata/ciis/ts_test01.dbf' size<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 116.添加Oracle数据文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> alter tablespace ts_test add datafile '/data2/oradata/ciis/ts_test02.dbf' size<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 117.查看Oracle表空间大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> desc DBA_DATA_FILES<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 118.查看Oracle剩余表空间大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> desc DBA_FREE_SPACE<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 119.查看Oracle当前用户表名<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> select * from tab;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 120.Oracle创建索引<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> CREATE INDEX idx_book_bookid ON book(bookname);<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 121.Oracle创建主键约束<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> ALTER TABLE book ADD CONSTRAINT pk_book_bookid PRIMARY KEY (bookid);<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 122.Oracle显示表结构<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> desc book<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 123.Oracle查看表的索引<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> column index_name format a30<br style="word-wrap:break-word"> select table_name, index_name from user_indexes;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 124.Oracle查看索引列<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> select table_name, index_name, column_name, column_position from user_ind_columns;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 125.Oracle查看数据段占空间大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> desc user_segments<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 126.Oracle查看表占空间大小<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> select segment_name,segment_type,bytes from user_segments where segment_type='TABLE';<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 127.安全删除USB<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rundll32.exe shell32.dll,Control_RunDLL hotplug.dll<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 128.打开SQL Server Management Studio<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> sqlwb %%1.sql<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 129.MySQL数据库导出备份<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> mysqldump -u %%1 -p %%2 %%3>%%4.sql<br style="word-wrap:break-word"> mysqldump --opt test > mysql.test //将数据库test导出到mysql.test文件,后面是一个文本文件<br style="word-wrap:break-word"> mysqldump -u root -p123456 --databases dbname > mysql.dbname //就是把数据库dbname导出到文件mysql.dbname中。<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 130.MySQL数据库数据导入<br style="word-wrap:break-word"> mysql -u %%1 -p %%2 %%3<%%4.sql<br style="word-wrap:break-word"> mysqlimport -u root -p123456 < mysql.dbname<br style="word-wrap:break-word"> 将文本数据导入数据库:<br style="word-wrap:break-word"> 文本数据的字段之间用tab键隔开<br style="word-wrap:break-word"> use test<br style="word-wrap:break-word"> load data local infile "文件名" into table 表名;<br style="word-wrap:break-word"> eg: load data local infile "D:/mysql.txt" into table mytable;<br style="word-wrap:break-word"> 导入.sql 文件命令<br style="word-wrap:break-word"> use database<br style="word-wrap:break-word"> source d:/mysql.sql;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 131.MySQL数据库检查<br style="word-wrap:break-word"> mysqlcheck -o %%3 -u %%1 -p %%2<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 132.MySQL数据表文件修复<br style="word-wrap:break-word"> myisamchk -B -o %%1.myd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 1,查看数据库状态 及启动停止<br style="word-wrap:break-word"> /etc/init.d/mysqld status<br style="word-wrap:break-word"> /etc/init.d/mysqld start<br style="word-wrap:break-word"> /etc/init.d/mysqld stop<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 2,给用户配置初始密码123456:<br style="word-wrap:break-word"> mysqladmin -u root -password 123456<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 3,修改root用户密码为 abc123<br style="word-wrap:break-word"> mysqladmin -u root -p123456 password abc123<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 4,如果想去掉密码:<br style="word-wrap:break-word"> mysqladmin -u root -pabc123 password ""<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 5,root连接数据库有密码和无密码:<br style="word-wrap:break-word"> mysql -u root(-uroot) -p<br style="word-wrap:break-word"> mysql<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 6,增加用户 test1 密码 abc,让它可以在任何主机上登录,并对所有数据库有查询,插入,修改,删除的权限:<br style="word-wrap:break-word"> 格式: grant select on 数据库.* to 用户名@登录主机 identified by "密码"<br style="word-wrap:break-word"> grant select,insert,update,delete on *.* to test1@"%" Identified by "abc";<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 8,增加一个用户test2,让它只可以在localhost上登录,并可以对数据库mydb进行查询,插入,修改,删除的操作,<br style="word-wrap:break-word"> 这样用户即使使用知道test2的密码,他也无法从internet 上直接访问数据库,只能通过mysql主机上的web页面来访问。<br style="word-wrap:break-word"> grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";<br style="word-wrap:break-word"> grant select,insert,update,delete on mydb.* to test2@localhost identified by ""; 设置无密码<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 9,显示数据库列表:<br style="word-wrap:break-word"> show databases;<br style="word-wrap:break-word"> use mysql 打开库<br style="word-wrap:break-word"> show tables;<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 10,表的操作<br style="word-wrap:break-word"> describle 表名; 显示数据表的结构<br style="word-wrap:break-word"> create database 库名;<br style="word-wrap:break-word"> drop database 库名;<br style="word-wrap:break-word"> create table 表名(字段设定列表)<br style="word-wrap:break-word"> drop table 表名;<br style="word-wrap:break-word"> delete from 表名;清空表记录<br style="word-wrap:break-word"> select * from 表名; 显示表中的记录<br style="word-wrap:break-word"> insert into 表名 values(, ,)<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> alter table 表名 add column <字段名><字段选项><br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 133.检查端口占用<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> netstat -ano<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 134.Linux下检查Apache是否安装<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rpm -qa | grep httpd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 135.Linux下启动Apache服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service httpd start<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 136.Linux下停止Apache服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service httpd stop<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 137.Linux下重新启动Apache服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service httpd restart<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 138.Linux下自动加载Apache 服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> chkconfig - level 3 httpd on<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 139.Linux下不自动加载Apache 服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> chkconfig - level 3 httpd off<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 140.Linux下检查VSFTP是否安装<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rpm -qa | grep vsftpd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 141.Linux下启动VSFTP服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service vsftpd start<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 142.Linux下停止VSFTP服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service vsftpd stop<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 143.Linux下重新启动VSFTP服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service vsftpd restart<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 144.Linux下检查VSFTP是否被启动<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> pstree | grep vsftpd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 145.Linux下检查Sendmail是否安装<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> rpm -qa | grep sendmail<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 146.Linux下启动Sendmail服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service sendmail start<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 147.Linux下停止Sendmail服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service sendma stop<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 148.Linux下重新启动Sendmail服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> service sendmail restart<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 149.Linux下自动加载Sendmail 服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> chkconfig - level 3 sendmail on<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 150.Linux下不自动加载Sendmail 服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> chkconfig - level 3 sendmail off<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 151.Linux下文本图形界面配置启动服务<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> ntsysv<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 152.以数组的方式删除文件夹<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 153.GCC批量编译<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find -type f \( -iname '*.c' -o -iname '*.cpp' \) -print |<br style="word-wrap:break-word"> while read filename<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "$filename" in<br style="word-wrap:break-word">     *.c)<br style="word-wrap:break-word">       gcc "$filename" -o "$(dirname "$filename")"/"$(basename "$filename" .c)"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.cpp)<br style="word-wrap:break-word">         gcc "$filename" -o "$(dirname "$filename")"/"$(basename "$filename" .cpp)"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 154.批量赋予可执行权限<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 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<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> for file in *.sh *.pl *.bin *.run *.bundle *.rb *.py<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [[ ! "$file" =~ \*.[A-Za-z]+ ]]; then<br style="word-wrap:break-word"> chmod +x "$(file)"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $(pwd) -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> for file in $path/*.sh $path/*.pl $path/*.bin $path/*.run $path/*.bundle $path/*.rb $path/*.py<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [[ ! "$file" =~ \*.[A-Za-z]+ ]]; then<br style="word-wrap:break-word"> chmod +x "$(path)/$(file)"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 155.批量执行<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 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 |<br style="word-wrap:break-word"> while read filename<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "$filename" in<br style="word-wrap:break-word">     *.sh | *.csh | *.ksh)<br style="word-wrap:break-word"> if [ ! "./""$(basename $filename)" = $0 ]; then<br style="word-wrap:break-word">         xterm -e "$filename"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.pl)<br style="word-wrap:break-word">         xterm -e perl "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.bin | *.run | *.bundle)<br style="word-wrap:break-word">         xterm -e "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.class)<br style="word-wrap:break-word">         xterm -e java "$(dirname "$filename")"/"$(basename "$filename" .class)"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.rpm)<br style="word-wrap:break-word">         xterm -e rpm -ivh "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.rb)<br style="word-wrap:break-word">         xterm -e ruby "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.py)<br style="word-wrap:break-word">         xterm -e python "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.jar)<br style="word-wrap:break-word">         xterm -e java -jar "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> 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<br style="word-wrap:break-word"> while read file<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "${file##*.}" in<br style="word-wrap:break-word">         sh ) xterm -e """"$file"""";;<br style="word-wrap:break-word">         pl ) xterm -e perl """"$file"""";;<br style="word-wrap:break-word">         bin ) xterm -e """"$file"""";;<br style="word-wrap:break-word">         run ) xterm -e """"$file"""";;<br style="word-wrap:break-word">         bundle ) xterm -e """"$file"""";;<br style="word-wrap:break-word">         class ) xterm -e java """"${file%.*}"""";;<br style="word-wrap:break-word">         rpm ) xterm -e rpm -ivh """"$file"""";;<br style="word-wrap:break-word">         rb ) xterm -e ruby """"$file"""";;<br style="word-wrap:break-word">         py ) xterm -e python """"$file"""";;<br style="word-wrap:break-word">         jar ) xterm -e java -jar """"$file"""";;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 156.获取操作系统版本<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> uname -r<br style="word-wrap:break-word"> #uname -a<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 157.自身复制<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> cp $0 "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 158.GCC批量创建静态库<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find -type f \( -iname '*.c' -o -iname '*.cpp' \) -print |<br style="word-wrap:break-word"> while read filename<br style="word-wrap:break-word"> do<br style="word-wrap:break-word">     case "$filename" in<br style="word-wrap:break-word">     *.c)<br style="word-wrap:break-word">       g++  -c -o "$(dirname "$filename")"/"$(basename "$filename" .c)".o"" "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     *.cpp)<br style="word-wrap:break-word">       g++  -c -o "$(dirname "$filename")"/"$(basename "$filename" .cpp)".o"" "$filename"<br style="word-wrap:break-word">         ;;<br style="word-wrap:break-word">     esac<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $(pwd) -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> ar ru $path".a" $path"/*.o" && ranlib $path".a"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> find "$PWD" -type f \( -iname '*.o' \) -print0 | xargs -0 rm -if<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 159.Java批量打包EJB<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> find "$PWD" -type f \( -iname '*.java' \) -print0 | xargs -0 javac<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $(pwd) -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> jar -cvf "$(path".jar")" "$(path"/*.*")" && cp "$(path".jar")" "$(JBOSS_HOME"/server/default/deploy")"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> find "$PWD" -type f \( -iname '*.class' \) -print0 | xargs -0 rm -if<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 160.获取环境变量<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 161.dd<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> dd<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 162.显示只有小写字母的文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> ls -1|awk '/^[[:lower:]].*/'<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 163.Zip压缩目录中的所有文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> targetpath="%%2"<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> mkdir -p "$targetpath/${path:${#direc}+1}"<br style="word-wrap:break-word"> for file in $path/*<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [ -f $file ]; then<br style="word-wrap:break-word"> zip -j "$targetpath/${path:${#direc}+1}/${file:${#path}+1}.zip" "$file"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 164.Zip解压缩目录中的所有文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> targetpath="%%2"<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> mkdir -p "$targetpath/${path:${#direc}+1}"<br style="word-wrap:break-word"> unzip -x "$path/*.zip" -d "$targetpath/${path:${#direc}+1}"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 165.分布式复制文件夹<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> targetpath="%%2"<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> mkdir -p "$targetpath/${path:${#direc}+1}"<br style="word-wrap:break-word"> rm -if "$targetpath/${path:${#direc}+1}/*.tmp"<br style="word-wrap:break-word"> for file in $path/*<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> if [ -f $file ]; then<br style="word-wrap:break-word"> cp "$file" "$targetpath/${path:${#direc}+1}/${file:${#path}+1}.tmp"<br style="word-wrap:break-word"> mv "$targetpath/${path:${#direc}+1}/${file:${#path}+1}.tmp" "$targetpath/${path:${#direc}+1}/${file:${#path}+1}"<br style="word-wrap:break-word"> fi<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 166.注册反注册组件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> regsvr32 "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 167.LZMA<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 168.CAB压缩文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 169.CAB解压缩文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 170.锁定屏幕<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> RUNDLL32.exe USER32,LockWorkStation<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 171.以其它用户的身份运行程序<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 172.添加系统用户<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> useradd "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 173.删除系统用户<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> userdel "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 174.添加用户组<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> groupadd -g 2000 "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 175.删除用户组<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> groupdel "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 176.赋予管理员权限<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 177.收回管理员权限<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 178.遍历目录产生删除文件的脚本<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 179.LZW压缩文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> z<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 180.LZW解压缩文件<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> z<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 181.递归赋予目录权限<br style="word-wrap:break-word"> #!/bin/bash<br style="word-wrap:break-word"> direc="%%1" #$(pwd)<br style="word-wrap:break-word"> OLDIFS=$IFS<br style="word-wrap:break-word"> IFS=:<br style="word-wrap:break-word"> for path in $( find $direc -type d -printf "%p$IFS")<br style="word-wrap:break-word"> do<br style="word-wrap:break-word"> chown -R root.root "$path"<br style="word-wrap:break-word"> done<br style="word-wrap:break-word"> IFS=$OLDIFS<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 182.卸载RPM包<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> rpm -e  "%%1"<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 183.删除源文件中的注释<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 184.设置目录下所有文件属性为可写<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 185.统计目录下所有文件的总共行数<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> cat * |wc<br style="word-wrap:break-word"> ls *|xargs wc -l<br style="word-wrap:break-word"> find ./ -name "*c" | xargs wc -l<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 186.删除自身<br style="word-wrap:break-word"> #!/bin/rm<br style="word-wrap:break-word"> exit 65<br style="word-wrap:break-word"> #rm $0<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 187.打开终端<br style="word-wrap:break-word"> #!/bin/bash -l<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 188.弹出光驱<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> eject<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 189.收回光驱<br style="word-wrap:break-word"> #!/bin/sh<br style="word-wrap:break-word"> eject -t<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 190.磁盘总空间计算<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 191.解析CSV文件<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 192.按行保存文件为数组<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> 193.MySQL执行SQL文件<br style="word-wrap:break-word"> mysqladmin -u %%1 -p%%2 < %%3.sql<br style="word-wrap:break-word"> <br style="word-wrap:break-word"> mysql -u %%1 -p%%2 -e "SOURCE %%3.sql"</span> </div> </div> <div class="Blog_con2_1 Blog_con3_2" style="word-wrap:break-word; margin-top:50px; position:relative; line-height:22px"> <div style="word-wrap:break-word; height:30px"> <div class="bdsharebuttonbox bdshare-button-style0-16" style="word-wrap:break-word; zoom:1; height:30px"> </div> </div> </div> </div> </div> </div> </div> </div> <!--PC和WAP自适应版--> <div id="SOHUCS" sid="1283099261327654912"></div> <script type="text/javascript" src="/views/front/js/chanyan.js"></script> <!-- 文章页-底部 动态广告位 --> <div class="youdao-fixed-ad" id="detail_ad_bottom"></div> </div> <div class="col-md-3"> <div class="row" id="ad"> <!-- 文章页-右侧1 动态广告位 --> <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_1"> </div> </div> <!-- 文章页-右侧2 动态广告位 --> <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_2"></div> </div> <!-- 文章页-右侧3 动态广告位 --> <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_3"></div> </div> </div> </div> </div> </div> </div> <div class="container"> <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(Linux,shell)</h4> <div id="paradigm-article-related"> <div class="recommend-post mb30"> <ul class="widget-links"> <li><a href="/article/1835513699826233344.htm" title="android系统selinux中添加新属性property" target="_blank">android系统selinux中添加新属性property</a> <span class="text-muted">辉色投像</span> <div>1.定位/android/system/sepolicy/private/property_contexts声明属性开头:persist.charge声明属性类型:u:object_r:system_prop:s0图12.定位到android/system/sepolicy/public/domain.te删除neverallow{domain-init}default_prop:property</div> </li> <li><a href="/article/1835509391361667072.htm" title="Linux下QT开发的动态库界面弹出操作(SDL2)" target="_blank">Linux下QT开发的动态库界面弹出操作(SDL2)</a> <span class="text-muted">13jjyao</span> <a class="tag" taget="_blank" href="/search/QT%E7%B1%BB/1.htm">QT类</a><a class="tag" taget="_blank" href="/search/qt/1.htm">qt</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/sdl2/1.htm">sdl2</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>需求:操作系统为linux,开发框架为qt,做成需带界面的qt动态库,调用方为java等非qt程序难点:调用方为java等非qt程序,也就是说调用方肯定不带QApplication::exec(),缺少了这个,QTimer等事件和QT创建的窗口将不能弹出(包括opencv也是不能弹出);这与qt调用本身qt库是有本质的区别的思路:1.调用方缺QApplication::exec(),那么我们在接口</div> </li> <li><a href="/article/1835504596898902016.htm" title="linux sdl windows.h,Windows下的SDL安装" target="_blank">linux sdl windows.h,Windows下的SDL安装</a> <span class="text-muted">奔跑吧linux内核</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/sdl/1.htm">sdl</a><a class="tag" taget="_blank" href="/search/windows.h/1.htm">windows.h</a> <div>首先你要下载并安装SDL开发包。如果装在C盘下,路径为C:\SDL1.2.5如果在WINDOWS下。你可以按以下步骤:1.打开VC++,点击"Tools",Options2,点击directories选项3.选择"Includefiles"增加一个新的路径。"C:\SDL1.2.5\include"4,现在选择"Libaryfiles“增加"C:\SDL1.2.5\lib"现在你可以开始编写你的第</div> </li> <li><a href="/article/1835503965563875328.htm" title="python os.environ_python os.environ 读取和设置环境变量" target="_blank">python os.environ_python os.environ 读取和设置环境变量</a> <span class="text-muted">weixin_39605414</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/os.environ/1.htm">os.environ</a> <div>>>>importos>>>os.environ.keys()['LC_NUMERIC','GOPATH','GOROOT','GOBIN','LESSOPEN','SSH_CLIENT','LOGNAME','USER','HOME','LC_PAPER','PATH','DISPLAY','LANG','TERM','SHELL','J2REDIR','LC_MONETARY','QT_QPA</div> </li> <li><a href="/article/1835503712899002368.htm" title="linux中sdl的使用教程,sdl使用入门" target="_blank">linux中sdl的使用教程,sdl使用入门</a> <span class="text-muted">Melissa Corvinus</span> <a class="tag" taget="_blank" href="/search/linux%E4%B8%ADsdl%E7%9A%84%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/1.htm">linux中sdl的使用教程</a> <div>本文通过一个简单示例讲解SDL的基本使用流程。示例中展示一个窗口,窗口里面有个随机颜色快随机移动。当我们鼠标点击关闭按钮时间窗口关闭。基本步骤如下:1.初始化SDL并创建一个窗口。SDL_Init()初始化SDL_CreateWindow()创建窗口2.纹理渲染存储RGB和存储纹理的区别:比如一个从左到右由红色渐变到蓝色的矩形,用存储RGB的话就需要把矩形中每个点的具体颜色值存储下来;而纹理只是一</div> </li> <li><a href="/article/1835502578050363392.htm" title="PHP环境搭建详细教程" target="_blank">PHP环境搭建详细教程</a> <span class="text-muted">好看资源平台</span> <a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/php/1.htm">php</a> <div>PHP是一个流行的服务器端脚本语言,广泛用于Web开发。为了使PHP能够在本地或服务器上运行,我们需要搭建一个合适的PHP环境。本教程将结合最新资料,介绍在不同操作系统上搭建PHP开发环境的多种方法,包括Windows、macOS和Linux系统的安装步骤,以及本地和Docker环境的配置。1.PHP环境搭建概述PHP环境的搭建主要分为以下几类:集成开发环境:例如XAMPP、WAMP、MAMP,这</div> </li> <li><a href="/article/1835501948011376640.htm" title="使用 FinalShell 进行远程连接(ssh 远程连接 Linux 服务器)" target="_blank">使用 FinalShell 进行远程连接(ssh 远程连接 Linux 服务器)</a> <span class="text-muted">编程经验分享</span> <a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/1.htm">开发工具</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a><a class="tag" taget="_blank" href="/search/ssh/1.htm">ssh</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>目录前言基本使用教程新建远程连接连接主机自定义命令路由追踪前言后端开发,必然需要和服务器打交道,部署应用,排查问题,查看运行日志等等。一般服务器都是集中部署在机房中,也有一些直接是云服务器,总而言之,程序员不可能直接和服务器直接操作,一般都是通过ssh连接来登录服务器。刚接触远程连接时,使用的是XSHELL来远程连接服务器,连接上就能够操作远程服务器了,但是仅用XSHELL并没有上传下载文件的功能</div> </li> <li><a href="/article/1835493373906087936.htm" title="libyuv之linux编译" target="_blank">libyuv之linux编译</a> <span class="text-muted">jaronho</span> <a class="tag" taget="_blank" href="/search/Linux/1.htm">Linux</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a> <div>文章目录一、下载源码二、编译源码三、注意事项1、银河麒麟系统(aarch64)(1)解决armv8-a+dotprod+i8mm指令集支持问题(2)解决armv9-a+sve2指令集支持问题一、下载源码到GitHub网站下载https://github.com/lemenkov/libyuv源码,或者用直接用git克隆到本地,如:gitclonehttps://github.com/lemenko</div> </li> <li><a href="/article/1835489588169240576.htm" title="ARM驱动学习之5 LEDS驱动" target="_blank">ARM驱动学习之5 LEDS驱动</a> <span class="text-muted">JT灬新一</span> <a class="tag" taget="_blank" href="/search/%E5%B5%8C%E5%85%A5%E5%BC%8F/1.htm">嵌入式</a><a class="tag" taget="_blank" href="/search/C/1.htm">C</a><a class="tag" taget="_blank" href="/search/%E5%BA%95%E5%B1%82/1.htm">底层</a><a class="tag" taget="_blank" href="/search/arm%E5%BC%80%E5%8F%91/1.htm">arm开发</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0/1.htm">学习</a><a class="tag" taget="_blank" href="/search/%E5%8D%95%E7%89%87%E6%9C%BA/1.htm">单片机</a> <div>ARM驱动学习之5LEDS驱动知识点:•linuxGPIO申请函数和赋值函数–gpio_request–gpio_set_value•三星平台配置GPIO函数–s3c_gpio_cfgpin•GPIO配置输出模式的宏变量–S3C_GPIO_OUTPUT注意点:DRIVER_NAME和DEVICE_NAME匹配。实现步骤:1.加入需要的头文件://Linux平台的gpio头文件#include//三</div> </li> <li><a href="/article/1835485681187647488.htm" title="【华为OD技术面试真题精选 - 非技术题】 -HR面,综合面_华为od hr面" target="_blank">【华为OD技术面试真题精选 - 非技术题】 -HR面,综合面_华为od hr面</a> <span class="text-muted">一个射手座的程序媛</span> <a class="tag" taget="_blank" href="/search/%E7%A8%8B%E5%BA%8F%E5%91%98/1.htm">程序员</a><a class="tag" taget="_blank" href="/search/%E5%8D%8E%E4%B8%BAod/1.htm">华为od</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a><a class="tag" taget="_blank" href="/search/%E8%81%8C%E5%9C%BA%E5%92%8C%E5%8F%91%E5%B1%95/1.htm">职场和发展</a> <div>最后的话最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!资料预览给大家整理的视频资料:给大家整理的电子书资料:如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。需要这份系统化的资料的朋友,可以点击这里获</div> </li> <li><a href="/article/1835482277870661632.htm" title="简介Shell、zsh、bash" target="_blank">简介Shell、zsh、bash</a> <span class="text-muted">zhaosuningsn</span> <a class="tag" taget="_blank" href="/search/Shell/1.htm">Shell</a><a class="tag" taget="_blank" href="/search/zsh/1.htm">zsh</a><a class="tag" taget="_blank" href="/search/bash/1.htm">bash</a><a class="tag" taget="_blank" href="/search/shell/1.htm">shell</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/bash/1.htm">bash</a> <div>Shell是Linux和Unix的外壳,类似衣服,负责外界与Linux和Unix内核的交互联系。例如接收终端用户及各种应用程序的命令,把接收的命令翻译成内核能理解的语言,传递给内核,并把内核处理接收的命令的结果返回给外界,即Shell是外界和内核沟通的桥梁或大门。Linux和Unix提供了多种Shell,其中有种bash,当然还有其他好多种。Mac电脑中不但有bash,还有一个zsh,预装的,据说</div> </li> <li><a href="/article/1835479000600899584.htm" title="Linux MariaDB使用OpenSSL安装SSL证书" target="_blank">Linux MariaDB使用OpenSSL安装SSL证书</a> <span class="text-muted">Meta39</span> <a class="tag" taget="_blank" href="/search/MySQL/1.htm">MySQL</a><a class="tag" taget="_blank" href="/search/Oracle/1.htm">Oracle</a><a class="tag" taget="_blank" href="/search/MariaDB/1.htm">MariaDB</a><a class="tag" taget="_blank" href="/search/Linux/1.htm">Linux</a><a class="tag" taget="_blank" href="/search/Windows/1.htm">Windows</a><a class="tag" taget="_blank" href="/search/ssl/1.htm">ssl</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/mariadb/1.htm">mariadb</a> <div>进入到证书存放目录,批量删除.pem证书警告:确保已经进入到证书存放目录find.-typef-iname\*.pem-delete查看是否安装OpenSSLopensslversion没有则安装yuminstallopensslopenssl-devel开启SSL编辑/etc/my.cnf文件(没有的话就创建,但是要注意,在/etc/my.cnf.d/server.cnf配置了datadir的,</div> </li> <li><a href="/article/1835476476514889728.htm" title="Shell、Bash、Zsh这都是啥啊" target="_blank">Shell、Bash、Zsh这都是啥啊</a> <span class="text-muted">小白码上飞</span> <a class="tag" taget="_blank" href="/search/bash/1.htm">bash</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>Zsh和Bash都是我们常用的Shell,那先搞明白啥是shell吧。Shell作为一个单词,他是“壳”的意思,蛋壳坚果壳。之所以叫壳,是为了和计算机的“核”来区分,用它表示“为使用者提供的操作界面”。所以这个命名其实很形象,翻译成中文,直译过来叫“壳层”。个人认为这个叫法很奇怪,意译貌似也没有什么好的词汇来匹配。就还是叫shell吧。维基百科给的定义是:Incomputing,ashellisa</div> </li> <li><a href="/article/1835476350190841856.htm" title="ExpRe[25] bash外的其它shell:zsh和fish" target="_blank">ExpRe[25] bash外的其它shell:zsh和fish</a> <span class="text-muted">tritone</span> <a class="tag" taget="_blank" href="/search/ExpRe/1.htm">ExpRe</a><a class="tag" taget="_blank" href="/search/bash/1.htm">bash</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/ubuntu/1.htm">ubuntu</a><a class="tag" taget="_blank" href="/search/shell/1.htm">shell</a> <div>文章目录zsh基础配置实用特性插件`autojump`语法高亮自动补全fish优点缺点时效性本篇撰写时间为2021.12.15,由于计算机技术日新月异,博客中所有内容都有时效和版本限制,具体做法不一定总行得通,链接可能改动失效,各种软件的用法可能有修改。但是其中透露的思想往往是值得学习的。本篇前置:ExpRe[10]Ubuntu[2]准备神秘软件、备份恢复软件https://www.cnblogs</div> </li> <li><a href="/article/1835469294436184064.htm" title="【从浅识到熟知Linux】Linux发展史" target="_blank">【从浅识到熟知Linux】Linux发展史</a> <span class="text-muted">Jammingpro</span> <a class="tag" taget="_blank" href="/search/%E4%BB%8E%E6%B5%85%E5%AD%A6%E5%88%B0%E7%86%9F%E7%9F%A5Linux/1.htm">从浅学到熟知Linux</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a> <div>归属专栏:从浅学到熟知Linux个人主页:Jammingpro每日努力一点点,技术变化看得见文章前言:本篇文章记录Linux发展的历史,因在介绍Linux过程中涉及的其他操作系统及人物,本文对相关内容也有所介绍。文章目录Unix发展史Linux发展史开源Linux官网企业应用情况发行版本在学习Linux前,我们可能都会问Linux从哪里来?它是如何发展的。但在介绍Linux之前,需要先介绍一下Un</div> </li> <li><a href="/article/1835467782687387648.htm" title="linux 发展史" target="_blank">linux 发展史</a> <span class="text-muted">种树的猴子</span> <a class="tag" taget="_blank" href="/search/%E5%86%85%E6%A0%B8/1.htm">内核</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/1.htm">操作系统</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a> <div>linux发展史说明此前对linux认识模糊一知半解,近期通过学习将自己对于linux的发展总结一下方便大家日后的学习。那Linux是目前一款非常火热的开源操作系统,可是linux是什么时候出现的,又是因为什么样的原因被开发出来的呢。以下将对linux的发展历程进行详细的讲解。目录一、Linux发展背景二、UINIX的诞生三、UNIX的重要分支-BSD的诞生四、Minix的诞生五、GNU与Free</div> </li> <li><a href="/article/1835466523163062272.htm" title="Linux sh命令" target="_blank">Linux sh命令</a> <span class="text-muted">fengyehongWorld</span> <a class="tag" taget="_blank" href="/search/Linux/1.htm">Linux</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>目录一.基本语法二.选项2.1-c字符串中读取内容,并执行2.1.1基本用法2.1.2获取当前目录下失效的超链接2.2-x每个命令执行之前,将其打印出来2.3结合Here文档使用一.基本语法⏹Linux和Unix系统中用于执行shell脚本或运行命令的命令。sh[选项][脚本文件][参数...]⏹选项-c:从字符串中读取内容,并执行。-x:在每个命令执行之前,将其打印出来。-s:从标准流中读取内容</div> </li> <li><a href="/article/1835466270955368448.htm" title="Linux vi常用命令" target="_blank">Linux vi常用命令</a> <span class="text-muted">fengyehongWorld</span> <a class="tag" taget="_blank" href="/search/Linux/1.htm">Linux</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>参考资料viコマンド(vimコマンド)リファレンス目录一.保存系命令二.删除系命令三.移动系命令四.复制粘贴系命令一.保存系命令⏹保存并退出:wq⏹强制保存并退出:wq!⏹退出(文件未编辑):q⏹强制退出(忽略已编辑内容):q!⏹另存为:w新文件名二.删除系命令⏹删除当前行dd⏹清空整个文档gg:移动到文档顶部dG:删除到最后一行ggdG三.移动系命令⏹移动到文档顶部gg⏹移动到文档底部#方式1G</div> </li> <li><a href="/article/1835456560277581824.htm" title="简单说说关于shell中zsh和bash的选择" target="_blank">简单说说关于shell中zsh和bash的选择</a> <span class="text-muted">秋刀prince</span> <a class="tag" taget="_blank" href="/search/MacOS/1.htm">MacOS</a><a class="tag" taget="_blank" href="/search/%E5%B0%8F%E7%8C%BF%E4%BB%AC%E7%9A%84%E5%BC%80%E5%8F%91%E6%97%A5%E5%B8%B8/1.htm">小猿们的开发日常</a><a class="tag" taget="_blank" href="/search/bash/1.htm">bash</a> <div>希望文章能给到你启发和灵感~如果觉得文章对你有帮助的话,点赞+关注+收藏支持一下博主吧~阅读指南开篇说明一、基础环境说明1.1硬件环境1.2软件环境二、什么是shell、bash、zsh?2.1bash2.2zsh三、选择Bash还是Zsh?四、一些常见问题开篇说明本篇主要简单说明一下,shell中bash和zsh的区别和选择;我们经常会把这两个搞混,不知道什么时候用哪一个,以及怎么使用;一、基础</div> </li> <li><a href="/article/1835452402178813952.htm" title="Linux查看服务器日志" target="_blank">Linux查看服务器日志</a> <span class="text-muted">TPBoreas</span> <a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a> <div>一、tail这个是我最常用的一种查看方式用法如下:tail-n10test.log查询日志尾部最后10行的日志;tail-n+10test.log查询10行之后的所有日志;tail-fn10test.log循环实时查看最后1000行记录(最常用的)一般还会配合着grep用,(实时抓包)例如:tail-fn1000test.log|grep'关键字'(动态抓包)tail-fn1000test.log</div> </li> <li><a href="/article/1835443696431099904.htm" title="笋丁网页自动回复机器人V3.0.0免授权版源码" target="_blank">笋丁网页自动回复机器人V3.0.0免授权版源码</a> <span class="text-muted">希希分享</span> <a class="tag" taget="_blank" href="/search/%E8%BD%AF%E5%B8%8C%E7%BD%9158soho_cn/1.htm">软希网58soho_cn</a><a class="tag" taget="_blank" href="/search/%E6%BA%90%E7%A0%81%E8%B5%84%E6%BA%90/1.htm">源码资源</a><a class="tag" taget="_blank" href="/search/%E7%AC%8B%E4%B8%81%E7%BD%91%E9%A1%B5%E8%87%AA%E5%8A%A8%E5%9B%9E%E5%A4%8D%E6%9C%BA%E5%99%A8%E4%BA%BA/1.htm">笋丁网页自动回复机器人</a> <div>笋丁网页机器人一款可设置自动回复,默认消息,调用自定义api接口的网页机器人。此程序后端语言使用Golang,内存占用最高不超过30MB,1H1G服务器流畅运行。仅支持Linux服务器部署,不支持虚拟主机,请悉知!使用自定义api功能需要有一定的建站基础。源码下载:https://download.csdn.net/download/m0_66047725/89754250更多资源下载:关注我。安</div> </li> <li><a href="/article/1835430214394540032.htm" title="python结束子进程_如何清除python中的子进程" target="_blank">python结束子进程_如何清除python中的子进程</a> <span class="text-muted">weixin_39995943</span> <a class="tag" taget="_blank" href="/search/python%E7%BB%93%E6%9D%9F%E5%AD%90%E8%BF%9B%E7%A8%8B/1.htm">python结束子进程</a> <div>我们使用python进程来管理长时间运行的python子进程。有时需要终止子进程。kill命令不会完全终止进程,只会使其失效。运行以下脚本将演示此行为。importsubprocessp=subprocess.Popen(['sleep','400'],stdout=subprocess.PIPE,shell=False)或者p=subprocess.Popen('sleep400',stdout</div> </li> <li><a href="/article/1835417097660887040.htm" title="Linux CTF逆向入门" target="_blank">Linux CTF逆向入门</a> <span class="text-muted">蚁景网络安全</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/CTF/1.htm">CTF</a> <div>1.ELF格式我们先来看看ELF文件头,如果想详细了解,可以查看ELF的manpage文档。关于ELF更详细的说明:e_shoff:节头表的文件偏移量(字节)。如果文件没有节头表,则此成员值为零。sh_offset:表示了该section(节)离开文件头部位置的距离+-------------------+|ELFheader|---++--------->+-------------------</div> </li> <li><a href="/article/1835415332345442304.htm" title="NPM私库搭建-verdaccio(Linux)" target="_blank">NPM私库搭建-verdaccio(Linux)</a> <span class="text-muted">Beam007</span> <a class="tag" taget="_blank" href="/search/npm/1.htm">npm</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a> <div>1、安装nodelinux服务器安装nodea)、官网下载所需的node版本https://nodejs.org/dist/v14.21.0/b)、解压安装包若下载的是xxx.tar.xz文件,解压命令为tar-xvfxxx.tar.xzc)、修改环境变量修改:/etc/profile文件#SETPATHFORNODEJSexportNODE_HOME=NODEJS解压安装的路径exportPAT</div> </li> <li><a href="/article/1835400463676174336.htm" title="C++常见知识掌握" target="_blank">C++常见知识掌握</a> <span class="text-muted">nfgo</span> <a class="tag" taget="_blank" href="/search/c%2B%2B/1.htm">c++</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>1.Linux软件开发、调试与维护内核与系统结构Linux内核是操作系统的核心,负责管理硬件资源,提供系统服务,它是系统软件与硬件之间的桥梁。主要组成部分包括:进程管理:内核通过调度器分配CPU时间给各个进程,实现进程的创建、调度、终止等操作。使用进程描述符(task_struct)来存储进程信息,包括状态(就绪、运行、阻塞等)、优先级、内存映射等。内存管理:包括物理内存和虚拟内存管理。通过页表映</div> </li> <li><a href="/article/1835399577818198016.htm" title="linux脚本sed替换变量,sed 命令中替换值为shell变量" target="_blank">linux脚本sed替换变量,sed 命令中替换值为shell变量</a> <span class="text-muted">诺坎普之约</span> <a class="tag" taget="_blank" href="/search/linux%E8%84%9A%E6%9C%ACsed%E6%9B%BF%E6%8D%A2%E5%8F%98%E9%87%8F/1.htm">linux脚本sed替换变量</a> <div>文章目录sed命令中替换值为shell变量替换基本语法sed中替换使用shell变量总结参考文档sed命令中替换值为shell变量替换基本语法大家都是sed有很多用法,最多就应该是替换一些值了。让我们先回忆sed的替换语法。在sed进行替换的时候sed-i's/old/new/g'1.txtecho"hellooldfrank"|sed's/old/new/g'结果如下:hellonewfrank</div> </li> <li><a href="/article/1835398694636187648.htm" title="RK3229_Android9.0_Box 4G模块EC200A调试" target="_blank">RK3229_Android9.0_Box 4G模块EC200A调试</a> <span class="text-muted">suifen_</span> <a class="tag" taget="_blank" href="/search/%E7%BD%91%E7%BB%9C/1.htm">网络</a> <div>0、kernel修改这部分完全可以参考Linux的移植:RK3588EC200A-CN【4G模块】调试_rkec200a-cn-CSDN博客1、修改device/rockchip/rk322xdiff--gita/device.mkb/device.mkindexec6bfaa..e7c32d1100755---a/device.mk+++b/device.mk@@-105,6+105,8@@en</div> </li> <li><a href="/article/1835391382567612416.htm" title="Shell脚本中sed使用" target="_blank">Shell脚本中sed使用</a> <span class="text-muted">jcrhl321</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>目录一、sed编辑器1、sed概述2、sed的工作流程3、sed命令的常见格式4、sed命令常用操作二、sed常用命令使用1、sed打印2、sed删除3、sed替换4、sed插入与增加4、sed剪切粘贴与复制粘贴一、sed编辑器sed(StreamEDitor)是一个强大而简单的文本解析转换工具,可以读取文本,并根据指定的条件对文本内容进行编辑(删除、替换、添加、移动等),最后输出所有行或者仅输出</div> </li> <li><a href="/article/1835390878806536192.htm" title="linux 安装Sublime Text 3" target="_blank">linux 安装Sublime Text 3</a> <span class="text-muted">hhyiyuanyu</span> <a class="tag" taget="_blank" href="/search/Python%E5%AD%A6%E4%B9%A0/1.htm">Python学习</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/sublime/1.htm">sublime</a><a class="tag" taget="_blank" href="/search/text/1.htm">text</a> <div>方法/步骤打开官网http://www.sublimetext.com/3,选择64位进行下载执行命令wgethttps://download.sublimetext.com/sublime_text_3_build_3126_x64.tar.bz2进行下载3、下载完成进行解压,执行tar-xvvfsublime_text_3_build_3126_x64.tar.bz解压4、解压完成以后,移动到</div> </li> <li><a href="/article/1835381929642389504.htm" title="shell脚本中sed命令如何使用变量" target="_blank">shell脚本中sed命令如何使用变量</a> <span class="text-muted">歪歪的酒壶</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>在shell脚本中我们常常需要使用sed命令进行配置文件的更新,但是更新的内容又往往根据环境相关。值并不是固定的。这里我们介绍一种在sed命令中使用变量的方法。比如,在nginx的配置中,我们需要根据环境来更新/etc/nginx/sites-available/default中的目录配置。通常我们采用一个变量,来记录当前环境需要配置的目录比如:dist_dir=/home/dev/code/ui</div> </li> <li><a href="/article/94.htm" title="PHP,安卓,UI,java,linux视频教程合集" target="_blank">PHP,安卓,UI,java,linux视频教程合集</a> <span class="text-muted">cocos2d-x小菜</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/UI/1.htm">UI</a><a class="tag" taget="_blank" href="/search/PHP/1.htm">PHP</a><a class="tag" taget="_blank" href="/search/android/1.htm">android</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>╔-----------------------------------╗┆                           </div> </li> <li><a href="/article/221.htm" title="各表中的列名必须唯一。在表 'dbo.XXX' 中多次指定了列名 'XXX'。" target="_blank">各表中的列名必须唯一。在表 'dbo.XXX' 中多次指定了列名 'XXX'。</a> <span class="text-muted">bozch</span> <a class="tag" taget="_blank" href="/search/.net/1.htm">.net</a><a class="tag" taget="_blank" href="/search/.net+mvc/1.htm">.net mvc</a> <div>在.net mvc5中,在执行某一操作的时候,出现了如下错误:       各表中的列名必须唯一。在表 'dbo.XXX' 中多次指定了列名 'XXX'。 经查询当前的操作与错误内容无关,经过对错误信息的排查发现,事故出现在数据库迁移上。 回想过去: 在迁移之前已经对数据库进行了添加字段操作,再次进行迁移插入XXX字段的时候,就会提示如上错误。  &</div> </li> <li><a href="/article/348.htm" title="Java 对象大小的计算" target="_blank">Java 对象大小的计算</a> <span class="text-muted">e200702084</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>                          Java对象的大小 如何计算一个对象的大小呢?    </div> </li> <li><a href="/article/475.htm" title="Mybatis Spring" target="_blank">Mybatis Spring</a> <span class="text-muted">171815164</span> <a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a> <div>ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); CustomerService userService = (CustomerService) ac.getBean("customerService"); Customer cust</div> </li> <li><a href="/article/602.htm" title="JVM 不稳定参数" target="_blank">JVM 不稳定参数</a> <span class="text-muted">g21121</span> <a class="tag" taget="_blank" href="/search/jvm/1.htm">jvm</a> <div>        -XX 参数被称为不稳定参数,之所以这么叫是因为此类参数的设置很容易引起JVM 性能上的差异,使JVM 存在极大的不稳定性。当然这是在非合理设置的前提下,如果此类参数设置合理讲大大提高JVM 的性能及稳定性。        可以说“不稳定参数”</div> </li> <li><a href="/article/729.htm" title="用户自动登录网站" target="_blank">用户自动登录网站</a> <span class="text-muted">永夜-极光</span> <a class="tag" taget="_blank" href="/search/%E7%94%A8%E6%88%B7/1.htm">用户</a> <div>1.目标:实现用户登录后,再次登录就自动登录,无需用户名和密码 2.思路:将用户的信息保存为cookie            每次用户访问网站,通过filter拦截所有请求,在filter中读取所有的cookie,如果找到了保存登录信息的cookie,那么在cookie中读取登录信息,然后直接</div> </li> <li><a href="/article/856.htm" title="centos7 安装后失去win7的引导记录" target="_blank">centos7 安装后失去win7的引导记录</a> <span class="text-muted">程序员是怎么炼成的</span> <a class="tag" taget="_blank" href="/search/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/1.htm">操作系统</a> <div>1.使用root身份(必须)打开 /boot/grub2/grub.cfg 2.找到 ### BEGIN /etc/grub.d/30_os-prober ###   在后面添加    menuentry "Windows 7 (loader) (on /dev/sda1)" { </div> </li> <li><a href="/article/983.htm" title="Oracle 10g 官方中文安装帮助文档以及Oracle官方中文教程文档下载" target="_blank">Oracle 10g 官方中文安装帮助文档以及Oracle官方中文教程文档下载</a> <span class="text-muted">aijuans</span> <a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a> <div>Oracle 10g 官方中文安装帮助文档下载:http://download.csdn.net/tag/Oracle%E4%B8%AD%E6%96%87API%EF%BC%8COracle%E4%B8%AD%E6%96%87%E6%96%87%E6%A1%A3%EF%BC%8Coracle%E5%AD%A6%E4%B9%A0%E6%96%87%E6%A1%A3 Oracle 10g 官方中文教程</div> </li> <li><a href="/article/1110.htm" title="JavaEE开源快速开发平台G4Studio_V3.2发布了" target="_blank">JavaEE开源快速开发平台G4Studio_V3.2发布了</a> <span class="text-muted">無為子</span> <a class="tag" taget="_blank" href="/search/AOP/1.htm">AOP</a><a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a><a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/javaee/1.htm">javaee</a><a class="tag" taget="_blank" href="/search/G4Studio/1.htm">G4Studio</a> <div>  我非常高兴地宣布,今天我们最新的JavaEE开源快速开发平台G4Studio_V3.2版本已经正式发布。大家可以通过如下地址下载。   访问G4Studio网站 http://www.g4it.org   G4Studio_V3.2版本变更日志 功能新增 (1).新增了系统右下角滑出提示窗口功能。 (2).新增了文件资源的Zip压缩和解压缩</div> </li> <li><a href="/article/1237.htm" title="Oracle常用的单行函数应用技巧总结" target="_blank">Oracle常用的单行函数应用技巧总结</a> <span class="text-muted">百合不是茶</span> <a class="tag" taget="_blank" href="/search/%E6%97%A5%E6%9C%9F%E5%87%BD%E6%95%B0/1.htm">日期函数</a><a class="tag" taget="_blank" href="/search/%E8%BD%AC%E6%8D%A2%E5%87%BD%E6%95%B0%28%E6%A0%B8%E5%BF%83%29/1.htm">转换函数(核心)</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E5%AD%97%E5%87%BD%E6%95%B0/1.htm">数字函数</a><a class="tag" taget="_blank" href="/search/%E9%80%9A%E7%94%A8%E5%87%BD%E6%95%B0%28%E6%A0%B8%E5%BF%83%29/1.htm">通用函数(核心)</a><a class="tag" taget="_blank" href="/search/%E5%AD%97%E7%AC%A6%E5%87%BD%E6%95%B0/1.htm">字符函数</a> <div>单行函数;   字符函数,数字函数,日期函数,转换函数(核心),通用函数(核心) 一:字符函数: .UPPER(字符串) 将字符串转为大写 .LOWER (字符串) 将字符串转为小写 .INITCAP(字符串) 将首字母大写 .LENGTH (字符串) 字符串的长度 .REPLACE(字符串,'A','_') 将字符串字符A转换成_ </div> </li> <li><a href="/article/1364.htm" title="Mockito异常测试实例" target="_blank">Mockito异常测试实例</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/1.htm">单元测试</a><a class="tag" taget="_blank" href="/search/mockito/1.htm">mockito</a> <div>Mockito异常测试实例: package com.bijian.study; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Assert; import org.junit.Test; import org.mockito.</div> </li> <li><a href="/article/1491.htm" title="GA与量子恒道统计" target="_blank">GA与量子恒道统计</a> <span class="text-muted">Bill_chen</span> <a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/%E6%B5%8F%E8%A7%88%E5%99%A8/1.htm">浏览器</a><a class="tag" taget="_blank" href="/search/%E7%99%BE%E5%BA%A6/1.htm">百度</a><a class="tag" taget="_blank" href="/search/Google/1.htm">Google</a><a class="tag" taget="_blank" href="/search/%E9%98%B2%E7%81%AB%E5%A2%99/1.htm">防火墙</a> <div>前一阵子,统计**网址时,Google Analytics(GA) 和量子恒道统计(也称量子统计),数据有较大的偏差,仔细找相关资料研究了下,总结如下:   为何GA和量子网站统计(量子统计前身为雅虎统计)结果不同? 首先:没有一种网站统计工具能保证百分之百的准确出现该问题可能有以下几个原因:(1)不同的统计分析系统的算法机制不同;(2)统计代码放置的位置和前后</div> </li> <li><a href="/article/1618.htm" title="【Linux命令三】Top命令" target="_blank">【Linux命令三】Top命令</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/linux%E5%91%BD%E4%BB%A4/1.htm">linux命令</a> <div>Linux的Top命令类似于Windows的任务管理器,可以查看当前系统的运行情况,包括CPU、内存的使用情况等。如下是一个Top命令的执行结果:     top - 21:22:04 up 1 day, 23:49, 1 user, load average: 1.10, 1.66, 1.99 Tasks: 202 total, 4 running, 198 sl</div> </li> <li><a href="/article/1745.htm" title="spring四种依赖注入方式" target="_blank">spring四种依赖注入方式</a> <span class="text-muted">白糖_</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a> <div>  平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程序员实例化,而是通过spring容器帮我们new指定实例并且将实例注入到需要该对象的类中。依赖注入的另一种说法是“控制反转”,通俗的理解是:平常我们new一个实例,这个实例的控制权是我</div> </li> <li><a href="/article/1872.htm" title="angular.injector" target="_blank">angular.injector</a> <span class="text-muted">boyitech</span> <a class="tag" taget="_blank" href="/search/AngularJS/1.htm">AngularJS</a><a class="tag" taget="_blank" href="/search/AngularJS+API/1.htm">AngularJS API</a> <div>angular.injector   描述: 创建一个injector对象, 调用injector对象的方法可以获得angular的service, 或者用来做依赖注入.   使用方法: angular.injector(modules, [strictDi])   参数详解: Param Type Details mod</div> </li> <li><a href="/article/1999.htm" title="java-同步访问一个数组Integer[10],生产者不断地往数组放入整数1000,数组满时等待;消费者不断地将数组里面的数置零,数组空时等待" target="_blank">java-同步访问一个数组Integer[10],生产者不断地往数组放入整数1000,数组满时等待;消费者不断地将数组里面的数置零,数组空时等待</a> <span class="text-muted">bylijinnan</span> <a class="tag" taget="_blank" href="/search/Integer/1.htm">Integer</a> <div> public class PC { /** * 题目:生产者-消费者。 * 同步访问一个数组Integer[10],生产者不断地往数组放入整数1000,数组满时等待;消费者不断地将数组里面的数置零,数组空时等待。 */ private static final Integer[] val=new Integer[10]; private static</div> </li> <li><a href="/article/2126.htm" title="使用Struts2.2.1配置" target="_blank">使用Struts2.2.1配置</a> <span class="text-muted">Chen.H</span> <a class="tag" taget="_blank" href="/search/apache/1.htm">apache</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/Web/1.htm">Web</a><a class="tag" taget="_blank" href="/search/xml/1.htm">xml</a><a class="tag" taget="_blank" href="/search/struts/1.htm">struts</a> <div>Struts2.2.1 需要如下 jar包: commons-fileupload-1.2.1.jar commons-io-1.3.2.jar commons-logging-1.0.4.jar freemarker-2.3.16.jar javassist-3.7.ga.jar ognl-3.0.jar spring.jar struts2-core-2.2.1.jar struts2-sp</div> </li> <li><a href="/article/2253.htm" title="[职业与教育]青春之歌" target="_blank">[职业与教育]青春之歌</a> <span class="text-muted">comsci</span> <a class="tag" taget="_blank" href="/search/%E6%95%99%E8%82%B2/1.htm">教育</a> <div>        每个人都有自己的青春之歌............但是我要说的却不是青春...        大家如果在自己的职业生涯没有给自己以后创业留一点点机会,仅仅凭学历和人脉关系,是难以在竞争激烈的市场中生存下去的....   &nbs</div> </li> <li><a href="/article/2380.htm" title="oracle连接(join)中使用using关键字" target="_blank">oracle连接(join)中使用using关键字</a> <span class="text-muted">daizj</span> <a class="tag" taget="_blank" href="/search/JOIN/1.htm">JOIN</a><a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a><a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a><a class="tag" taget="_blank" href="/search/using/1.htm">using</a> <div>在oracle连接(join)中使用using关键字 34. View the Exhibit and examine the structure of the ORDERS and ORDER_ITEMS tables. Evaluate the following SQL statement: SELECT oi.order_id, product_id, order_date FRO</div> </li> <li><a href="/article/2507.htm" title="NIO示例" target="_blank">NIO示例</a> <span class="text-muted">daysinsun</span> <a class="tag" taget="_blank" href="/search/nio/1.htm">nio</a> <div>NIO服务端代码: public class NIOServer { private Selector selector; public void startServer(int port) throws IOException { ServerSocketChannel serverChannel = ServerSocketChannel.open(</div> </li> <li><a href="/article/2634.htm" title="C语言学习homework1" target="_blank">C语言学习homework1</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/c/1.htm">c</a><a class="tag" taget="_blank" href="/search/homework/1.htm">homework</a> <div>0、 课堂练习做完 1、使用sizeof计算出你所知道的所有的类型占用的空间。 int x; sizeof(x);   sizeof(int);   # include <stdio.h> int main(void) { int x1; char x2; double x3; float x4; printf(&quo</div> </li> <li><a href="/article/2761.htm" title="select in order by , mysql排序" target="_blank">select in order by , mysql排序</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a> <div>If i select like this: SELECT id FROM users WHERE id IN(3,4,8,1); This by default will select users in this order 1,3,4,8, I would like to select them in the same order that i put IN() values so: </div> </li> <li><a href="/article/2888.htm" title="页面校验-新建项目" target="_blank">页面校验-新建项目</a> <span class="text-muted">fanxiaolong</span> <a class="tag" taget="_blank" href="/search/%E9%A1%B5%E9%9D%A2%E6%A0%A1%E9%AA%8C/1.htm">页面校验</a> <div>$(document).ready( function() { var flag = true; $('#changeform').submit(function() { var projectScValNull = true; var s =""; var parent_id = $("#parent_id").v</div> </li> <li><a href="/article/3015.htm" title="Ehcache(02)——ehcache.xml简介" target="_blank">Ehcache(02)——ehcache.xml简介</a> <span class="text-muted">234390216</span> <a class="tag" taget="_blank" href="/search/ehcache/1.htm">ehcache</a><a class="tag" taget="_blank" href="/search/ehcache.xml/1.htm">ehcache.xml</a><a class="tag" taget="_blank" href="/search/%E7%AE%80%E4%BB%8B/1.htm">简介</a> <div>ehcache.xml简介          ehcache.xml文件是用来定义Ehcache的配置信息的,更准确的来说它是定义CacheManager的配置信息的。根据之前我们在《Ehcache简介》一文中对CacheManager的介绍我们知道一切Ehcache的应用都是从CacheManager开始的。在不指定配置信</div> </li> <li><a href="/article/3142.htm" title="junit 4.11中三个新功能" target="_blank">junit 4.11中三个新功能</a> <span class="text-muted">jackyrong</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>junit 4.11中两个新增的功能,首先是注解中可以参数化,比如 import static org.junit.Assert.assertEquals; import java.util.Arrays; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runn</div> </li> <li><a href="/article/3269.htm" title="国外程序员爱用苹果Mac电脑的10大理由" target="_blank">国外程序员爱用苹果Mac电脑的10大理由</a> <span class="text-muted">php教程分享</span> <a class="tag" taget="_blank" href="/search/windows/1.htm">windows</a><a class="tag" taget="_blank" href="/search/PHP/1.htm">PHP</a><a class="tag" taget="_blank" href="/search/unix/1.htm">unix</a><a class="tag" taget="_blank" href="/search/Microsoft/1.htm">Microsoft</a><a class="tag" taget="_blank" href="/search/perl/1.htm">perl</a> <div>Mac 在国外很受欢迎,尤其是在 设计/web开发/IT 人员圈子里。普通用户喜欢 Mac 可以理解,毕竟 Mac 设计美观,简单好用,没有病毒。那么为什么专业人士也对 Mac 情有独钟呢?从个人使用经验来看我想有下面几个原因: 1、Mac OS X 是基于 Unix 的 这一点太重要了,尤其是对开发人员,至少对于我来说很重要,这意味着Unix 下一堆好用的工具都可以随手捡到。如果你是个 wi</div> </li> <li><a href="/article/3396.htm" title="位运算、异或的实际应用" target="_blank">位运算、异或的实际应用</a> <span class="text-muted">wenjinglian</span> <a class="tag" taget="_blank" href="/search/%E4%BD%8D%E8%BF%90%E7%AE%97/1.htm">位运算</a> <div>一. 位操作基础,用一张表描述位操作符的应用规则并详细解释。       二. 常用位操作小技巧,有判断奇偶、交换两数、变换符号、求绝对值。       三. 位操作与空间压缩,针对筛素数进行空间压缩。    &n</div> </li> <li><a href="/article/3523.htm" title="weblogic部署项目出现的一些问题(持续补充中……)" target="_blank">weblogic部署项目出现的一些问题(持续补充中……)</a> <span class="text-muted">Everyday都不同</span> <a class="tag" taget="_blank" href="/search/weblogic%E9%83%A8%E7%BD%B2%E5%A4%B1%E8%B4%A5/1.htm">weblogic部署失败</a> <div>好吧,weblogic的问题确实……   问题一: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [zip:E:/weblogic/user_projects/domains/base_domain/serve</div> </li> <li><a href="/article/3650.htm" title="tomcat7性能调优(01)" target="_blank">tomcat7性能调优(01)</a> <span class="text-muted">toknowme</span> <a class="tag" taget="_blank" href="/search/tomcat7/1.htm">tomcat7</a> <div>    Tomcat优化: 1、最大连接数最大线程等设置 <Connector port="8082" protocol="HTTP/1.1"                useBodyEncodingForURI="t</div> </li> <li><a href="/article/3777.htm" title="PO VO DAO DTO BO TO概念与区别" target="_blank">PO VO DAO DTO BO TO概念与区别</a> <span class="text-muted">xp9802</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/DAO/1.htm">DAO</a><a class="tag" taget="_blank" href="/search/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/1.htm">设计模式</a><a class="tag" taget="_blank" href="/search/bean/1.htm">bean</a><a class="tag" taget="_blank" href="/search/%E9%A2%86%E5%9F%9F%E6%A8%A1%E5%9E%8B/1.htm">领域模型</a> <div>O/R Mapping 是 Object Relational Mapping(对象关系映射)的缩写。通俗点讲,就是将对象与关系数据库绑定,用对象来表示关系数据。在O/R Mapping的世界里,有两个基本的也是重要的东东需要了解,即VO,PO。 它们的关系应该是相互独立的,一个VO可以只是PO的部分,也可以是多个PO构成,同样也可以等同于一个PO(指的是他们的属性)。这样,PO独立出来,数据持</div> </li> </ul> </div> </div> </div> <div> <div class="container"> <div class="indexes"> <strong>按字母分类:</strong> <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a> </div> </div> </div> <footer id="footer" class="mb30 mt30"> <div class="container"> <div class="footBglm"> <a target="_blank" href="/">首页</a> - <a target="_blank" href="/custom/about.htm">关于我们</a> - <a target="_blank" href="/search/Java/1.htm">站内搜索</a> - <a target="_blank" href="/sitemap.txt">Sitemap</a> - <a target="_blank" href="/custom/delete.htm">侵权投诉</a> </div> <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved. <!-- <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>--> </div> </div> </footer> <!-- 代码高亮 --> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script> <link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/> <script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script> </body> </html>