|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Bash Script to Compress All Subdirectories
I'd like to create simple bash script that, given a directory, compresses each directory by name, e.g.:
Contents of ~/Documents Folder1 Folder2 Folder3 compress-subdirectoies.sh ~/Documents Results: Folder1.[some kind of compression like bzip2 or zip] Folder2.[some kind of compression like bzip2 or zip] Folder2.[some kind of compression like bzip2 or zip] Any advice would be appreciated |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Since you have BASH, I presume you have linux. Code:
find . -type d -mindepth 1 -maxdepth 1 | while read DIR
do
echo tar -zcf "$DIR.tar.gz" "${DIR}"
doneRemove the 'echo' once you know it does what you want. |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Try this... Code:
find . -type d | xargs -I {} tar -cf {}.tar {}--ahamed |
|
#4
|
|||
|
|||
|
That make zips for folders inside folders, not just zips for the outside folders.
|
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Quote:
I just created one level of folders and tested it... didn't realize that there can be subfolders too... Code:
find . -mindepth 1 -maxdepth 1 -type d | xargs -I {} tar -cf {}.tar {}--ahamed |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Wow, thank you both. Gosh, I love the "little pieces" way Unix works. Here's what I'd change:
1. move from plain text to XML as the transfer method (hidden from user) as the default communication method; 2. tell the Java people they've got the right idea but they didn't implement it right - building their apps is composed of lots of pieces (good) that are almost impossible to configure to work correctly directly (bad). |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
I can only see the value of XML for data which isn't easily stored in a simple, tabular format. Last edited by Corona688; 02-09-2012 at 11:31 AM.. |
| Sponsored Links | ||
|
|
![]() |
| Tags |
| compress batchy |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compress files as per timestamp in multiple subdirectories | sreewin7 | Shell Programming and Scripting | 2 | 10-28-2010 12:28 PM |
| Bash: Gzip files in Directory and itīs Subdirectories | JamesCarter | Shell Programming and Scripting | 2 | 02-10-2010 08:02 AM |
| Issue: Compress in unix server and FTP to windows and open the compress file using Winzip | sakthifire | UNIX for Dummies Questions & Answers | 4 | 11-02-2009 08:38 AM |
| script needed for compress | kingkhankk | Shell Programming and Scripting | 1 | 03-04-2008 07:01 AM |
| compress script | cubicle^dweller | UNIX for Dummies Questions & Answers | 3 | 07-17-2003 09:01 AM |
|
|