Search your torrent directory using find command

Introduction

Often, when you browse a torrent site for your favorite Linux distribution, you might ask the question, have I already downloaded this torrent or not? One way to find out is to actually go into your torrent directory and search (by the way, new nautilus is pretty good at searching), but it is always good to have a script (that uses find command) to do that.

Script

Create a file inside bin directory in your home folder (lets say torrent.sh) with following texts.

#!/bin/bash
# Example ./torrent.sh Ubuntu Linux Or put it in PATH and type torrent.sh
STR="("
for i in "$@"; # for loop of all command line parameters
 do 
 STR+="$i|" # add pipe character for egrep 
done
STR="${STR%?})" # remove last pipe character
find ~/Torrent/ | egrep -i "$STR" # search (file1|file2|file3)

This script is nothing special, other than it searches file names with spaces, lower or upper case etc. If Torrent directory is not in your home folder you can use following command to link it there

ln -s /path/to/torrent ~/Torrent

or you could simply change ~/Torrent in above script to where ever you save your torrent files.

Setup

First make this file executable with following command

chmod +x ~/bin/torrent.sh

and if you have not done already, add ~/bin to PATH environment variable in .bashrc file.

export PATH=$PATH:~/bin

Search

You can search files in your torrent directory using texts like following

torrent.sh ubuntu
torrent.sh ubuntu linux

Conclusion

You can modify above script to search other directories and files too. I hope this script was useful to you.

Cheers !!

About these ads

Leave a comment

Filed under Uncategorized

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s