LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 06-30-2008, 12:27 PM   #1
infonlinebr
LQ Newbie
 
Registered: May 2008
Posts: 20

Rep: Reputation: 0
compress folder in rar


I wanted to compress each folder in a directory rar or zip, and the files would have to have the name of your folders
 
Old 06-30-2008, 01:05 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: OpenSUSE 12.1 CentOS 6.2
Posts: 8,998

Rep: Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349
To create a zip archive the command is
Code:
zip -R directory.zip directory/*
To crete a rar archive - if you have rar installed
Code:
rar a -r directory.rar directory/*
The zip archive preserves the directory structure inside the archive. I don't know how to preserve it using rar archives.
 
Old 06-30-2008, 01:11 PM   #3
infonlinebr
LQ Newbie
 
Registered: May 2008
Posts: 20

Original Poster
Rep: Reputation: 0
I wanted to do this is automated, because I have about 7000 folders

would be something like?
Code:
for folder; do rar a -r "$folder.rar" "$folder"; done
 
Old 06-30-2008, 01:25 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: OpenSUSE 12.1 CentOS 6.2
Posts: 8,998

Rep: Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349
Yes, it should be. However, the syntax you used (without in) does a loop over the arguments of the script. To specify a list of directories you have to do something like this
Code:
for folder in */
do
  echo rar a -r "${folder%/}.rar" "$folder"
done
this loops over all the folders in the current directory. The parameter substitution ${folder%/} serves to strip out the "/" at the end of the folder name.

I put a leading echo to the rar command for testing purpose. Visualize the commands which will be executed and when you're satisfied with the results, strip out the echo.

Just a note regarding what I previously stated. Actually the rar utility preserves the directory structure inside the archive. I had only to extract by unrar x instead of unrar e.
 
Old 06-30-2008, 01:34 PM   #5
infonlinebr
LQ Newbie
 
Registered: May 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Perfect, worked certinho, thank you very much.
Whenever I have some doubts in these exchanges of office files to folders.
 
  


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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question on how to rar multiple files into there own rar file steve51184 Linux - Software 13 10-24-2007 04:23 PM
how do i add a folder into a rar archive steve51184 Linux - Software 6 12-06-2006 04:27 PM
Compress folder to Zip file makan007 Red Hat 1 09-05-2006 04:27 AM
to compress a file or folder sanjay2004 Linux - Newbie 1 04-11-2006 08:28 AM
How to compress a folder deWin Linux - Newbie 3 11-11-2004 10:00 PM


All times are GMT -5. The time now is 02:20 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration