zhshqzyc
asked on
Use one line command to run compress directoies
Hi, I have an application to compress each directory. There are 20 directoies.
Now I just want one line command to accomplish it.
TarApp 1
TarApp 2
TarApp 3
...
TarApp 20
Of course we can use a loop in a batch file.#!/bin/bash
for (( i=1; i<21; i++ ))
do
TarApp $i
done
Now I just want one line command to accomplish it.
for t in $(find /home/ -type d -mindepth 1 -maxdepth 1); do tar -czf /path/to/archives/${t}.tar.gz ${t}/; done
for t in $(find /home/ -type d -mindepth 1 -maxdepth 1); do TarApp ${t}/; done
for t in $(seq 1 20); do TarApp ${t}; done
ASKER
TarApp is a batch file.
#!/bin/bash
tar cvzf $1.tgz $1
You need to get dirnames from command line?
Just change the script to
#!/bin/bash
for name in $*
do
tar cvzf ${name}.tgz $name
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
Open in new window