Linux复制文件到usb设备中,使用shell脚本实现USB设备的加载与文件复制
使用shell腳本實(shí)現(xiàn)USB設(shè)備的加載與文件復(fù)制
在Linux操作系統(tǒng)中,如果插入一個(gè)USB設(shè)備,需要用mount掛載命令才能實(shí)現(xiàn)這個(gè)設(shè)備的加載,下面寫(xiě)一個(gè)USB設(shè)備掛載與文件復(fù)制的Shell程序,程序需求:
www.2cto.com
1、運(yùn)行時(shí),提示用戶輸入“y”或者“Y”,確定是否掛載USB設(shè)備,U盤文件/dev/sdc1
if[$ANS="Y" -o $ANS = "y"]
then mount -t vfat /dev/sdc1 /mnt/usb
2、確定是否復(fù)制文件到/root
最好用$?判斷一下是否復(fù)制成功,$? -eq 0,表示復(fù)制成功
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、確定是否復(fù)制文件到USB設(shè)備中 ?www.2cto.com
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
完整的腳本: ?www.2cto.com
#!/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!!"
http://www.dengb.com/Linuxjc/551379.htmlwww.dengb.comtruehttp://www.dengb.com/Linuxjc/551379.htmlTechArticle使用shell腳本實(shí)現(xiàn)USB設(shè)備的加載與文件復(fù)制 在Linux操作系統(tǒng)中,如果插入一個(gè)USB設(shè)備,需要用mount掛載命令才能實(shí)現(xiàn)這個(gè)設(shè)備的加載,下面寫(xiě)...
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的Linux复制文件到usb设备中,使用shell脚本实现USB设备的加载与文件复制的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: css如何插入动态图,css动态图(作业
- 下一篇: linux 其他常用命令