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 ...
随机推荐
- angular4.0 父子组建之间的相互通信
父组建---->子组建 传递信息 首先先通过angular脚手架生成两个基本组件,有一个好处是 会自动关联到跟模版,节约时间,而且还是偷懒 ng generate component compo ...
- vijos1056题解
题目: 桌面上放了N个平行于坐标轴的矩形,这N个矩形可能有互相覆盖的部分,求它们组成的图形的面积. 在翻题目时,偶然发现了这道标号为WA的题目. 原来,以前我把一中培训的代码发了上去,却WA了4个点, ...
- 虚拟硬盘格式vdi、vhd、vmdk相互转换
Windows7的引导程序能够引导vhd格式的虚拟硬盘,而VirtualBox创建的虚拟硬盘文件是vdi格式的,怎么办呢? 以前要借助其他软件才能实现,但是VirtualBox早就悄悄为我们带来了一个 ...
- 如何快速轻松学习bootstrap
我以前也是通过看一些视频教程来学的,比如慕课网上的,比如51cto上的那些零基础入门bootstrap什么的,还有一些培训班里流传出来的,感觉晕乎乎的,不知所云. 还是在后面不断使用的过程中慢慢体会到 ...
- 浅谈javascript中的call与apply方法
call方法与apply方法都是为了改变函数体内部this的指向. call方法与apply方法,这二者的作用完全一样,只是接受参数的方式不太一样. apply()方法: Function.apply ...
- docker~linux下的部署和基本命令
回到目录 docker是最近比较流行的容器工具,它可以帮助我们快速部署应用,尤其是在“微服务”环境下,成百个服务要去启动,停止,部署一次太麻烦,而如果把它部署到docker里,下一次应用就方便多了,如 ...
- Missing number - 寻找缺失的那个数字
需求:给出一个int型数组,包含不重复的数字0, 1, 2, ..., n:找出缺失的数字: 如果输入是[0, 1, 2] 返回 3 输入数组 nums = [0, 1, 2, 4] :应该返回 3 ...
- 各种demo:css实现三角形,css大小梯形,svg使用
各种demo: 1.css实现正方形 思路:width为0:height为0:使用boder-width为正方形的边长的一半,不占任何字节:border-style为固体:border-color为正 ...
- (转)java之runnable jar与普通jar
背景:项目中有时候需要导出相关的jar包,可是总是不能分清楚. 1 导出包 导出普通jar包(可作为第三方库,类似dll,so等) 在eclipse中右键选择except->java->j ...
- (转)Mysql数据库存储引擎
什么是MySql数据库 通常意义上,数据库也就是数据的集合,具体到计算机上数据库可以是存储器上一些文件的集合或者一些内存数据的集合. 我们通常说的MySql数据库,sql server数据库等 ...