LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: KornLee

【shell脚本欣赏区】:[展示你的作品的好去处!欢迎投帖]

[复制链接]
发表于 2003-10-1 02:39:15 | 显示全部楼层
一个用mplayer听音乐的简单脚本。
特别感谢原创者: devel
-------------------------------------------------
#!/usr/local/bin/bash
#date:2003/10/1
mount /mnt/d 2>/dev/null #suppress error message
#touch /mnt/d/media/test0 2>/dev/null 。
#mv -rf `find / -name *.mp3` /mnt/d/media/test0
a=`pwd`
cd /mnt/d/media/good/
while true
do
echo "input music name: (will exit if you enter  e  ! )"
read name
if [ $name = "e" ] ; then echo "The process will exit !";cd $a;exit 0;fi
r=`echo $name|rev|cut -c1-2|rev`
m=`echo $name|rev|cut -c1-3|rev`
if [[ $r = "rm" || $m = "mp3" ]];then
if [ -r $name ];then
mplayer $name
echo "music already played complete !";sleep 3
else echo "Good bye ! Dear  This music can  not read ! You can play next time !"
fi
else echo "Can not support this type !";fi
done
#祝大家国庆节快乐!!
-----------------------------------------------
谢谢大家的帮助!有什么bug就指出。
 楼主| 发表于 2003-10-3 18:11:56 | 显示全部楼层

latex2pdf的脚本

作者:alphatan
由于本人学LaTeX也不久,所以有些功能可能没想到,欢迎大家对程序修改,适应各自的需要。本脚本已可以处理索引了,以后将会不断更新。
  1. #!/bin/bash
  2. #
  3. #   "latex2pdf.sh" is a script written in bash to make processing latex
  4. #   file easier.
  5. #   Copyright (C) 2003 alphatan<alphatan@263.net>  version 0.51
  6. #
  7. #   This program is free software; you can redistribute it and/or modify
  8. #   it under the terms of the GNU General Public License as published by
  9. #   the Free Software Foundation; either version 2 of the License, or
  10. #   (at your option) any later version.
  11. #
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program; if not, write to the Free Software
  19. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21. target=${1%.tex}
  22. action=$2
  23. declare -f dvi errorMsg ldvi lpdf lpdfmx lps lview pdf pdfmx ps view
  24. function errorMsg()
  25. {
  26.         echo -e "    Usage: ${0##*/} <filename> [action] " >&2
  27.         echo -e "         <filename> : the tex file with '.tex' extension. "
  28.         echo -e "                          This could not be ignored."
  29.         echo -e "         [action]   : the 'action' you wish to operate on the '.tex' file"
  30.         echo -e "             dvi   : process to 'dvi' output"
  31.         echo -e "             ps    : process to 'ps' output"
  32.         echo -e "             pdf   : process to 'pdf' output with 'dvipdf' command "
  33.         echo -e "             pdfmx : process to 'pdf' output with 'dvipdfmx' command "
  34.         echo -e "             view  : view the '<filename>.pdf' with 'acroread' \n"
  35.         echo -e "             The action type above could put an 'l' precede it. eg. 'ldvi' "
  36.         echo -e "        it will call the corresponding process and do a cleaning course by "
  37.         echo -e "        the end. "
  38.         echo -e "             If the 'action' is ignored, it is refer to 'lview', it would "
  39.         echo -e "        cause 'lpdfmx' and 'cleaning course', and view the '.pdf' output "
  40.         echo -e "        with 'acroread'"
  41. }
  42. if [ ! -e ${target}.tex ]; then
  43.         echo -e "ERROR!!: ${target}.tex does not exist! " >&2
  44.         errorMsg
  45.         exit 1
  46. fi
  47. function dvi()
  48. {
  49.         if latex ${target}.tex ; then
  50.                 if [ -e ${target}.idx ] ; then
  51.                         if makeindex ${target}.idx ; then
  52.                                 if latex ${target}.tex ; then
  53.                                         return 0;
  54.                                 else return 1
  55.                                 fi
  56.                         else return 1
  57.                         fi
  58.                 else
  59.                         return 0
  60.                 fi
  61.         else return 1
  62.         fi
  63. }
  64. function ps()
  65. {
  66.         if dvi ; then
  67.                 if dvips ${target}.dvi ; then
  68.                         return 0;
  69.                 else return 1
  70.                 fi
  71.         else return 1
  72.         fi
  73. }
  74. function pdf()
  75. {
  76.         if dvi ; then
  77.                 if dvipdf ${target}.dvi ; then
  78.                         return 0;
  79.                 else return 1
  80.                 fi
  81.         else return 1
  82.         fi
  83. }
  84. function pdfmx()
  85. {
  86.         if dvi ; then
  87.                 if dvipdfmx ${target}.dvi ; then
  88.                         return 0;
  89.                 else return 1
  90.                 fi
  91.         else return 1
  92.         fi
  93. }
  94. function view()
  95. {
  96.         if [ -e ${target}.pdf ] ; then
  97.                 acroread ${target}.pdf
  98.         else return 1
  99.         fi
  100. }
  101. function cleanFiles()
  102. {
  103.         echo "Cleaning process caught ... "
  104.         unset i;
  105.         for i in aux dvi idx ilg ind lof log lot pdf ps ; do
  106.                 if [ ! $i = $1 ]; then
  107.                         if [ -e ${target}.$i ]; then
  108.                                 rm -f ${target}.$i
  109.                         fi
  110.                 fi
  111.         done
  112.         unset i;
  113. }
  114. function ldvi()
  115. {
  116.         if dvi ; then
  117.                 cleanFiles dvi
  118.         else return 1
  119.         fi
  120. }
  121. function lps()
  122. {
  123.         if ps ; then
  124.                 cleanFiles ps
  125.         else return 1
  126.         fi
  127. }
  128. function lpdf()
  129. {
  130.         if pdf ; then
  131.                 cleanFiles pdf
  132.         else return 1
  133.         fi
  134. }
  135. function lpdfmx()
  136. {
  137.         if pdfmx ; then
  138.                 cleanFiles pdf
  139.         else return 1
  140.         fi
  141. }
  142. function lview()
  143. {
  144.         if lpdfmx ; then
  145.                 if acroread ${target}.pdf ; then
  146.                         cleanFiles pdf
  147.                         return 0
  148.                 else return 1
  149.                 fi
  150.         else return 1
  151.         fi
  152. }
  153. case $action in
  154.         dvi ) eval $action ;;
  155.         ps )  eval $action ;;
  156.         pdf ) eval $action ;;
  157.         pdfmx ) eval $action ;;
  158.         view ) eval $action ;;
  159.         ldvi ) eval $action ;;
  160.         lps ) eval $action ;;
  161.         lpdfmx ) eval $action ;;
  162.         lview ) eval $action ;;
  163.         '' ) eval lpdfmx ;;
  164.         * ) echo -e "Error Action type! " >&2
  165.                 errorMsg
  166.                 exit 1 ;;
  167. esac
复制代码
发表于 2003-10-18 02:36:34 | 显示全部楼层

del-and-recover 0.52 to Linux

特别感谢作者: alphatan
发信人: alphatan ([`a:lfa:ta2n]), 信区: LinuxApp
标  题: Re: del-and-recover 0.52 (1-3 del)
发信站: BBS 水木清华站 (Sat Oct 18 04:44:43 2003), 转信


写了两天,终于写完了,基本可实现如win下的“回收站”功能。
del: 删除东西用的。
  del {路径}
        路径允许通配符,允许多个路径,允许相对与绝对路径混用
lstrash: 看自己的垃圾筒内有什么。当然,一如“回收站”,如果你自己硬塞进去
        的东西它是记录不了的。
  lstrash [-n]
        显示垃圾筒里的东西,参数-n用于显示其在记录文件中的行号。
undel: 恢复用。
  undel {-ln LINENUMBER | -tn TRASHNAME | -sp SOURCEPATH}
        -ln LINUENUMBER LINENUMBER为lstrash -n显示的行号
        -tn TRASHNAME   TRASHNAME,文件在垃圾筒内的名字,记录文件的第一列。
        -sp SOURCEPATH  SOURCEPATH,删除前的原文件的绝对路径--能力有限,不能确定唯一的绝对跟径……--也就是记录文件的第二加第三列形成的路径。

【 在 alphatan ([`a:lfa:ta2n]) 的大作中提到: 】
: #!/bin/bash
: #
: #   "delset" is a set of scripts written in bash to simulate the win
: #   version of del-and-recover to Linux. This is the content of 'del'
: #   Copyright (C) 2003 alphatan<alphatan@263.net>  version 0.52
: #
: #   This program is free software; you can redistribute it and/or modify
: #   it under the terms of the GNU General Public License as published by
: #   the Free Software Foundation; either version 2 of the License, or
: #   (at your option) any later version.
: #
: ...................

