?
Solved

Use one line command to run compress directoies

Posted on 2011-03-25
8
Medium Priority
?
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

800 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