I want to program my Ubuntu in such a way that it automatically copies the content of USB flash drive to a defined folder in my home directory.
I would like this to be done automatically when any flash drive is being connected (so not just specific ones).
The script below is an opposite- variant of this script; while that one acts on specified drives, this scripts acts on all except specified (usb) drives.
What it does
target_folder =
). A sub directory is created with the name of the drive it was copied from.excluded =
, in which you can (and probably should) list the names of your "normal", (permanent) usb devices ("normal" drives are excluded already automatically). it seems Ubuntu defines the type of device mainly by the file system; I tested formatting a flash drive asext4
, and it showed up as a "normal" drive instead of a flash drive.The script
How to use
Copy the script into an empty file. In the head section, set:
the path to where you want to store the copies of your inserted flash drives
the names of your possibly permanently connected devices (use
lsblk
if you don't know)For example:
In the output of my
lsblk
, there are two devices:19C3-0A41
andmedia_extern
. The last one is my permanently connected disk I want to exclude:Save the script as
copy_flash.py
, run it by:If it does what you want, add it to your startup applications: Dash > Startup Applications > Add