Saturday, May 4, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1469  / 3 Years ago, sun, august 29, 2021, 7:28:29

I'm looking for a way to delete automatic backup files (those on the form "filename.extension~") from a external hard drive, where I keep a backup from my main disk.



If the files were in /home, I could erase them with bleachbit or a similar program, like ubuntu tweak.



Is it possible to do?


More From » external-hdd

 Answers
7

Here's a command-line way of doing this using find. It's a little bit more advanced than using a GUI like Ubuntu Tweak, though.




  1. Find the mount point of your external hard drive. Several ways exist:




    • In your file manager, press Ctrl+L to get a text-based location bar. Copy this absolute location to your clipboard.

    • In a terminal identify the hard drive using cat /proc/mounts and locate the mount point. Example:



      /dev/sdc1 /media/1589-880A vfat rw,nosuid,[...]


      Indicates the mount point as /media/1589-880A.



  2. Open a terminal and use the following find command to list the files matching the search we're performing. Replace the /media path here with the mount point you just found in the previous step. I've added -type f to filter for files only - disregarding links and directories.



    find /media/1589-880A -name "*~" -type f

  3. If you feel happy about the results and you are sure you want to delete these files, then perform the delete like this:



    find /media/1589-880A -name "*~" -type f -delete


    Note: These files will not be sent to the Trash! They go to oblivion straight away. No easy undo exists. Don't ask for undoing this.




Feel free to modify the *~ pattern to allow other matches for other use cases (e.g. *.bak, autobackup-2012-*.tar.gz, etc. It's just using plain shell globbing. It's also perfectly possible to select a sub folder or even a parent folder instead of the mount point. Anyway, always list first before deleting!



Optionally add -xdev to the find command to prevent it descending into other file systems if you're unsure about it.


[#32846] Tuesday, August 31, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ticrew

Total Points: 190
Total Questions: 111
Total Answers: 99

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
;