Linux复制文件到usb设备中,使用shell脚本实现USB设备的加载与文件复制

在Linux操作系统中,如果插入一个USB设备,需要用mount挂载命令才能实现这个设备的加载,下面写一个USB设备挂载与文件复制的Shell程序,程序需求:

1、运行时,提示用户输入“y”或者“Y”,确定是否挂载USB设备,U盘文件/dev/sdc1

if[$ANS="Y" -o $ANS = "y"]     then mount -t vfat /dev/sdc1 /mnt/usb

2、确定是否复制文件到/root

最好用$?判断一下是否复制成功,$? -eq 0,表示复制成功

while[$ANS="Y" -o $ANS = "y"]     do         ls -lha /mnt/usb         echo "type the filename you want to copy"         read FILE         cp /mnt/usb/"$FILE" /root

3、确定是否复制文件到USB设备中

echo "Do you want to copy files to USB(y/n)" read ANS while[$ANS="Y" -o $ANS = "y"]     do         ls -lh /root         echo "type the filename you want to copy"         read FILE         cp /root/"$FILE" /mnt/usb         if[ $? -eq 0];then             echo "Finished"             else             echo "Error"         fi         echo "any other files(Y/N)"         read ANS     done

完整的脚本:

#!/bin/bash #autousb  echo "Welcome to USB" echo "Do you want load USB(Y/N)"     read ANS  if[$ANS="Y" -o $ANS = "y"];     then mount -t vfat /dev/sdc1 /mnt/usb     echo "Do you want to copy files to /root(y/n)?"     read ANS     while[$ANS="Y" -o $ANS = "y"]     do         ls -lha /mnt/usb         echo "type the filename you want to copy"         read FILE         cp /mnt/usb/"$FILE" /root         if[ $? -eq 0];then             echo "Finished"             else             echo "Error"         fi     echo "any other files(Y/N)"     read ANS     done fi  echo "Do you want to copy files to USB(y/n)" read ANS while[$ANS="Y" -o $ANS = "y"]     do         ls -lh /root         echo "type the filename you want to copy"         read FILE         cp /root/"$FILE" /mnt/usb         if[ $? -eq 0];then             echo "Finished"             else             echo "Error"         fi         echo "any other files(Y/N)"         read ANS     done  echo "Do you want to umount?(y/n)" read ANS   if[$ANS="Y" -o $ANS = "y"];then         umount /mnt/usb else     echo "umount error" fi echo "GoodBye!!"

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值