Solved

Use one line command to run compress directoies

Posted on 2011-03-25
8
255 Views
Last Modified: 2012-05-11
Hi, I have an application to compress each directory. There are 20 directoies.
TarApp 1
TarApp 2
TarApp 3
...
TarApp 20

Open in new window

Of course we can use a loop in a batch file.
#!/bin/bash
for (( i=1; i<21; i++ ))
do
	TarApp $i
done

Open in new window


Now I just want one line command to accomplish it.
0
Comment
Question by:zhshqzyc
  • 4
  • 3
8 Comments
 
LVL 19

Expert Comment

by:simon3270
ID: 35216479
I suppose that you don't mean:
for (( i=1; i<21; i++ )); do TarApp $i; done

Open in new window


If TarApp is a shell script, then you could modify that to accept multiple arguments.  If it is the "tar" command, then it already accepts mutlitple arguments.  In either case, you can then say:
TarApp 1 2 3 4 5 6 7 8 9 010 11 12 13 14 15 16 17 18 19 20

Open in new window

0
 
LVL 8

Expert Comment

by:pilson66
ID: 35216537
for t in $(find /home/ -type d -mindepth 1 -maxdepth 1); do tar -czf /path/to/archives/${t}.tar.gz ${t}/; done

Open in new window

0
 
LVL 8

Expert Comment

by:pilson66
ID: 35216551

for t in $(find /home/ -type d -mindepth 1 -maxdepth 1); do TarApp ${t}/; done

Open in new window

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 8

Expert Comment

by:pilson66
ID: 35216563
for t in $(seq 1 20); do TarApp ${t}; done
0
 

Author Comment

by:zhshqzyc
ID: 35216575
TarApp is a batch file.
#!/bin/bash
tar cvzf $1.tgz $1

Open in new window

0
 
LVL 8

Expert Comment

by:pilson66
ID: 35216600
You need to get dirnames from command line?
0
 
LVL 19

Expert Comment

by:simon3270
ID: 35216661
Just change the script to

#!/bin/bash
for name in $*
do
  tar cvzf ${name}.tgz $name
done

Open in new window

0
 
LVL 19

Accepted Solution

by:
simon3270 earned 50 total points
ID: 35216665
Then call it as:
    TarApp 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question