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. 【Linux相识相知】bash的基础特性

    命令历史 shell进程会记录用户提交执行过的命令 可以是用history查看: [root@localhost dev]# history ss -tnl ifconfig vi /etc/sysc ...

  2. twemproxyMemcache协议解析探索——剖析twemproxy代码正编补充

    memcache是一种和redis类似的高速缓存服务器,但是memcache只提供键值对这种简单的存储方式,相对于redis支持的存储方式多样化,memcache就比较简单了.memcache通过tc ...

  3. JavaScript第三课 (循环)

    循环语句       !如果至少需要执行一次循环体,就用do … while语句,一般情况下用while语句就可以了. while 语法:一直读取循环到条件为假时停止循环. while(条件) { 语 ...

  4. jsPlumb之流程图项目总结及实例

    在使用jsPlumb过程中,所遇到的问题,以及解决方案,文中引用了<数据结构与算法JavaScript描述>的相关图片和一部分代码.截图是有点多,有时比较懒,没有太多的时间去详细的编辑. ...

  5. ubuntu(linux)新装系统恢复备份后无法进入系统问题的解决

    1. 引子: 可以跳过直接看3.~5. 我们可能会遇到这样的状况,从ubuntu转到别的系统,兜兜转转又回到了ubuntu. 比如说: Fedora升级后一大堆BUG,与java有关的软件渲染都糟糕的 ...

  6. mysql主从数据库设置备忘

    [mysqld] binlog-do-db = databasename1 binlog-do-db = databasename2 binlog-do-db = databasename3 -- 且 ...

  7. Django--Uploaded Files以及Handlers

    一.表示已经上传的文件(uploaded files)的类 表示已经上传的文件的类有下面几个: class UploadedFile 在文件上传的期间,实际的文件数据被存储在request.FILES ...

  8. 聊天类APP功能测试总结

    做聊天类的APP 测试已经有一段时间了,也许哪天就不做了,趁今天轻松点,记录下来. 聊天类的APP都差不多,不管是微信,还是米聊,还是QQ,如果抓住了共性,测试的点都差不太多. 我用编程的术语来比方功 ...

  9. sudo 和su

    场景:在服务器上进行操作的时候通常不适用root用户,但是有时候执行某一些操作需要使用root权限... 1 su命令 使用su命令来切换用户,su是switch user切换用户的缩写. 可以是从普 ...

  10. Linux shell for while 循环

    1.数字段形式for i in {1..10}do   echo $idone 2.详细列出(字符且项数不多)for File in 1 2 3 4 5 do     echo $File done ...