How to Auto‑Copy USB Files with Python When the Drive Is Inserted
This guide explains how to silently monitor USB insertions on a computer, automatically copy the drive’s contents to a local folder or server using a Python script that periodically scans the /Volumes directory and triggers file transfer without the user noticing.
Preface: I was annoyed by a colleague who constantly hides a USB drive and plugs it into computers whenever he sleeps, and I wanted a way to see what he stores without directly taking or tricking him, which would embarrass me as a Python developer.
Idea: When a USB is inserted, automatically copy its contents to the local machine or upload them to a server using a Python script running in the background.
Detecting USB insertion: Open the terminal, navigate to the /Volumes directory. When a USB is plugged in, it appears as a new folder under /Volumes. By continuously monitoring this directory, the script can detect when a new folder shows up, indicating a USB insertion.
Implementation: Use time.sleep(3) to keep the program running and scan the /Volumes directory every three seconds. When a new folder is detected, immediately copy its contents to another folder (or upload them).
Result: The USB contents are fully copied to the home directory within about 30 seconds after insertion.
Note: This is the extent of the demonstration.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
