Use shell scripts to load USB devices and copy files in Linux. If a USB device is inserted, use the mount command to load the device, the following is a Shell program for mounting a USB device and copying files. program requirements: www.2cto.com 1. during runtime, the user is prompted to enter "y" or "Y" to determine whether to mount the USB device, U Disk File/dev/sdc1if [$ ANS = "Y"-o $ ANS = "y"] then mount-t vfat/dev/sdc1/mnt/usb 2. Confirm whether to copy file to/root is best to use $? Check whether the copy is successful. $? -Eq 0, it indicates that the copy is successful 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. Check whether the FILE is copied to the USB device 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 complete script: 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 !!"