Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Use one line command to run compress directoies

Posted on 2011-03-25
8
Medium Priority
?
261 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 20

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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 20

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 20

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…

636 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