Do anyone know if there's some decent software which auto extracts anything which gets downloaded (to f.e. ~/Downloads)? If, let's say, I download x.tar, it would automatically extract it to x (folder).
-
I'd imagine some combination of cron and batch scripts would do it, but I don't know much about cron.– MachaDec 5, 2009 at 16:26
-
You could make an applciation to do some polling to check for new tarballs. This is interesting...– LinusDec 5, 2009 at 17:37
-
The question is unclear, let me rephrase it and see if that's what you want: whenever something new appears in the directory ~/Downloads, this stuff should look at it, identify if it's a tarball or other archive format, and if so extract it to another folder??– DavideDec 5, 2009 at 18:35
3 Answers
You could maybe try a little mini-daemon along the lines of:
#!/bin/bash
DOWNLOAD_DIR=~/Downloads
while true;
do
for file in $DOWNLOAD_DIR/*.tar*;
do
if [ -f $file ]
then
tar xf $file
if [ $? -eq 0 ] # remove if successfully extracted
then rm $file
fi
fi
done
sleep 5
done
Just start that running and away you go. I'm not sure what the performance implications of a bash forever loop would be, but just looking at it in top
it doesn't seem to be too bad (i.e. it isn't in there.) You could boost the sleep time if necessary.
-
5+1 Better way would be to use the inotify command line interfaces inotify-tools.sourceforge.net/#info You could change the script to just run when the folder contents is modified. I think this would be the best way to go about this problem Dec 5, 2009 at 18:20
-
Cool, I didn't know about inotify-tools. You're right, that would be much better than constantly polling in the script.– ngmDec 5, 2009 at 18:25
-
You could use fsniper, which makes use of inotify.
From the fsniper homepage:
Common uses include making a single drop directory for all things from a webbrowser etc, and having semi-intelligent scripts figure out what to do with those files. You write the scripts yourself.
It's not automatic, but "right click > extract here" for gnome extracts it into a folder of the same name.