linux下自动挂载U盘并复制内容
date
Mar 16, 2024
slug
linux-auto-copy-file
status
Published
tags
随想
问题记录
summary
type
Post
读书笔记
1、在/etc/udev/rules.d/新建一个文件,文件名任意设置,例如 usb.rules,内容是:
KERNEL!="sd[b-z]?", GOTO="automount_exit"
ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/mkdir /media/%E{ID_FS_LABEL}-%E{ID_FS_UUID}", RUN+="/bin/mount -o uid=1000,user,codepage=936,utf8 $root/%k /media/%E{ID_FS_LABEL}-%E{ID_FS_UUID}" RUN+="/bin/cp -r /media/%E{ID_FS_LABEL}-%E{ID_FS_UUID} /mnt/"
ACTION=="remove", SUBSYSTEM=="block", RUN+="/bin/umount /media/%E{ID_FS_LABEL}-%E{ID_FS_UUID}", RUN+="/bin/rmdir /media/%E{ID_FS_LABEL}-%E{ID_FS_UUID}"
LABEL="automount_exit"
2、然后重启linux,这样在插入u盘以后自动挂载,并把U盘中的文件复制到/mnt下面