



you can add a startup to clean /media/you/(folders)chenlong wrote: ↑Fri Mar 24, 2023 2:23 amI am working on a project where I use a camera to collect data and store it on a USB flash drive, but user irregularities may occur, such as cutting off the power supply without a safe shutdown. This will create these unnecessary directories, which will affect the operation of the program on the USB flash drive. So I want to know how to avoid generating these directories during an unsafe disconnect.![]()
![]()
Code: Select all
mkdir ~/.config/autostart
Code: Select all
mousepad ~/.config/autostart/clean-media.desktop
Code: Select all
[Desktop Entry]
Type=Application
Exec=sudo rm -r /media/$USER/*
An @reboot cron job or an entry in rc.local might be a better choice. Those should run before the desktop starts and the automounter has a chance to create yet another directory with a numbered suffix.kerry_s wrote: ↑Fri Mar 24, 2023 8:47 pmyou can add a startup to clean /media/you/(folders)chenlong wrote: ↑Fri Mar 24, 2023 2:23 amI am working on a project where I use a camera to collect data and store it on a USB flash drive, but user irregularities may occur, such as cutting off the power supply without a safe shutdown. This will create these unnecessary directories, which will affect the operation of the program on the USB flash drive. So I want to know how to avoid generating these directories during an unsafe disconnect.![]()
![]()
Code: Select all
mkdir ~/.config/autostart
Code: Select all
mousepad ~/.config/autostart/clean-media.desktop
Code: Select all
[Desktop Entry] Type=Application Exec=sudo rm -r /media/$USER/*
Code: Select all
crontab -e
Code: Select all
@reboot rmdir /media/$LOGNAME/*
Code: Select all
rmdir --ignore-fail-on-non-empty /media/pi/*