find - How do I extract multiple files at once?

07
2014-07
  • curios

    I have a number of rar files stored like so:

    /torrents/televisionshowS01E0$X/nameoftelevisionshow.rar
    

    where $X is a variable ={0,1,2,...,12}

    I would like to extract them using a single command to a single output directory (/publicshare/).

    Here's what I have so far:

    for i in find /torrents/televisionshowS01*/ -name *.rar; do unrar x "$i" /publicshare/;done
    

    but I'm getting the following result:

    Cannot open /torrents/televisionshowS01E01/.rar
    No such file or directory
    No files to extract
    

    However, find /torrents/televisionshowS01*/ -name *.rar returns correct paths.

  • Answers
  • curios

    Oh, looking at other people's bashscript I realized I should have backticks around the find command. Like so,

    for i in `find /torrents/televisionshowS01*/ -name *.rar`; do unrar x "$i" /publicshare/; done
    

    and then command functioned the way I wished it to. Though, I'm still not sure WHY, exactly. I'm assuming they work the way parentheses would in math. Obviously, it worked this time, but as a matter of good practice should I have put backticks around unrar x "$i" /publicshare/?

    Thanks


  • Related Question

    windows xp - Extracting only files that match specific number from many compressed files
  • LinuxNewbie

    I have over 500 rar files with lots of compressed ppt files in one directory. I would like to search each archive if archive has file prj_09hr23 in name and ppt extension. What program should I use to extract only ppt files with prj_09hr23 in file name?

    I have Windows XP Pro SP3 and I have 7z installed.

    Thanks.


  • Related Answers
  • BloodPhilia

    WinRAR has such a function.

    1. Install WinRAR, I got it from http://www.winrar.nl/ it has an English version available.
    2. Start WinRAR and browse to the folder that contains all your archives.
    3. List item go to Extra -> Search Files (Or press F3)
    4. Search in current directory and set your search parameters. It will now search for any matches in your archives.
    5. When matches have been found, select the files you want and click "Extract".