📄 chname
字号:
#!/bin/bash# change file's name# karlno 20080928function man{ echo "Usage: chname -c|-n|-d|-a path old_name [new_name]" echo "option function" echo " -c replace old suffix by new one" echo " -n replace the string of filename by new one" echo " -d delete the string from the filename" echo " -a add the suffix to all files" echo " -h help" echo "make by karlno"}if [ "$0" != "chname" ]; then #check the program name exit 1fiif [ "$#" = 0 ]; then #check the arg number man exit 1fiif [ "$1" = "-c" ] || [ "$1" = "-n" ] || [ "$1" = "-d" ] || [ "$1" = "-a" ]; then if [ "$2" ] && [ -d "$2" ]; then #check and open the path cd $2 elif [ ! "$2" ]; then echo "Please input path!" exit 1 else echo "Not found this path:\"$2\"!" #the path not exist exit 1 fificase $1 in #option-c) #eg.change ***.abc to ***.abb if [ "$3" ] && [ "$4" ]; then #check arg for filename in *.$3 do mv "$filename" "${filename/.$3/.$4}" done else echo "arg3 or arg4 err!" exit 1 fi ;; -n) #eg.change **abc** to **abb** if [ "$3" ]; then #check arg for filename in *$3* do mv "$filename" "${filename/$3/$4}" done else echo "arg3 err!" exit 1 fi ;; -d) if [ "$3" ]; then #eg.change ***.abc to *** for filename in *.$3 do mv "$filename" "${filename/.$3/}" done else echo "arg3 err!" exit 1 fi ;; -a) if [ "$3" ]; then #add suffix for filename in * do if [ "$filename" != "$0" ]; then mv "$filename" "$filename.$3" fi done else echo "arg3 err!" exit 1 fi ;; -h) #display help man ;; *) man exit 1esac
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -