LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-05-2012, 11:26 PM   #1
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,177

Rep: Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761
Extracting a single file from a RAR archive


This is probably straightforward, but I can't figure it out. Let's say I create a RAR archive on the command line as follows:

Code:
rar a -r test.rar /home/user/pictures/
How can I then open test.rar and extract a single file or directory from test.rar without extracting the whole lot?

 
Old 02-06-2012, 12:28 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Basically you just specify the file/s within the archive that you want to extract, at the end of the command.

I should note too, that "unrar e" will extract the files into the current directory, and "unrar x" will extract the files including the full path stored in the archive.
This will also work with parameter expansion, as in to extract a range, using "file{2..8}".

Code:
~/tmp $ unrar l test.rar 

UNRAR 3.93 freeware      Copyright (c) 1993-2010 Alexander Roshal

Archive test.rar

 Name             Size   Packed Ratio  Date   Time     Attr      CRC   Meth Ver
-------------------------------------------------------------------------------
 file1               0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
 file10              0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
 file2               0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
 file3               0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
 file4               0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
 file5               0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
 file6               0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
 file7               0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
 file8               0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
 file9               0        8   0% 06-02-12 17:16 -rw-r----- 00000000 m3b 2.9
-------------------------------------------------------------------------------
   10                0       80   0%

~/tmp $ unrar e test.rar file5 file8

UNRAR 3.93 freeware      Copyright (c) 1993-2010 Alexander Roshal


Extracting from test.rar

Extracting  file5                                                     OK 
Extracting  file8                                                     OK 
All OK
 
1 members found this post helpful.
Old 02-06-2012, 01:54 AM   #3
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,177

Original Poster
Rep: Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761
Quote:
Originally Posted by fukawi1 View Post
Basically you just specify the file/s within the archive that you want to extract, at the end of the command.
I do that but I get the message "No files to extract".

Code:
~/pictures $ unrar lb test.rar

subdir01
subdir02
pic01.jpg
pic02.jpg
pic03.jpg
pic04.jpg
pic05.jpg
pic06.jpg
pic07.jpg
pic08.jpg
pic09.jpg


~/pictures $ unrar e test.rar pic08.jpg pic09.jpg

UNRAR 4.10 freeware      Copyright (c) 1993-2012 Alexander Roshal

Extracting from test.rar

No files to extract
 
Old 02-06-2012, 02:01 AM   #4
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,177

Original Poster
Rep: Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761
Embarrassing doesn't even begin to describe it!

The archive was created with the full path, so I need either to exclude the full path name when creating archives or to specify the full path name in the unrar command.

Code:
unrar e test.rar pictures/pic08.jpg pictures/pic08.jpg
does the trick.

Many thanks!
 
1 members found this post helpful.
Old 02-06-2012, 02:05 AM   #5
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
I notice you are using a newer version of unrar. It is possible, however unlikely that could change the way accepts multiple files.

Try checking the manpage.

Will it work for a single file?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting archive file to /opt? DaftDave Programming 14 04-01-2008 06:46 AM
Extracting a RAR file... KillerPlatinum Linux - Software 6 05-24-2007 04:33 AM
extracting .rar with part01.rar? chime Linux - General 5 04-11-2006 06:59 PM
tar - extracting a single directory from a large archive? lowpro2k3 Linux - General 1 07-24-2005 02:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration