#!/bin/bash #this script tries to find all the files that are not seeded by rtorrent (in the download dir) #It should deal with all filenames except those containing newlines $'\n' and probably $':' too :( #It requires bash 3 and probably GNU/BSD sed #find dirs home_dir=~ rtorrent_temp_dir=$(sed -n 's/session[[:space:]]*=[[:space:]]\(.*\)/\1/p' ~/.rtorrent.rc) rtorrent_download_dir=$(sed -n 's/directory[[:space:]]*=[[:space:]]\(.*\)/\1/p' ~/.rtorrent.rc) #avoid the use of eval for ~ expansion rtorrent_temp_dir=${rtorrent_temp_dir//\~/$home_dir} rtorrent_download_dir=${rtorrent_download_dir//\~/$home_dir} #want to use backreferences here but it's awfully slow :( unset seeded_files i while read -d $'\0' f do strlen="$(strings "$f" | sed -n 's/.*name\([0-9]\+\).*/\1/p')" seeded_files[i++]="$(strings "$f" | sed -n 's/.*name'$strlen':\(.\{'$strlen'\}\).*/\1/p')" done < <(find $rtorrent_temp_dir -mindepth 1 -maxdepth 1 -type f -iname \*.torrent -print0) echo "theses files are unseeded..." echo -e "size(MB)\tName" while read -d $'\0' file do flag=0 for i in $(seq 0 ${#seeded_files[*]}) do if [[ $(basename "$file") == "${seeded_files[$i]}" ]] ; then flag=1 break fi done if [[ $flag -eq 0 ]] ; then du -ms "$file" fi done < <(find $rtorrent_download_dir -mindepth 1 -maxdepth 1 -print0) #-print0 rules