--
Learning is to improve, but not to prove.


※ 来源:·BBS 水木清华站 smth.org·[FROM: 218.19.45.30]

发信人: alphatan ([`a:lfa:ta2n]), 信区: LinuxApp
标  题: del-and-recover 0.52 (1-3 del)
发信站: BBS 水木清华站 (Sat Oct 18 04:41:29 2003), 转信
  1. #!/bin/bash
  2. #
  3. #   "delset" is a set of scripts written in bash to simulate the win
  4. #   version of del-and-recover to Linux. This is the content of 'del'
  5. #   Copyright (C) 2003 alphatan<alphatan@263.net>  version 0.52
  6. #
  7. #   This program is free software; you can redistribute it and/or modify
  8. #   it under the terms of the GNU General Public License as published by
  9. #   the Free Software Foundation; either version 2 of the License, or
  10. #   (at your option) any later version.
  11. #
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program; if not, write to the Free Software
  19. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21. # Your *preparation* comes here
  22. declare -i NumberOfsourceFiles
  23. declare -f cleanTrash trashIsFull processFile appendRecordANDremoveFile
  24. declare -a sourceFiles
  25. # 对@, 1, 2, 3...之类的变量越早操作越好。
  26. sourceNumber=${#@}
  27. # 以下对IFS的操作比较简单,不会引起异常。
  28. tempIFS=$IFS
  29. IFS=$';'
  30. sourceFiles=( $@ )
  31. IFS=$tempIFS
  32. unset tempIFS
  33. NumberOfsourceFiles=${#sourceFiles[@]}
  34. # function definition begin
  35. function appendRecordANDremoveFile()
  36. {
  37.   declare baseName dirName extName
  38.   dirName="$1"
  39.   baseName="$2"
  40.   if [ "${baseName#*.}" = "${baseName}" ]; then
  41.     extName=""
  42.   else
  43.     extName=".${baseName#*.}"
  44.   fi
  45.   # 这里可以加个测试,看.Trashdbm的第一栏中有没有跟filenameInTrash一样的
  46.   # 文件名,如果有的话就再提一次随机数。
  47.   # 我这里没设的原因是,既然人家叫得说是随机数,应该相同率起码小于
  48.   # 1,000,000吧,而每次都在这测试的话,又是读文件,又是调用其它程序的,
  49.   # 浪费太多资源,所以省了这步。要求高的自己写上吧。
  50.   filenameInTrash="$(echo $RANDOM)$extName"
  51.   if [ -e ${HOME}/.Trash/.Trashdbm ] ; then
  52.     if [ -w ${HOME}/.Trash/.Trashdbm ] ; then
  53.        if mv "$dirName/$baseName" "${HOME}/.Trash/$filenameInTrash" ; then
  54.          echo -e "$filenameInTrash;$dirName;$baseName" >>$HOME/.Trash/.Trashdbm
  55.        else return 1
  56.        fi
  57.      else
  58.        echo -e "I can NOT write the Record file!" >&2
  59.        return 1
  60.      fi
  61.   elif [ -w ${HOME}/.Trash/ ] ; then
  62.      if mv "$dirName/$baseName" "${HOME}/.Trash/$filenameInTrash" ; then
  63.        echo -e "$filenameInTrash;$dirName;$baseName" >>$HOME/.Trash/.Trashdbm
  64.      else return 1
  65.      fi
  66.   else
  67.      echo -e "I can NOT write the Record file!" >&2
  68.      return 1
  69.   fi
  70. }
  71. # processFile不可以有return--否则会停了大while了。其返回值为离开本函数前最后执行的命令。
  72. function processFile()
  73. {
  74.   declare i baseName dirName
  75.   declare -i j=0
  76.   while (( $j < ${NumberOfsourceFiles} )) ; do
  77.         i="${sourceFiles[$j]}" # 虽然多了个变量,但程序看起来舒服一些。
  78.     if [ "${i#/}" = "${i}" ]; then # 测试参数给出的是绝对路径还是相对路径
  79.       i="$(pwd)/$i" # 形成绝对路径 本为相对路径
  80.       dirName=$(dirname "$i")
  81.       baseName=$(basename "$i")
  82.       if [ -e "$i" ] && [ -w "${dirName}" ]; then # 测试是否可删
  83.             appendRecordANDremoveFile "$dirName" "$baseName"
  84.       else
  85.         echo -e "!!ERROR!!\n"$i" NOT-exist or NOT-writable!" >&2
  86.       fi
  87.     else
  88.       i="$i" # 形成绝对路径 -- 符合规划书
  89.       dirName=$(dirname "$i")
  90.       baseName=$(basename "$i")
  91.       if [ -e "$i" ] && [ -w "${dirName}" ]; then # 测试是否可删
  92.             appendRecordANDremoveFile "$dirName" "$baseName"
  93.       else
  94.         echo -e "!!ERROR!!\n"$i" NOT-exist or NOT-writable!" >&2
  95.       fi
  96.     fi
  97.   let j++
  98.   done
  99. }
  100. function cleanTrash()
  101. {
  102.   if [  -x ${HOME}/.Trash ] && [ -w ${HOME}/.Trash ] ; then
  103.         rm -rf ${HOME}/.Trash/*
  104.     echo "" >${HOME}/.Trash/.Trashdbm
  105.     return 0
  106.   else
  107.     echo -e "!!ERROR!!\nI could not open your TRASH directory!\n Cleaning course FAILED!" >&2
  108.     return 1
  109.   fi
  110. }
  111. function trashIsFull()
  112. {
  113.   declare cleanResponse trashVolumn=$(du -sm ~/.Trash |awk '{print $1}')
  114.   if [ $trashVolumn -ge 501 ]; then
  115.     echo -n "!!ERROR!!\nYour Trash is out of 500M!! Clean ALL?(yes, or else)" >&2
  116.         read cleanResponse
  117.     cleanResponse=$(echo $cleanResponse |tr [A-Z] [a-z])
  118.     if [ "$cleanResponse" = 'yes' ] ; then
  119.       if cleanTrash ; then
  120.                 if processFile ; then
  121.           return 0
  122.                 else return 1
  123.                 fi
  124.           else return 1
  125.       fi
  126.     else
  127.       echo -e "I had NOT done ANY cleaning, Your Trash is still FULL!!" >&2
  128.       return 0
  129.     fi
  130.   else
  131.     if processFile ; then
  132.       return 0
  133.         else return 1
  134.         fi
  135.   fi
  136. }
  137. # function definition end
  138. # function *main* comes here
  139. trashIsFull
复制代码





--
Learning is to improve, but not to prove.


※ 来源:·BBS 水木清华站 smth.org·[FROM: 218.19.45.30]


发信人: alphatan ([`a:lfa:ta2n]), 信区: LinuxApp
标  题: del-and-recover 0.52 (2-3 lstrash)
发信站: BBS 水木清华站 (Sat Oct 18 04:42:11 2003), 转信
  1. #!/bin/bash
  2. #
  3. #   "delset" is a set of scripts written in bash to simulate the win
  4. #   version of del-and-recover to Linux. This is the content of 'lstrash'
  5. #   Copyright (C) 2003 alphatan<alphatan@263.net>  version 0.52
  6. #
  7. #   This program is free software; you can redistribute it and/or modify
  8. #   it under the terms of the GNU General Public License as published by
  9. #   the Free Software Foundation; either version 2 of the License, or
  10. #   (at your option) any later version.
  11. #
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program; if not, write to the Free Software
  19. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21. # 这里不使用getopts,只有(只允许)一个选项,没必要用那个。
  22. declare showLineNumber="$1"
  23. if [ ! -r ${HOME}/.Trash/.Trashdbm ]; then
  24.   exit 1
  25. fi
  26. if [ "$showLineNumber" = '-n' ] ; then
  27.   awk -F\; 'BEGIN{counter=1}{print counter" : " $1" => "$2"/"$3; counter++;}' ${HOME}/.Trash/.Trashdbm
  28. elif [ "$showLineNumber" = '' ] ; then
  29.   awk -F\; '{print $1" => "$2"/"$3}' ${HOME}/.Trash/.Trashdbm
  30. elif [ "$showLineNumber" = '--help' ] || [ "$showLineNumber" = '-h' ] ; then
  31.   echo -e " Usage: ${0##*/} [-n]" >&2
  32. else
  33.   echo -e "!!ERROR!!\nunknown Argument: "$showLineNumber" \n Usage: ${0##*/} [-n]" >&2
  34. fi
复制代码

--
Learning is to improve, but not to prove.


※ 来源:·BBS 水木清华站 smth.org·[FROM: 218.19.45.30]


发信人: alphatan ([`a:lfa:ta2n]), 信区: LinuxApp
标  题: del-and-recover 0.52 (3-3 undel)
发信站: BBS 水木清华站 (Sat Oct 18 04:42:57 2003), 转信
  1. #!/bin/bash
  2. #
  3. #   "delset" is a set of scripts written in bash to simulate the win
  4. #   version of del-and-recover to Linux. This is the content of 'undel'
  5. #   Copyright (C) 2003 alphatan<alphatan@263.net>  version 0.52
  6. #
  7. #   This program is free software; you can redistribute it and/or modify
  8. #   it under the terms of the GNU General Public License as published by
  9. #   the Free Software Foundation; either version 2 of the License, or
  10. #   (at your option) any later version.
  11. #
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program; if not, write to the Free Software
  19. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21. # Your *preparation* comes here
  22. declare whatDoYouWant whichFile
  23. declare -f checkArgument cleanRecord undelWithLN undelWithTN undelWithSP
  24. whatDoYouWant="$1"
  25. whichFile="$2"
  26. # function definition begin
  27. function checkArgument()
  28. {
  29.   if [ ! -z "$whichFile" ]; then
  30.     if [ "$whatDoYouWant" = '-ln' ]; then
  31.       # 测试如果以'-ln'开头,其参是否为完全整数构成。
  32.           if [ -z "$(echo $whichFile |sed -e 's/[0-9]//g')" ]; then
  33.             if [ $whichFile -gt 0 ]; then
  34.           undelWithLN $whichFile
  35.                 else
  36.                   echo -e "!!ERROR!!\nYour LINENUMBER exceed legal range." >&2
  37.                   return 1
  38.                 fi
  39.           else return 1
  40.           fi
  41.     elif [ "$whatDoYouWant" = '-tn' ]; then
  42.       undelWithTN "$whichFile"
  43.     elif [ "$whatDoYouWant" = '-sp' ]; then
  44.       undelWithSP "$whichFile"
  45.     else
  46.           # 无任何参数,则默认出错。
  47.           echo -e "!!ERROR!!\nunknown Argument: "$whatDoYouWant" \n Usage: ${0##*/} {-ln LINENUMBER | -tn TRASHNAME | -sp SOURCEPATH}" >&2
  48.       return 1
  49.     fi
  50.   else
  51.     # 没了第二个参数。
  52.         echo -e "!!ERROR!!\nArgument required. \n Usage: ${0##*/} {-ln LINENUMBER | -tn TRASHNAME | -sp SOURCEPATH}" >&2
  53.       return 1
  54.   fi
  55. }
  56. function cleanRecord()
  57. {
  58.   declare lineNumber=$1
  59.   if sed -e "${lineNumber}d" ${HOME}/.Trash/.Trashdbm >/tmp/trash.tmp ; then
  60.     if mv --force /tmp/trash.tmp ${HOME}/.Trash/.Trashdbm ; then
  61.       rm --force /tmp/trash.tmp # 如果成功返回'成功'。
  62.         else return 1
  63.         fi
  64.   else return 1
  65.   fi
  66. }
  67. function undelWithLN()
  68. {
  69.   declare -i lineNumber
  70.   declare -a operateFile
  71.   lineNumber="$1"
  72.   if [ ! -w ${HOME}/.Trash/.Trashdbm ]; then
  73.     echo -e "!!ERROR!!\nI didn't have write permittion to ${HOME}/.Trash/.Trashdbm" >&2
  74.         return 1
  75.   fi
  76.   # 暂时改变IFS,为了把文件中的记录分隔
  77.   #echo "BREAK POINT 1" >&2
  78.   declare tempIFS=$IFS
  79.   IFS=$';'
  80.   operateFile=( $(sed -ne "${lineNumber}p" ${HOME}/.Trash/.Trashdbm) )
  81.   IFS=$tempIFS
  82.   unset tempIFS
  83.   #echo "BREAK POINT 2" >&2
  84.   if [ ${#operateFile[@]} -eq 0 ]; then
  85.     echo -e "!!ERROR!!\nYour LINENUMBER exceed the record range." >&2
  86.     return 1
  87.   fi
  88.   # 测原目录是否存在并可写
  89.   if [ ! -w "${HOME}/.Trash/${operateFile[0]}" ] ; then
  90.     echo -e "!!ERROR!!\n"${HOME}/.Trash/${operateFile[0]}" seems NOT writable or exist. " >&2
  91.     # 删除记录 cleanRecord $lineNumber
  92.         # 上面不写入程序是因为mount与umount的关系,如flashram,所以可能有些记录要自己手动删除记录
  93.     return 1 # 返回出错 纵使删除记录成功与否,以后的改进版本会有不同的返回码
  94.   elif [ ! -w "${operateFile[1]}" ]; then
  95.     echo -e "!!ERROR!!\n"${operateFile[1]}" seems NOT writable or exist. " >&2
  96.     # 删除记录 cleanRecord $lineNumber
  97.     return 1 # 返回出错
  98.   else
  99.     if mv "${HOME}/.Trash/${operateFile[0]}" "${operateFile[1]}/${operateFile[2]}" ; then
  100.       echo -e "Recovery: ${HOME}/.Trash/${operateFile[0]} => ${operateFile[1]}/${operateFile[2]}" >&2
  101.       # 删除记录
  102.           cleanRecord $lineNumber # 返回代码看删除记录的返回码
  103.     else return 1
  104.     fi
  105.   fi
  106. }
  107. function undelWithTN()
  108. {
  109.   declare fileNameInTrash=$1
  110.   declare -i lineNumber
  111.   lineNumber=$(grep -n "$fileNameInTrash;" ${HOME}/.Trash/.Trashdbm | awk -F\: '{print $1}')
  112.   if [ $lineNumber -gt 0 ]; then
  113.         undelWithLN $lineNumber
  114.   else
  115.     echo -e "!!ERROR!!\n"$fileNameInTrash" is NOT found in ${HOME}/.Trash/.Trashdbm\n You might recover it yourself..." >&2
  116.         return 1
  117.   fi
  118. }
  119. function undelWithSP()
  120. {
  121.   declare fileNameInSourcePath dirName baseName
  122.   declare -i lineNumber
  123.   fileNameInSourcePath="$1"
  124.   dirName=$(dirname "$fileNameInSourcePath")
  125.   baseName=$(basename "$fileNameInSourcePath")
  126.   lineNumber=$(grep -n ";$dirName;$baseName" ${HOME}/.Trash/.Trashdbm | awk -F\: '{print $1}')
  127.   if [ $lineNumber -gt 0 ]; then
  128.         undelWithLN $lineNumber
  129.   else
  130.     echo -e "!!ERROR!!\n"$fileNameInSourcePath" is NOT found in ${HOME}/.Trash/.Trashdbm"
  131.         echo -e "If your file really exist, You might recover it yourself..." >&2
  132.         return 1
  133.   fi
  134. }
  135. # function definition end
  136. # function *main* comes here
  137. checkArgument
复制代码


--
Learning is to improve, but not to prove.


※ 来源:·BBS 水木清华站 smth.org·[FROM: 218.19.45.30]


 楼主| 发表于 2003-10-21 17:22:25 | 显示全部楼层

shell game:俄罗斯方块

特别感谢作者:飞灰橙
转自: www.chinaunix.net

运行于GNU bash, version 2.05a.0(1)-release (i686-pc-linux-gnu)
  1. #!/bin/bash
  2. # Tetris Game
  3. # 10.21.2003 xhchen<xhchen@winbond.com.tw>
  4. #color definition
  5. cRed=1
  6. cGreen=2
  7. cYellow=3
  8. cBlue=4
  9. cFuchsia=5
  10. cCyan=6
  11. cWhite=7
  12. colorTable=($cRed $cGreen $cYellow $cBlue $cFuchsia $cCyan $cWhite)
  13. #size & position
  14. iLeft=3
  15. iTop=2
  16. ((iTrayLeft = iLeft + 2))
  17. ((iTrayTop = iTop + 1))
  18. ((iTrayWidth = 10))
  19. ((iTrayHeight = 15))
  20. #style definition
  21. cBorder=$cGreen
  22. cScore=$cFuchsia
  23. cScoreValue=$cCyan
  24. #control signal
  25. sigRotate=25
  26. sigLeft=26
  27. sigRight=27
  28. sigDown=28
  29. sigAllDown=29
  30. sigExit=30
  31. box0=(0 0 0 1 1 0 1 1)
  32. box1=(0 2 1 2 2 2 3 2 1 0 1 1 1 2 1 3)
  33. box2=(0 0 0 1 1 1 1 2 0 1 1 0 1 1 2 0)
  34. box3=(0 1 0 2 1 0 1 1 0 0 1 0 1 1 2 1)
  35. box4=(0 1 0 2 1 1 2 1 1 0 1 1 1 2 2 2 0 1 1 1 2 0 2 1 0 0 1 0 1 1 1 2)
  36. box5=(0 1 1 1 2 1 2 2 1 0 1 1 1 2 2 0 0 0 0 1 1 1 2 1 0 2 1 0 1 1 1 2)
  37. box6=(0 1 1 1 1 2 2 1 1 0 1 1 1 2 2 1 0 1 1 0 1 1 2 1 0 1 1 0 1 1 1 2)
  38. box=(${box0[@]} ${box1[@]} ${box2[@]} ${box3[@]} ${box4[@]} ${box5[@]} ${box6[@]})
  39. countBox=(1 2 2 2 4 4 4)
  40. offsetBox=(0 1 3 5 7 11 15)
  41. iScoreEachLevel=50   #be greater than 7
  42. #Runtime data
  43. sig=0
  44. iScore=0
  45. iLevel=0
  46. boxNew=()   #new box
  47. cBoxNew=0   #new box color
  48. iBoxNewType=0   #new box type
  49. iBoxNewRotate=0   #new box rotate degree
  50. boxCur=()   #current box
  51. cBoxCur=0   #current box color
  52. iBoxCurType=0   #current box type
  53. iBoxCurRotate=0   #current box rotate degree
  54. boxCurX=-1   #current X position
  55. boxCurY=-1   #current Y position
  56. iMap=()
  57. for ((i = 0; i < iTrayHeight * iTrayWidth; i++)); do iMap[$i]=-1; done
  58. function RunAsKeyReceiver()
  59. {
  60.    local pidDisplayer key aKey sig cESC sTTY
  61.    pidDisplayer=$1
  62.    aKey=(0 0 0)
  63.    cESC=`echo -ne "\33"`
  64.    cSpace=`echo -ne "\40"`
  65.    sTTY=`stty -g`
  66.    
  67.    trap "MyExit;" INT TERM
  68.    trap "MyExitNoSub;" $sigExit
  69.    
  70.    echo -ne "\33[?25l"
  71.    while [[ 1 ]]
  72.    do
  73.       read -s -n 1 key
  74.       aKey[0]=${aKey[1]}
  75.       aKey[1]=${aKey[2]}
  76.       aKey[2]=$key
  77.       sig=0
  78.       if [[ $key == $cESC && ${aKey[1]} == $cESC ]]
  79.       then
  80.          MyExit
  81.       elif [[ ${aKey[0]} == $cESC && ${aKey[1]} == "[" ]]
  82.       then
  83.          if [[ $key == "A" ]]; then sig=$sigRotate
  84.          elif [[ $key == "B" ]]; then sig=$sigDown
  85.          elif [[ $key == "D" ]]; then sig=$sigLeft
  86.          elif [[ $key == "C" ]]; then sig=$sigRight
  87.          fi
  88.       elif [[ $key == "W" || $key == "w" ]]; then sig=$sigRotate
  89.       elif [[ $key == "S" || $key == "s" ]]; then sig=$sigDown
  90.       elif [[ $key == "A" || $key == "a" ]]; then sig=$sigLeft
  91.       elif [[ $key == "D" || $key == "d" ]]; then sig=$sigRight
  92.       elif [[ "[$key]" == "[]" ]]; then sig=$sigAllDown
  93.       elif [[ $key == "Q" || $key == "q" ]]
  94.       then
  95.          MyExit
  96.       fi
  97.       if [[ $sig != 0 ]]
  98.       then
  99.          kill -$sig $pidDisplayer
  100.       fi
  101.    done
  102. }
  103. function MyExitNoSub()
  104. {
  105.    local y
  106.    stty $sTTY
  107.    ((y = iTop + iTrayHeight + 4))
  108.    echo -e "\33[?25h\33[${y};0H"
  109.    exit
  110. }
  111. function MyExit()
  112. {
  113.    kill -$sigExit $pidDisplayer
  114.    MyExitNoSub
  115. }
  116. function RunAsDisplayer()
  117. {
  118.    local sigThis
  119.    InitDraw
  120.    trap "sig=$sigRotate;" $sigRotate
  121.    trap "sig=$sigLeft;" $sigLeft
  122.    trap "sig=$sigRight;" $sigRight
  123.    trap "sig=$sigDown;" $sigDown
  124.    trap "sig=$sigAllDown;" $sigAllDown
  125.    trap "ShowExit;" $sigExit
  126.    while [[ 1 ]]
  127.    do
  128.       for ((i = 0; i < 21 - iLevel; i++))
  129.       do
  130.          usleep 20000
  131.          sigThis=$sig
  132.          sig=0
  133.          if ((sigThis == sigRotate)); then BoxRotate;
  134.          elif ((sigThis == sigLeft)); then BoxLeft;
  135.          elif ((sigThis == sigRight)); then BoxRight;
  136.          elif ((sigThis == sigDown)); then BoxDown;
  137.          elif ((sigThis == sigAllDown)); then BoxAllDown;
  138.          fi
  139.       done
  140.       #kill -$sigDown $$
  141.       BoxDown
  142.    done
  143. }
  144. function BoxMove()
  145. {
  146.    local j i x y xTest yTest
  147.    yTest=$1
  148.    xTest=$2
  149.    for ((j = 0; j < 8; j += 2))
  150.    do
  151.       ((i = j + 1))
  152.       ((y = ${boxCur[$j]} + yTest))
  153.       ((x = ${boxCur[$i]} + xTest))
  154.       if (( y < 0 || y >= iTrayHeight || x < 0 || x >= iTrayWidth))
  155.       then
  156.          return 1
  157.       fi
  158.       if ((${iMap[y * iTrayWidth + x]} != -1 ))
  159.       then
  160.          return 1
  161.       fi
  162.    done
  163.    return 0;
  164. }
  165. function Box2Map()
  166. {
  167.    local j i x y xp yp line
  168.    for ((j = 0; j < 8; j += 2))
  169.    do
  170.       ((i = j + 1))
  171.       ((y = ${boxCur[$j]} + boxCurY))
  172.       ((x = ${boxCur[$i]} + boxCurX))
  173.       ((i = y * iTrayWidth + x))
  174.       iMap[$i]=$cBoxCur
  175.    done
  176.    
  177.    line=0
  178.    for ((j = iTrayWidth * iTrayHeight; j > 0; j -= iTrayWidth))
  179.    do
  180.       for ((i = j - iTrayWidth; i < j; i++))
  181.       do
  182.          if ((${iMap[$i]} == -1)); then break; fi
  183.       done
  184.       if ((i < j)); then continue; fi
  185.    
  186.       ((line++))   
  187.       for ((i = j - 1; i >= iTrayWidth; i--))
  188.       do
  189.          ((x = i - iTrayWidth))
  190.          iMap[$i]=${iMap[$x]}
  191.       done
  192.       for ((i = 0; i < iTrayWidth; i++))
  193.       do
  194.          iMap[$i]=-1
  195.       done
  196.    done
  197.    
  198.    if ((line == 0)); then return; fi
  199.    ((x = iLeft + iTrayWidth * 2 + 7))
  200.    ((y = iTop + 11))
  201.    ((iScore += line * 2 - 1))
  202.    echo -ne "\33[1m\33[3${cScoreValue}m\33[${y};${x}H${iScore}         "
  203.    if ((iScore % iScoreEachLevel < line * 2 - 1))
  204.    then
  205.       if ((iLevel < 20))
  206.       then
  207.          ((iLevel++))
  208.          ((y = iTop + 14))
  209.          echo -ne "\33[3${cScoreValue}m\33[${y};${x}H${iLevel}        "
  210.       fi
  211.    fi
  212.    echo -ne "\33[0m"
  213.    for ((y = 0; y < iTrayHeight; y++))
  214.    do
  215.       ((yp = y + iTrayTop + 1))
  216.       ((xp = iTrayLeft + 1))
  217.       ((i = y * iTrayWidth))
  218.       echo -ne "\33[${yp};${xp}H"
  219.       for ((x = 0; x < iTrayWidth; x++))
  220.       do
  221.          ((j = i + x))
  222.          if ((${iMap[$j]} == -1))
  223.          then
  224.             echo -ne "  "
  225.          else
  226.             echo -ne "\33[1m\33[3${iMap[$j]}m\33[4${iMap[$j]}m[]\33[0m"
  227.          fi
  228.       done
  229.    done
  230. }
  231. function BoxDown()
  232. {
  233.    local y s
  234.    ((y = boxCurY + 1))
  235.    if BoxMove $y $boxCurX
  236.    then
  237.       s="`DrawCurBox 0`"
  238.       ((boxCurY = y))
  239.       s="$s`DrawCurBox 1`"
  240.       echo -ne $s
  241.    else
  242.       Box2Map
  243.       RandomBox
  244.    fi
  245. }
  246. function BoxLeft()
  247. {
  248.    local x s
  249.    ((x = boxCurX - 1))
  250.    if BoxMove $boxCurY $x
  251.    then
  252.       s=`DrawCurBox 0`
  253.       ((boxCurX = x))
  254.       s=$s`DrawCurBox 1`
  255.       echo -ne $s
  256.    fi
  257. }
  258. function BoxRight()
  259. {
  260.    local x s
  261.    ((x = boxCurX + 1))
  262.    if BoxMove $boxCurY $x
  263.    then
  264.       s=`DrawCurBox 0`
  265.       ((boxCurX = x))
  266.       s=$s`DrawCurBox 1`
  267.       echo -ne $s
  268.    fi
  269. }
  270. function BoxAllDown()
  271. {
  272.    local k j i x y iDown s
  273.    iDown=$iTrayHeight
  274.    for ((j = 0; j < 8; j += 2))
  275.    do
  276.       ((i = j + 1))
  277.       ((y = ${boxCur[$j]} + boxCurY))
  278.       ((x = ${boxCur[$i]} + boxCurX))
  279.       for ((k = y + 1; k < iTrayHeight; k++))
  280.       do
  281.          ((i = k * iTrayWidth + x))
  282.          if (( ${iMap[$i]} != -1)); then break; fi
  283.       done
  284.       ((k -= y + 1))
  285.       if (( $iDown > $k )); then iDown=$k; fi
  286.    done
  287.    
  288.    s=`DrawCurBox 0`
  289.    ((boxCurY += iDown))
  290.    s=$s`DrawCurBox 1`
  291.    echo -ne $s
  292.    Box2Map
  293.    RandomBox
  294. }
  295. function BoxRotate()
  296. {
  297.    local iCount iTestRotate boxTest j i s
  298.    iCount=${countBox[$iBoxCurType]}
  299.    ((iTestRotate = iBoxCurRotate + 1))
  300.    if ((iTestRotate >= iCount))
  301.    then
  302.       ((iTestRotate = 0))
  303.    fi
  304.    for ((j = 0, i = (${offsetBox[$iBoxCurType]} + $iTestRotate) * 8; j < 8; j++, i++))
  305.    do
  306.       boxTest[$j]=${boxCur[$j]}
  307.       boxCur[$j]=${box[$i]}
  308.    done
  309.    if BoxMove $boxCurY $boxCurX
  310.    then
  311.       for ((j = 0; j < 8; j++))
  312.       do
  313.          boxCur[$j]=${boxTest[$j]}
  314.       done
  315.       s=`DrawCurBox 0`
  316.       for ((j = 0, i = (${offsetBox[$iBoxCurType]} + $iTestRotate) * 8; j < 8; j++, i++))
  317.       do
  318.          boxCur[$j]=${box[$i]}
  319.       done
  320.       s=$s`DrawCurBox 1`
  321.       echo -ne $s
  322.       iBoxCurRotate=$iTestRotate
  323.    else
  324.       for ((j = 0; j < 8; j++))
  325.       do
  326.          boxCur[$j]=${boxTest[$j]}
  327.       done
  328.    fi
  329. }
  330. function DrawCurBox()
  331. {
  332.    local i j t bDraw sBox s
  333.    bDraw=$1
  334.    s=""
  335.    if (( bDraw == 0 ))
  336.    then
  337.       sBox="\40\40"
  338.    else
  339.       sBox="[]"
  340.       s=$s"\33[1m\33[3${cBoxCur}m\33[4${cBoxCur}m"      
  341.    fi
  342.    
  343.    for ((j = 0; j < 8; j += 2))
  344.    do
  345.       ((i = iTrayTop + 1 + ${boxCur[$j]} + boxCurY))
  346.       ((t = iTrayLeft + 1 + 2 * (boxCurX + ${boxCur[$j + 1]})))
  347.       s=$s"\33[${i};${t}H${sBox}"
  348.    done
  349.    s=$s"\33[0m"
  350.    echo -n $s
  351. }
  352. function RandomBox()
  353. {
  354.    local i j t
  355.    #change current box
  356.    iBoxCurType=${iBoxNewType}
  357.    iBoxCurRotate=${iBoxNewRotate}
  358.    cBoxCur=${cBoxNew}
  359.    for ((j = 0; j < ${#boxNew[@]}; j++))
  360.    do
  361.       boxCur[$j]=${boxNew[$j]}
  362.    done
  363.    
  364.    if (( ${#boxCur[@]} == 8 ))
  365.    then
  366.       #calculate current box's starting position
  367.       for ((j = 0, t = 4; j < 8; j += 2))
  368.       do
  369.          if ((${boxCur[$j]} < t)); then t=${boxCur[$j]}; fi
  370.       done
  371.       ((boxCurY = -t))
  372.       for ((j = 1, i = -4, t = 20; j < 8; j += 2))
  373.       do
  374.          if ((${boxCur[$j]} > i)); then i=${boxCur[$j]}; fi
  375.          if ((${boxCur[$j]} < t)); then t=${boxCur[$j]}; fi
  376.       done
  377.       ((boxCurX = (iTrayWidth - 1 - i - t) / 2))
  378.       echo -ne `DrawCurBox 1`
  379.       if ! BoxMove $boxCurY $boxCurX
  380.       then
  381.          kill -$sigExit ${PPID}
  382.          ShowExit
  383.       fi
  384.    fi
  385.    
  386.    
  387.    
  388.    
  389.    #clear old box
  390.    for ((j = 0; j < 4; j++))
  391.    do
  392.       ((i = iTop + 1 + j))
  393.       ((t = iLeft + 2 * iTrayWidth + 7))
  394.       echo -ne "\33[${i};${t}H        "
  395.    done
  396.    #get a random new box
  397.    ((iBoxNewType = RANDOM % ${#offsetBox[@]}))
  398.    ((iBoxNewRotate = RANDOM % ${countBox[$iBoxNewType]}))
  399.    for ((j = 0, i = (${offsetBox[$iBoxNewType]} + $iBoxNewRotate) * 8; j < 8; j++, i++))
  400.    do
  401.       boxNew[$j]=${box[$i]};
  402.    done
  403.    ((cBoxNew = ${colorTable[RANDOM % ${#colorTable[@]}]}))
  404.    
  405.    #display new box
  406.    echo -ne "\33[1m\33[3${cBoxNew}m\33[4${cBoxNew}m"
  407.    for ((j = 0; j < 8; j += 2))
  408.    do
  409.       ((i = iTop + 1 + ${boxNew[$j]}))
  410.       ((t = iLeft + 2 * iTrayWidth + 7 + 2 * ${boxNew[$j + 1]}))
  411.       echo -ne "\33[${i};${t}H[]"
  412.    done
  413.    echo -ne "\33[0m"
  414. }
  415. function InitDraw()
  416. {
  417.    clear
  418.    RandomBox
  419.    RandomBox
  420.    local i t1 t2 t3
  421.    #draw border
  422.    echo -ne "\33[1m"
  423.    echo -ne "\33[3${cBorder}m\33[4${cBorder}m"
  424.    
  425.    ((t2 = iLeft + 1))
  426.    ((t3 = iLeft + iTrayWidth * 2 + 3))
  427.    for ((i = 0; i < iTrayHeight; i++))
  428.    do
  429.       ((t1 = i + iTop + 2))
  430.       echo -ne "\33[${t1};${t2}H||"
  431.       echo -ne "\33[${t1};${t3}H||"
  432.    done
  433.    
  434.    ((t2 = iTop + iTrayHeight + 2))
  435.    for ((i = 0; i < iTrayWidth + 2; i++))
  436.    do
  437.       ((t1 = i * 2 + iLeft + 1))
  438.       echo -ne "\33[${iTrayTop};${t1}H=="
  439.       echo -ne "\33[${t2};${t1}H=="
  440.    done
  441.    echo -ne "\33[0m"
  442.    
  443.    #draw score & level prompt
  444.    echo -ne "\33[1m"
  445.    ((t1 = iLeft + iTrayWidth * 2 + 7))
  446.    ((t2 = iTop + 10))
  447.    echo -ne "\33[3${cScore}m\33[${t2};${t1}HScore"
  448.    ((t2 = iTop + 11))
  449.    echo -ne "\33[3${cScoreValue}m\33[${t2};${t1}H${iScore}"
  450.    ((t2 = iTop + 13))
  451.    echo -ne "\33[3${cScore}m\33[${t2};${t1}HLevel"
  452.    ((t2 = iTop + 14))
  453.    echo -ne "\33[3${cScoreValue}m\33[${t2};${t1}H${iLevel}"
  454.    echo -ne "\33[0m"
  455. }
  456. function ShowExit()
  457. {
  458.    local y
  459.    ((y = iTrayHeight + iTrayTop + 3))
  460.    echo -e "\33[${y};0HGameOver!\33[0m"
  461.    exit
  462. }
  463. #Start from here.
  464. if [[ $1 != "--show" ]]
  465. then
  466.    $0 --show&
  467.    RunAsKeyReceiver $!
  468.    exit
  469. else
  470.    RunAsDisplayer
  471.    exit
  472. fi
复制代码
发表于 2003-11-18 14:04:13 | 显示全部楼层

写个脚本,for gentoo

作者: lordbyorn兄

脚本说明:
用emerge -up world >log可以得到要升级的包
bash update.sh log 可以得到升级每个包的脚本
包升级后脚本自毁


  1. cat update.sh
  2. #!/bin/bash
  3. #update.sh
  4. sed '1,4d' $1 > tmp1
  5. sed 's/^.*\///' tmp1 > tmp2
  6. sed 's/-[0-9].*$//' tmp2 > tmp
  7. rm tmp1 tmp2
  8. a=0
  9. b=0
  10. c=0
  11. for  package in  $(< ./tmp)
  12. do
  13. cat > $a$b$c$package <<EOF
  14. #!/bin/bash
  15. if emerge $package; then
  16. rm $a$b$c$package
  17. else echo "Error in executing $a$b$c$package" >>log
  18. fi
  19. EOF
  20. chmod +x $a$b$c$package
  21. let c++
  22. if [[ $c -eq 10 ]]; then
  23. let c=0
  24. let b++
  25. fi
  26. if [[ $b -eq 10 ]]; then
  27. let b=0
  28. let a++
  29. fi
  30. done
  31. rm tmp
复制代码
 楼主| 发表于 2003-12-10 21:12:15 | 显示全部楼层

用echo显示颜色的脚本[转]

转自:www.linuxeden.com
感谢作者:dearvoid
  1. #!/bin/bash
  2. T='gYw' # The test text
  3. echo
  4. echo  "        default  40m     41m     42m     43m     44m     45m     46m
  5.   47m"
  6. ## FGs 为前景(foreground)色, BG 为背景(background)色
  7. for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' '1;32m' '
  8. 33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' '  36m' '1;36m' '  37m' '1;37m'
  9.         do
  10.         FG=$(echo $FGs|tr -d ' ')
  11.         echo -en " $FGs \033[$FG  $T  "
  12.         for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
  13.                 do
  14.                 echo -en " \033[$FG\033[$BG  $T  \033[0m"
  15.         done
  16.         echo
  17. done
  18. echo
复制代码
 楼主| 发表于 2003-12-12 00:26:21 | 显示全部楼层

利用鼠标右键建立新文件脚本

来自: http://www.linuxsir.cn/bbs/showthread.php?threadid=15344
作者:dany
  1. #!/bin/sh
  2. if [ -f Newfile.txt ]
  3. then
  4. for num in 1 2 3 4 5 6 7 8 9; do
  5. {
  6. if [ -f "Newfile${num}.txt" ]
  7. then
  8. continue
  9. else
  10. {
  11. eval "touch Newfile$num.txt"
  12. break
  13. }
  14. fi
  15. }
  16. done
  17. else
  18. eval "touch Newfile.txt"
  19. fi
复制代码
发表于 2003-12-12 19:39:15 | 显示全部楼层
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mon, Aug 05, 2002 at 02:13:06PM +0200, ROSSEL Olivier wrote:
> BTW? I am currently making some customizations of the official
> CD so it can fit into a credit-card CD (:150Mb).
> I used a tip that was sent on the list a fewx weeks ago.
> I still have a few problems (something like 'read-only filesystem')
> when depmod -a is launched. But I presume I made something wrong.
> I will have a look later.
>
> My current operating procedure is:
> boot on Knoppix-CD.
> Copy / to a directory on the hard drive.

You should copy /KNOPPIX/*, not / !

> Chroot to it.
> Make all the apt-XXX I want.
> Leave the chroot.
> Use the magical sabbat trick to create the KNOPPIX file.
>
> I think you told me a long time ago that
> /var needed to be cleaned up before you can make
> a clean KNOPPIX file. And that you use scripts to
> clean it up.

I'm sending it again as Attachment.

Regards
-Klaus Knopper
--
Klaus Knopper                           Technical Solutions & Finances
knopper@linuxtag.org                          http://www.linuxtag.org/
Phone +49-(0)631-3109371                        Fax +49-(0)631-3109372
LinuxTag 2003 - Europes largest Linux Expo       Where .com meets .org

--XF85m9dhOBO43t/C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="Knoppix.clean"

#!/bin/sh
umask 022

/etc/init.d/autofs stop

# remove only "temporary" or saved files in the given directories
nuke(){
for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 -o -name \*.0.log -o -name browse.dat 2>/dev/null`; do
rm -f "$i"
done
}

# set all files in the given directories to a length of zero
zero(){
for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
:> "$i"
done
}

rmdir /mnt/cdrom?* /mnt/hd?* 2>/dev/null
rm -f /etc/ifstate /etc/X11/XF86Config /etc/X11/XF86Config-4 \
      /etc/XF86Config /etc/XF86Config-4 /etc/sysconfig/* \
      /etc/ssh/*key* \
      /etc/samba/*.SID /var/lib/samba/* /var/cache/samba/* /etc/samba/*.tdb \
      /dev/mouse* /dev/cdrom* /dev/cdwriter* \
      /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
      /var/state/*/* /var/state/* /var/log/nessus/* /var/lib/nessus/* \
      /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
      /etc/resolv.conf /etc/*passwd- /etc/*shadow- /etc/*group- 2>/dev/null
mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
cat >/etc/dhcpc/resolv.conf <<EOT
# insert nameservers here
# nameserver 127.0.0.1
EOT
chmod 644 /etc/dhcpc/resolv.conf
ln -s /etc/dhcpc/resolv.conf /etc/
rm -rf /tmp/* /var/tmp/* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
       /root/.bash_history /home/*/.bash_history \
       /home/knoppix/* /home/knoppix/.??* /var/lib/texmf/ls-R \
       /var/spool/texmf/ls-R /var/run/screen/*
nuke /var/log /var/cache
zero /var/local /var/log /var/spool /var/mail \
     /var/lib/games /var/cache/man /var/lib/wine \
     /var/lib/nfs /var/lib/xkb

for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
[ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
done

# delete old dowloaded packages
apt-get clean

# Recreate empty utmp and wtmp
:>/var/run/utmp
:>/var/run/wtmp
# regenerate module dependencies and ls.so.cache
echo -n "Updating ld.so.cache..."
ldconfig
echo "        Done."
echo -n "Updating modules.dep..."
depmod -a 2>/dev/null
echo "        Done."
echo -n "Updating texhash..."
mktexlsr
echo "        Done."
echo -n "Updating mandb..."
mandb -c
man doesnotexist >/dev/null 2>&1
echo "        Done."
echo -n "Updating menus..."
/usr/sbin/mkmenusfromkde
echo "        Done."
echo -n "Updating locate-database..."
updatedb --prunepaths="/KNOPPIX.build /mnt/hd /mnt/cdrom /tmp /usr/tmp /var/tmp"
echo "        Done."

echo -n "Fixing permissions in /dev/..."
chown root.root /dev/ttyp*
chmod 666 /dev/ttyp* /dev/sg* /dev/audio* /dev/dsp* /dev/mixer* /dev/sequencer*
echo "  Done".

echo -n "Removing unused architecture Kernel sources: "
for i in `ls -1 /usr/src/linux/arch/ | grep -v i386`; do
        echo -n "$i "; rm -rf /usr/src/linux/arch/"$i" /usr/src/linux/include/asm-"$i"
done
echo "        Done."

echo -n "Creating auto.mnt..."
cat >/etc/auto.mnt <<EOT
# Knoppix automounter file for Directory /mnt/auto
# umask=000 only works for msdos/vfat floppies, but otherwise the floppy is read-only.
floppy        -fstype=auto,user,exec,umask=000        :/dev/fd0
cdrom        -fstype=auto,user,exec,ro        :/dev/cdrom
# The following entries (if any) are auto-generated by knoppix-autoconfig
EOT
echo "  Done".
echo "Setting OpenOffice Link to default EN"
rm -f /etc/alternatives/soffice.resource ; ln -sf /opt/openoffice/program/resource-en /etc/alternatives/soffice.resource

--XF85m9dhOBO43t/C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="Knoppix.postupgrade"

#!/bin/sh
# Remove unwanted init scripts and KDE-autostart files

STOP=""
for i in `ls -d1 /etc/rc?.d/* | egrep -v -e '(README|knoppix|xsession)'`; do
BASE=`basename $i`
BASE=${BASE##[KS]??}
case "$STOP" in *${BASE}*) ;; *) STOP="$STOP $BASE"; ;; esac
rm -vf $i
done

for i in $STOP; do
/etc/init.d/$i stop
done


for i in `ls -d1 /usr/share/autostart/* | egrep -v -e '(panel|kdesktop|khotkeys)\.desktop'`; do
rm -vf $i
done

chmod u+s /usr/bin/cdrecord /usr/bin/cdrdao /usr/bin/cdparanoia

# Some GTK programs HAVE to run as root. :-/

for i in `egrep -q -l -r -e '(xcdroast|ethereal)' /usr/share/applnk/.`; do
        perl -pi -e 's|Exec=/|Exec=sudo /|g' "$i"
done

# Replace kdesu (needs password) by sudo (doesn't)
for i in `grep -q -l -r 'Exec=.*kdesu' /usr/share/applnk/.`; do
        perl -pi -e 's|Exec=.*kdesu |Exec=sudo -H |g' "$i"
done

# Remove -ncp in xboard startup file
for i in `grep -q -l -r 'Exec=.*xboard.*-ncp' /usr/share/applnk/.`; do
        perl -pi -e 's| -ncp||g' "$i"
done

for i in "alias net-pf-17 af_packet" "alias ide_cs ide-cs" "alias usbcore off" "alias autofs autofs4"; do
grep -q "$i" /etc/modutils/aliases || { echo "$i" >> /etc/modutils/aliases; update-modules; }
done

#for i in "vendor 0x055d product 0x9001 module pwc"; do
#grep -q "$i" /etc/usbmgr/usbmgr.conf || echo "$i" >> /etc/usbmgr/usbmgr.conf
#done

# Euro font stuff
perl -pi -e 's/iso8859-1( |$)/iso8859-15$1/g' /etc/X11/fonts/misc/xfonts-base.alias && update-fonts-alias /usr/lib/X11/fonts/misc

--XF85m9dhOBO43t/C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="Knoppix.mkcompressed"

#!/bin/bash

DEST="$1"

[ -z "$DEST" -o ! -d "$DEST" ] && { echo "Usage: $0 DESTINATIONDIR" >&2 ; exit 1; }
[ ! -x /usr/bin/create_compressed_fs ] && { echo "Need /usr/bin/create_compressed_fs." ; exit 1; }

# Compression blocksize (must be multiple of 512)
# All block headers must fit into a kmalloc segment (ca. 130000 bytes)
BLOCKSIZE=65536
# BLOCKSIZE=53248
# BLOCKSIZE=102400

echo -n "Update Bootfloppy file(s)? "
read answer
if [ "$answer" = "y" ]; then
cp -uv /KNOPPIX.build/Knoppix.System/bootdisk/Knoppix/boot-*.img "$DEST"/KNOPPIX/
( cd "$DEST"/KNOPPIX && ln -f -v boot-de.img boot.img ) || exit 1
fi

[ ! -f "$DEST"/KNOPPIX/boot.img ] && { echo "Missing required file $DEST/KNOPPIX/boot.img" >&2 ; exit 1; }

echo -n "Recreate KNOPPIX compressed FS? "
read answer
if [ "$answer" = "y" ]
then
rm -f "$DEST"/KNOPPIX/KNOPPIX

# Remove files that need to be autogenerated from source dir!
echo -n "Sweep/Clean system before remastering? "
read answer
[ "$answer" = "y" ] && { . /KNOPPIX.build/Knoppix.postupgrade; . /KNOPPIX.build/Knoppix.clean; }

cat >/etc/network/interfaces <<EOT
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
# automatically added when upgrading
auto lo
iface lo inet loopback

EOT

cat >/etc/dhcpc/resolv.conf <<EOT
# Insert nameservers here
# nameserver 127.0.0.1
EOT

# Mount root read-only, so no files change while generating image
mount -o ro,remount / || { echo "Error: Cannot mount / read-only" >&2 ; exit 0; }

# Hide unwanted LOCALEs.
HIDELOCALE=""
HIDEMAN=""
MYLOCALE=$(awk -F'[="_]' '/^(LANG|LANGUAGE)=/{if(!/[$]/){x=x" "$3}}END{print x}' /etc/init.d/knoppix-autoconfig)
MYLOCALE="$MYLOCALE C en uk fi ja be"
LOCALEDIR=/usr/share/locale
MANPAGEDIR=/usr/share/man
for LOCALE in `/bin/ls -1 $LOCALEDIR`; do
[ -d "$LOCALEDIR/$LOCALE/LC_MESSAGES" ] || continue
        FOUND=""
        for l in $MYLOCALE; do
                case "$LOCALE" in $l*) FOUND="yes" ;; esac
        done
        if [ -z "$FOUND" ]; then
                HIDELOCALE="$HIDELOCALE -m $LOCALEDIR/$LOCALE"
                [ -d "$MANPAGEDIR/$LOCALE" ] && HIDELOCALE="$HIDELOCALE -m $MANPAGEDIR/$LOCALE"
        fi
done

# -U implies: -d, -l, -L, -N, -relaxed-filenames,  -allow-lowercase,
# -allow-multidot  and  -no-iso-translate
#        -iso-level 3 -U -cache-inodes -no-bak -pad \
#        -hide-rr-moved \
#        -m /var/lib/dpkg/available\* \
SORT=""
[ -e /KNOPPIX.build/mkisofs.sort ] && SORT="-sort /KNOPPIX.build/mkisofs.sort"
# mkisofs -pad -R -l -v $SORT \
mkisofs -R -U -v $SORT \
        -V "KNOPPIX ISO9660 Filesystem" \
        -P "Knopper.Net http://www.knopper.net/" \
        -p "Klaus Knopper <knoppix@knopper.net>" \
        -hide-rr-moved -cache-inodes -no-bak -pad \
        -m /proc/\* -m /tmp/\* -m /var/tmp/\* -m /home/\* -m /initrd/\* \
        -m /KNOPPIX.build -m /mnt/\*/\* -m \*.dpkg-\* \
        -m /mnt/hd/\* -m /mnt/hd\* -m /mnt/cdrom\* -m /etc/fstab\* \
        -m /etc/sysconfig/\* -m /etc/exports -m /etc/dhcpc/dhcpcd\* \
        -m /var/spool/mail/\* -m /var/spool/mqueue/\* \
        -m /etc/driveprm -m .ssh -m .bash_history \
        -m /etc/printcap\* -m /var/spool/cups/tmp/\* \
        -m /etc/cups/certs/\* -m /etc/cups/\*.O -m /etc/cups/ppd/\* \
        -m /etc/gpm.conf -m /etc/isapnp.\* -m /etc/minirc.dfl \
        -m /var/cache/debconf/\*-old -m /var/lib/\*/\*- \
        -m /var/lib/\*/\*-old -m /var/log/XFree86.\* \
        -m /var/samba/\*.pid -m /var/lib/samba/\* -m /var/cache/samba/\* \
        -m /var/mail/\* -m /var/apt/cache/archives/lock \
        -m /var/log/ksymoops\* -m /var/spool/exim/db/\* -m /etc/\*.old \
        -m /etc/\*.save -m /etc/ssl/certs/\* -m \*.preserved \
        -m .viminfo -m .\*.swp -m lost+found \
        -m /.\?\?\* -m /root/.\?\?\* -m /etc/.\?\?\* \
        -m /boot/map -m /boot/boot.0\* \
        -m /usr/src/kernel\*.deb -m /usr/src/kernel\*.dsc -m /usr/src/kernel\*.changes -m /usr/src/kernel\*.tar.gz \
        -m /usr/src/modules/pcmcia\* \
        -m /usr/src/linux\*/drivers \
        -m /usr/src/linux\*/fs \
        -m /usr/src/linux\*/init \
        -m /usr/src/linux\*/mm \
        -m /usr/src/linux\*/net \
        -m /usr/src/linux\*/vmlinu\* \
        -m /usr/src/linux\*/System.map \
        -m /usr/src/linux\*/ipc \
        -m /usr/src/linux\*/kernel \
        -m /usr/src/linux\*/lib \
        -m /usr/src/linux\*/Rules.make \
        -m /usr/src/linux\*/scripts \
        $HIDELOCALE \
        / \
        | nice -5 /usr/bin/create_compressed_fs - $BLOCKSIZE \
        >"$DEST"/KNOPPIX/KNOPPIX || exit 1
mount -o rw,remount /
chmod 444 "$DEST"/KNOPPIX/KNOPPIX
# swapoff /dev/hdc2 2>/dev/null
fi

mkfinal(){
TARGET="$1.iso"
# Alternate boot record
#        -eltorito-alt-boot \
#        -b KNOPPIX/boot-en.img -c KNOPPIX/boot.cat \
mkisofs -pad -l -r -J -v \
        -sort /tmp/knoppix.sort \
        -V 'KNOPPIX' -A 'KNOPPIX CD-ROM' \
        -P "KNOPPER.NET http://www.knopper.net/" \
        -p "KNOPPIX CD-ROM Taskforce <knoppix@knopper.net>" \
        -b KNOPPIX/boot.img -c KNOPPIX/boot.cat \
        -hide-rr-moved \
        -o "$TARGET" "$DEST"
}

echo -n "Recreate KNOPPIX-DE isofile '$DEST.iso'? "
read answer
if [ "$answer" = "y" ]; then
# Make sure that the boot floppy file is at the beginning of the image.
# Some controllers seem to depend on this.
rm -f /tmp/knoppix.sort
echo "$DEST/KNOPPIX/boot.img 100002" >/tmp/knoppix.sort
echo "$DEST/KNOPPIX/KNOPPIX 100001" >>/tmp/knoppix.sort
echo "$DEST/Demos/Audio/*.mp3 -100000" >>/tmp/knoppix.sort
echo "$DEST/Demos/Audio/*.ogg -100000" >>/tmp/knoppix.sort
# Make final CD Image
mkfinal "$DEST"

echo -n "Recreate KNOPPIX-EN isofile '$DEST-EN.iso'? "
read answer
if [ "$answer" = "y" ]; then
( cd "$DEST"/KNOPPIX && ln -f -v boot-en.img boot.img ) || exit 1
mkfinal "$DEST-EN"
( cd "$DEST"/KNOPPIX && ln -f -v boot-de.img boot.img ) || exit 1
fi
rm -f /tmp/knoppix.sort
fi

echo -n "BURN german CD version? "
read answer
if [ "$answer" = "y" ]; then
cdrecord -v -pad -eject dev=0,1,0 speed=16 fs=24M "$DEST.iso"
fi
 楼主| 发表于 2003-12-23 03:03:15 | 显示全部楼层

文件中两行互换的脚本

看了CU上有人问,我也即兴来一段~~~ ;)
  1. #!/bin/ksh
  2. (($#!=3))&&{ echo Usage:$(basename $0) num1 num2 filename;exit 1; }
  3. num=$(cat $3|wc -l)
  4. n=1
  5. while ((n<=$num))
  6. do
  7. case $n in
  8.         $1)     cat $3|sed -n ${2}p ;;
  9.         $2)     cat $3|sed -n ${1}p ;;
  10.         *)      cat $3|sed -n ${n}p ;;
  11. esac
  12. ((n+=1))
  13. done
