Shell Script编程——USB挂载/复制文件/查找文件/压缩文件
PS:$引用变量的时候不要加空格。用了case,while的结构。
#!/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
)./usb;;
)./compression;;
)./changemod;;
)./changedate;;
)./findfile;;
)clear
echo " Thank you for using my program "
echo " Bye Bye "
sleep
while true
do
exit
done;;
*)echo " please input the right number "
sleep
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
}
umntusb(){
clear
umount /mnt
echo "if no error warn then umount successfully!"
sleep
}
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
}
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
}
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
}
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
)mntusb;;
)umntusb;;
)listusb;;
)cpdisktousb;;
)cpusbtodisk;;
)rmusb;;
)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
}
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
}
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
)replace;;
)pack;;
)back2;;
*)echo "please input the right order!"
sleep
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
}
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
)filegzip;;
)fileunzip;;
)back;;
*)echo "please input the right number!"
sleep
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
}
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
)show;;
)change;;
)clear
exit;;
*)echo "please input the right number!"
sleep
clear;;
esac
done
changedate程序——显示时间、修改系统时间
#! /bin/bash
show(){
echo "Now the date is: "
date
echo "Have a nice day!"
sleep
}
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
}
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
)show;;
)edit;;
)clear
exit;;
*)echo "please input the right number!"
sleep
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
)schcom;;
)schpar;;
)clear
exit;;
*)echo "please input the right number"
sleep
clear;;
esac
done
Shell Script编程——USB挂载/复制文件/查找文件/压缩文件的更多相关文章
- 07.进程管理+作业控制+文件查找与压缩+文件压缩与打包+tar打包解包+NFS
进程管理 程序放在磁盘上叫文件,把它复制到内存,并在cpu运行,就叫进程, 进程多少也反映当前运行程序的多少 进程在系统中会为每个进程生成一个进程号,在所有的进程中有一个特殊进程即init进程, 它是 ...
- linux基础—课堂随笔04_文件查找和压缩
文件查找和压缩 文件查找 1.locate 这个命令是对其生成的数据库进行遍历(生成数据库的命令:updatedb),这一特性决定了用locate查找文件速度很快,但是locate命令只能对文件进 ...
- java 压缩文件 传入文件数组,压缩文件,在指定路径下生成指定文件名的压缩文件
/** * 传入文件数组,压缩文件,在指定路径下生成指定文件名的压缩文件 * * @param files * 文件数组 * @param strZipName * 压缩文件路径及文件名 * @thr ...
- Java解压和压缩带密码的zip或rar文件(下载压缩文件中的选中文件、向压缩文件中新增、删除文件)
JAVA 实现在线浏览管理zip和rar的工具类 (有密码及无密码的)以及下载压缩文件中的选中文件(向压缩文件中新增.删除文件) 这是之前的版本 JAVA 解压压缩包中指定文件或实现压缩文件的预览及下 ...
- 《Linux命令行与shell脚本编程大全》 第七章理解Linux文件权限
Linux沿用了Unix文件权限的方法,允许用户和组根据每个文件和目录的安全性设置来访问文件. 用户权限通过创建用户时分配的用户ID(UID)来跟踪的.每个用户有唯一的ID,但是登录时用的不是UID, ...
- shell script 编程入门
参考 <linux shell scripting cookbook> 控制台输出 结构化输出 #!/bin/bash #Filename: printf.sh printf " ...
- shell文件查找和压缩命令
locate命令 1.locate filename 模糊匹配 只要文件名中包含关键字即可 非实时查找,速度比find快. 依靠索引数据库 /var/lib/mlocate/m ...
- Linux中文件查找,压缩和打包指令
1.文件的查找和搜索 可执行文件的搜索:which .whereis locate搜索文件 find搜索文件 1.1可执行文件的搜索 在Linux系统中,有成百上千个指令,不同 ...
- Linux如何复制,打包,压缩文件
(1)复制文件 cp -r 要copy的文件/("/"指的是包括里面的内容) newfile_name(要命名的文件名) eg:cp -r webapps_zero/ f ...
随机推荐
- Java+Tomcat + Idea + Jrebel 实现热部署
1. 首先安装idea的jrebel插件, jrebel是收费的,所以要在网上下载验证码. 2. 安装好以后再setting 菜单能看到一个jrebel的菜单. 3. 4.其中需要选中frame失去 ...
- Hibernate的一个简单应用例子
Hibernate是一个开源的ORM框架,顾名思义,它的核心思想即ORM(Object Relational Mapping,对象关系映射),可以通过对象来操作数据库中的信息,据说开发者一开始是不太熟 ...
- 一个简单的时间轴demo
一个时间轴的组成 使用一个块级元素包裹内容,并未块级元素设置边框 定义圆形或者菱形等元素标签,子元素设置偏移或者定位元素将图标定位到边框上 使其中的内容不溢出,自动换行,内容自动撑高 英文自动换行:w ...
- POJ 3683 Priest John's Busiest Day / OpenJ_Bailian 3788 Priest John's Busiest Day(2-sat问题)
POJ 3683 Priest John's Busiest Day / OpenJ_Bailian 3788 Priest John's Busiest Day(2-sat问题) Descripti ...
- 事务之使用JDBC进行事务的操作2
本篇将讲诉如何使用JDBC进行数据库有关事务的操作.在上一篇博客中已经介绍了事务的概念,和在MySQL命令行窗口进行开启事务,提交事务以及回滚事务的操作. 似乎事务和批处理都可以一次同时执行多条SQL ...
- vue mint UI
vue 与mint UI 结合开发手机app html5页面 api 文档 http://mint-ui.github.io/#!/zh-cn
- css3-transition过渡属性
transition主要是用于一个元素的一种状态到另一种状态的一个过渡的过程,不能够主动触发,必须依赖于事件,例如hover伪类选择器. 一,transition简写 transition:要过渡的属 ...
- (转)PLSQL Developer导入Excel数据
场景:近来在做加班记录的统计,主要是统计Excel表格中的时间,因为我对于Excel表格的操作不是很熟悉,所以就想到把表格中的数据导入到数据库中,通过脚本语言来统计,就很方便了!但是目前来看,我还没有 ...
- (转)Java线程:大总结
Java线程:大总结 Java线程是Java语言中一个非常重要的部分,Java5之前,多线程的语言支持还是比较弱的,内容也较少,写一个复杂的多线程程序是相当有挑战性的. 在Java5以后,Ja ...
- iOS开发实战-时光记账Demo 网络版
之前写了一个本地数据库版本 戳这里 现在这个就是增加了后台 登录注册页面以及web的上传记录展示页面 含有少量php有兴趣可以看下 另外demo中包括数据库操作.json.网络请求等都没有用到第三方库 ...