Solved

Use one line command to run compress directoies

Posted on 2011-03-25
8
254 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
 
LVL 8

Expert Comment

by:pilson66
ID: 35216563
for t in $(seq 1 20); do TarApp ${t}; done
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exchange management shell error exchange 2013 5 65
Uninstall via powershell 1 68
Parsing a file using ksh 10 56
Linux "time" command output redirection 16 118
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now