PS:$引用变量的时候不要加空格。用了case,while的结构。

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
)./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挂载/复制文件/查找文件/压缩文件的更多相关文章

  1. 07.进程管理+作业控制+文件查找与压缩+文件压缩与打包+tar打包解包+NFS

    进程管理 程序放在磁盘上叫文件,把它复制到内存,并在cpu运行,就叫进程, 进程多少也反映当前运行程序的多少 进程在系统中会为每个进程生成一个进程号,在所有的进程中有一个特殊进程即init进程, 它是 ...

  2. linux基础—课堂随笔04_文件查找和压缩

    文件查找和压缩 文件查找 1.locate   这个命令是对其生成的数据库进行遍历(生成数据库的命令:updatedb),这一特性决定了用locate查找文件速度很快,但是locate命令只能对文件进 ...

  3. java 压缩文件 传入文件数组,压缩文件,在指定路径下生成指定文件名的压缩文件

    /** * 传入文件数组,压缩文件,在指定路径下生成指定文件名的压缩文件 * * @param files * 文件数组 * @param strZipName * 压缩文件路径及文件名 * @thr ...

  4. Java解压和压缩带密码的zip或rar文件(下载压缩文件中的选中文件、向压缩文件中新增、删除文件)

    JAVA 实现在线浏览管理zip和rar的工具类 (有密码及无密码的)以及下载压缩文件中的选中文件(向压缩文件中新增.删除文件) 这是之前的版本 JAVA 解压压缩包中指定文件或实现压缩文件的预览及下 ...

  5. 《Linux命令行与shell脚本编程大全》 第七章理解Linux文件权限

    Linux沿用了Unix文件权限的方法,允许用户和组根据每个文件和目录的安全性设置来访问文件. 用户权限通过创建用户时分配的用户ID(UID)来跟踪的.每个用户有唯一的ID,但是登录时用的不是UID, ...

  6. shell script 编程入门

    参考 <linux shell scripting cookbook> 控制台输出 结构化输出 #!/bin/bash #Filename: printf.sh printf " ...

  7. shell文件查找和压缩命令

    locate命令 1.locate filename     模糊匹配 只要文件名中包含关键字即可     非实时查找,速度比find快.     依靠索引数据库 /var/lib/mlocate/m ...

  8. Linux中文件查找,压缩和打包指令

    1.文件的查找和搜索 可执行文件的搜索:which .whereis locate搜索文件 find搜索文件       1.1可执行文件的搜索       在Linux系统中,有成百上千个指令,不同 ...

  9. Linux如何复制,打包,压缩文件

    (1)复制文件 cp -r  要copy的文件/("/"指的是包括里面的内容)   newfile_name(要命名的文件名) eg:cp -r webapps_zero/   f ...

随机推荐

  1. redis内存消耗详解

    Redis所有的数据都存在内存中,相对于廉价的硬盘,内存资源还是比较昂贵的,因此如何高效利用redis内存变得非常重要. 内存消耗分析 管理内存的原理和方法 内存优化技巧 一.内存消耗 理解redis ...

  2. href 和 src 区别

    去网上百度了一下,感觉还是没有清楚的定义,所以自己稍稍的总结了一下: 1 html标签分为行类元素 和块元素 在加空元素(也可以叫做替换元素img input iframe):当元素为替换元素的时候, ...

  3. Linux配置LNMP环境(一)配置Nginx

    注意:配置版本nginx-1.12.0,使用虚拟机安装linux.教程中的下载地址可能有变化.注意(在您看本教程之前首先需要对linux的基本操作熟悉) 1.  先cd到/usr/local/src ...

  4. ASP.NET Core 开源论坛项目 NETCoreBBS

    ASP.NET Core 轻量化开源论坛项目,ASP.NET Core Light forum NETCoreBBS 采用 ASP.NET Core + EF Core Sqlite + Bootst ...

  5. Python之__loader__

    主要引自:http://stackoverflow.com/questions/22185888/pythons-loader-what-is-it What is __loader__? __loa ...

  6. String to Integer (atoi) - 字符串转为整形,atoi 函数(Java )

    String to Integer (atoi) Implement atoi to convert a string to an integer. [函数说明]atoi() 函数会扫描 str 字符 ...

  7. hdu_1506:Largest Rectangle in a Histogram 【单调栈】

    题目链接 对栈的一种灵活运用吧算是,希望我的注释写的足够清晰.. #include<bits/stdc++.h> using namespace std; typedef long lon ...

  8. 导航栏使用UIButton自定义返回按钮的图片

    - (void)viewDidLoad { UIButton *backItem = [UIButton buttonWithType:UIButtonTypeCustom]; UIBarButton ...

  9. python开发部署时新增数据库中表的方法

    在项目版本让运维部署时,涉及到数据库表的增加问题,想了一下,可以有四种方法 1.使用SQLAlchemy的db.create_all()方法 # -*- coding:utf-8 -*- from f ...

  10. 【RequireJS】requireJS的基础知识

    1. requirejs的优点 1)异步加载依赖的文件 2)管理文件加载顺序 3)管理文件加载的包路径 2. requirejs下载地点 https://github.com/jrburke/requ ...