2

I've been using transmission to download various torrents, but every now and then transmission does not remove the file but removes the torrent file.

This makes it that my download folder is full of already removed torrents, but the files are still there.

What is the best way to find which files are currently not linked to any loaded torrent and remove them?

Thanks for your time!

  • "Remove" and "remove and delete data" are two separate operations in Transmission, for the very good reason that you don't always want to get rid of the files you downloaded when you stop participating in the swarm. If you want to delete the files associated with torrents you've already removed, use the rm command. – Tom Hunt Dec 2 '15 at 22:12
  • I've used the remove and delete data, it just doesn't always remove the files. There is no space being freed. - removing the files manually could help.. But with over 50k files and 1k torrents currently active I woudn't even know which ones can be deleted. (Thats what I want to find out) – Bart Dec 2 '15 at 22:20
  • find -mtime +7 or find -atime +7 perhaps? – roaima Dec 2 '15 at 22:51
2

You can ask transmission-remote for a list of the files it knows about. There are two options for asking for files, --files and --info-files/-if; which you need probably depends on the version you're running:

$ transmission-remote «host» -N ~/.transmission-netrc -t all --files    # or -if
musopen-lossless-dvd (4 files):
  #  Done Priority Get      Size  Name
  0: 100% Normal   Yes   8.07 GB  musopen-lossless-dvd/Musopen-Lossless-DVD.zip
⋮

Unfortunately, it's intended for display, not parsing, and there doesn't seem to be an option to make scripting-friendly output. If you're a programmer, you could grab the source and fix that or alternatively hack together your own implementation in Perl/Python/Ruby/JavaScript/etc. to get the file names. Transmission uses a documented, fairly simple JSON-over-HTTP protocol.

You could also try --move to ask Transmission to move everything it knows about to a new directory.

  • 1
    Thank you, I'll just move all the files and remove the ones that are left behind (Not 'owned' by transmission anymore). – Bart Dec 2 '15 at 22:44
  • @Bart I'd suggest keeping a copy of them for a bit (at least across a Transmission restart) just in case --move is as buggy as --remove-and-delete apparently is for you... – derobert Dec 2 '15 at 22:45
3

This is an old question but I stumbled on it whilst trying to solve this and I imagine others might too.

Using derobert's answer I wrote a bash script to remove all files that aren't listed by transmission-remote

#!/bin/bash

# get a list of all torrents transmission-remote 2.52
transmission-remote 127.0.0.1 -t all --files > _all_torrents.tmp

# all items in this directory
for i in * 
do      
        # is it a file or a directory
        if test -f "$i" -o -d "$i"
        then    
                # does it NOT exist in the list of all torrent files
                #if [[ $all_files != *"$i"* ]]
                if ! grep -Fq "$i" _all_torrents.tmp
                then    
                        # does it not start with an underscore (my special char for files in directory not related to transmission
                        if [[ "$i" != _* ]]
                        then
                                # delete them
                                echo rm -rf \"$i\"
                                # rm -rf "$i"
                        fi
                fi
        fi
done

# clear tmp file
rm _all_torrents.tmp

Note that the line to actually delete the files is commented out. I recommend running the script first to see what will be deleted before doing it. It will also delete any files not listed in Transmission, such as the "Incomplete" directory, if you keep it in your downloads folder.

I'm far from an expert at bash scripting and this is quite a slow script with a large number of torrents as searching for the substring with this method seems slow, feel free to suggest alternatives. I suspect it might break with unusual filenames too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.