Shell Script编程——USB挂载/复制文件/查找文件/压缩文件
2016-06-19 16:28
507 查看
PS:$引用变量的时候不要加空格。用了case,while的结构。
main文件
usb程序
compression程序
changemod程序——改变文件的读写执行权限
changedate程序——显示时间、修改系统时间
findfile程序——查找文件(给出完整名称,部分名称,但是要给出绝对路径)
main文件
#!/bin/bash chmod a+x changedate chmod a+x changemod chmod a+x usb chmod a+x findfile chmod a+x compression clear while true do echo "welcome to my program" echo "wish you have a good day" echo "" echo "========================================================" echo "** ALL FUNCTION **" echo " 1-Usb function " echo " 2-Compression functions " echo " 3-Edit files'properties " echo " 4-Time " echo " 5-Search " echo " 0-Exit " echo "========================================================" echo "please input the number to choose the function: " read num case $num in 1)./usb;; 2)./compression;; 3)./changemod;; 4)./changedate;; 5)./findfile;; 0)clear echo " Thank you for using my program " echo " Bye Bye " sleep 1 while true do exit done;; *)echo " please input the right number " sleep 1 clear;; esac done
usb程序
#! /bin/sh mntusb(){ clear /sbin/fdisk -l|grep dev/sd echo "please input the device name(like sdb1 or else)which is shown above" read r mount dev/$r/mnt echo "if no error warn then" echo "successfully! The USB has been mounted in /mnt document" sleep 1 } umntusb(){ clear umount /mnt echo "if no error warn then umount successfully!" sleep 1 } listusb(){ clear ls -la/mnt } cpdisktousb(){ clear echo "please input the filename to be copied in current directory" read FILE1 cp $FILE1 /mnt echo "if no error warn the copy successfully!" sleep 1 } cpusbtodisk(){ clear echo "please input the filename to be copied in usb" echo "PS:the file will be copied in the current directory" read FILE2 cp /mnt/ $FILE2 echo "if no error warn then copy successfully" sleep 1 } rmusb(){ clear echo "input the file you want remove in the diretory" read FILE3 rm -v /mnt/$FILE3 echo "if no error warn then remove successfully!" sleep 1 } back(){ clear exit } while true do clear echo "================================================================" echo "*** USB FUNCTIONS ********" echo " ------------- " echo " 1-mount USB " echo " 2-umount USB " echo " 3-list USB's files' information " echo " 4-copy current directory's file in disk to USB " echo " 5-copy USB's file to current diretory in disk " echo " 6-remove the file in USB " echo " 0-back " echo "================================================================" echo "input the number to choose the function " echo "PS: If you want to do something to USB,please mount first " read choice case $choice 1)mntusb;; 2)umntusb;; 3)listusb;; 4)cpdisktousb;; 5)cpusbtodisk;; 6)rmusb;; 0)back;; *)echo "please input the right number!(press any key to continue)" read c; clear;; esac done
compression程序
#! /bin/bash replace(){ echo "please input the file's absolute way including the file's name" read way1 gzip $ way1 echo "if no error warn then compress successfully!" sleep 2 } pack(){ echo "please input the directory's absolute way!" read way2 way8=$way2.tar.gz tar -zcvf $way8 $way2 echo "ignore the warn" echo "if no error warn then operate successfully!" sleep 3 } back2(){ clear ./compression } filegzip(){ while true clear do echo "============================================================" echo " 1-Replace the original file with compressed file " echo " 2-packing and compress directory " echo " 0-back " echo "============================================================" echo "input the right number to choose the function " read num1 case $num1 in 1)replace;; 2)pack;; 0)back2;; *)echo "please input the right order!" sleep 1 clear;; esac done } fileunzip(){ echo "please input the file's absolute way including the file's name" read way3 gzip-d $way3 echo "if no error warn then decompress successfully! " sleep 1 } back(){ clear exit } while true clear do echo "=============================================================" echo " COMPRESS FUNCTION " echo " 1-Compress file " echo " 2-Decompress file " echo " 0-back " echo "=============================================================" echo "please input the number to choose the function " read choice2 case $choice2 in 1)filegzip;; 2)fileunzip;; 0)back;; *)echo "please input the right number!" sleep 2 clear;; esac done
changemod程序——改变文件的读写执行权限
#! /bin/bash show(){ echo "input the file's absolute way including the file's name" read way4 echo "the information of the file is list following " ls -l $way4 sleep 1 } change(){ echo "input the file's absolute way including the file's name" echo "and input the file's properities you want change to,input like 700" read way5 pro echo "the formal properities of the file is like following" ls -l $way5 chmod $pro $way5 echo "change successfully!" echo "the changed file's properities is like following " ls -l $way5 } clear while true do echo "=========================================================" echo " EDIT FUNCTION " echo " 1-Show the properities of the file " echo " 2-Change the properities of the file " echo " 0-back " echo "input the right number to choose function " read num3 case $num3 in 1)show;; 2)change;; 0)clear exit;; *)echo "please input the right number!" sleep 1 clear;; esac done
changedate程序——显示时间、修改系统时间
#! /bin/bash show(){ echo "Now the date is: " date echo "Have a nice day!" sleep 1 } edit(){ echo "input the time you want to change to" echo "Ex: 0312043307 represent for 2007-03-12-04:33" read time2 date $ time2 echo "if no error warn then change date successfully" sleep 1 } while true do echo "======================================================" echo " CHANGEDATE FUNCTION " echo " 1-Show the time " echo " 2-Edit the system time " echo " 0-back " echo "input the number to choose function " read num3 case $num3 in 1)show;; 2)edit;; 0)clear exit;; *)echo "please input the right number!" sleep 1 clear;; esac done
findfile程序——查找文件(给出完整名称,部分名称,但是要给出绝对路径)
#! /bin/bash schcom(){ clear echo "input the complele file's name you want to search" read file9 echo "input the way you want to search in(like /root)" read dir9 find $dir9 -name "$ file9" -print echo "press Enter to continue" read c } schpar(){ echo "input the part file's name you remember" read file7 file6=*$file7* echo "input the way which you want to search in:(like /root)" read dir7 find $dir7 -name "$ file6" -print echo "the above way is the file's way you want to search!" echo "please Enter to continue" read c } while true do clear echo "================================================================" echo " SEARCH FUNCTION " echo " 1-Search file if you remember the complete file's name " echo " 2-Search file if you remember the part of file's name " echo " 0-back " echo "================================================================" echo "please input the number to choose function " read num5 case $num5 in 1)schcom;; 2)schpar;; 0)clear exit;; *)echo "please input the right number" sleep 1 clear;; esac done
相关文章推荐
- Shell脚本_创建系统用户,从一个用户列表文件(6.18重构)。
- shell脚本:字符串的截取
- Shell的test
- Shell练习题
- shell脚本相关知识
- shell_sed_awk使用
- shell脚本设置守护进程
- linux shell 流程控制
- Shell文本处理 - 分割合并与过滤
- Powershell管理系列(三十二)PowerShell操作之开启终端Powershell远程管理
- linux bash中for条件语句结构总结
- shell登录模式及其相应配置文件(转)
- shell中exec解析(转)
- Linux下profile和bashrc四种的区别
- Homebrew安装时”-bash:brew:command not found”的问题
- Xshell连接centos操作
- bash中(),{},(()),[],[[]]的区别
- trap信号捕捉命令介绍与shell结合实战讲解
- "CoolShell puzzle game" writeup
- 73 条日常 shell 命令汇总,总有一条你需要!