复制代码
发表于 2003-12-23 12:10:24 | 显示全部楼层

[转载]安全删除和恢复文件的脚本 -- 作者:bjgirl

[原创]:安全删除和恢复文件的脚本
http://www.chinaunix.net 作者:bjgirl  发表于:2003-12-22 14:30:34

由于现在的linux文件系统大多是etx3的,一不小心删除后是无法恢复的(至少我不知道),而rm是个很危险的操作!鉴于此我写了这俩小脚本,希望GGJJ们指点!
1,用root修改rm的权限:
#chmod o-x /bin/rm
2,在用户主目录下创建个"垃圾箱"
$mkdir ~/.temp

删除文件脚本:

  1. cat erase

  2. #!/bin/ksh
  3. (($#==0)) && { echo "No paraments!";exit 1; }
  4. for i in $*
  5. do
  6.         mv -f $i ~/.temp/$(find $(pwd) -maxdepth 1 -name $i|tr "/" "=")
  7. done
复制代码


恢复文件脚本:

  1. cat unerase

  2. #!/bin/ksh
  3. (($#==0))&&{ echo "No paraments!";exit 1; }
  4. cd ~/.temp
  5. list=$(for i in $*;do ls ~/.temp|grep "\<$i\>";done)
  6. for j in $list
  7. do
  8.   file=$(echo $j|tr "=" "/")
  9.   mv $j ${file%/*}/${file##*/}
  10. done
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表