I am trying to compress all folder in dir based on some regex so I used grep to filter out the output now i need to use tar and folder name.
For example I want to .tar.gz each top level directory to its own archive. Dir name must start with "web_" and not end with ".tar.gz".
How can I catch grep output to a varibel so it looks like this:
find . -maxdepth 1 -mindepth 1 -type d -print | grep -v \.tar\.gz$ | grep ^\./web_ | exec tar -czf $name.tar.gz $name
or with ls -h
ls -h | grep -v \.tar\.gz$ | grep ^web_ | exec tar -czf $name.tar.gz $name
Selection "find ...":
root@4a94aef49e3a:/home# find . -maxdepth 1 -mindepth 1 -type d -print | grep -v \.tar\.gz$ | grep ^web_
./web_demozip1
./web_demozip2
Selection "ls -h":
root@4a94aef49e3a:/home# ls -h | grep -v \.tar\.gz$ | grep ^web_
web_demozip1
web_demozip2
Example:
# fixed name works but its overwrite itself so I need to catch a var from grep
ls -h | grep -v \.tar\.gz | grep ^_web | exec tar -czf web_demozip1.tar.gz web_demozip1
root@4a94aef49e3a:/home# pwd
/home
root@4a94aef49e3a:/home# tree .
.
├── web_demozip1
│ └── somefile.txt
├── web_demozip1.tar.gz
└── web_demozip2
└── somefile.txt