Compress and delete folders

Hello,

can someone help me to create a short script that tar.gz all folders form a specific folder and the delete the folders themself (without deleting the tar.gz created files)?

Moreover I'd like to add it on crontab and run it each day.

For example: in /tmp I have:

/tmp/test/test1
/tmp/test/test2
/tmp/test/test3
/tmp/test/test4

I'd like to tar.gz test1 test2 test3 test4 and then delete the folder (not the new testX.tar.gz).
Compression can be also done according to specific folder month.

not sure I understood what you wanted...
Is it you want to archive /tmp/test ( easy...) or separately each testX subdir, in which case you would have many archives...

I already have a list of directory in /tmp/test.
I'd like to compress directory by directory and then delete only the directory (not the created compressed file).
Goal is to have:

from

/tmp/test/test1/*
/tmp/test/test2/*
/tmp/test/test3/*
/tmp/test/test4/*

to:

/tmp/test/test1.tar.gz
/tmp/test/test2.tar.gz
/tmp/test/test3.tar.gz
/tmp/test/test4.tar.gz

If your tar allows for gzip ping in one go, try

for i in /tmp/test/test?; do tar cvvzf $i.tgz $i/* && rm -fr $i; done

and if I already have some .tar.gz file how can I skip them?

Sorry?

if I already have some tar.gz in the /tmp/test/ directory, and I want to skip these files in your "for" cicle, is it possible?

Replace the tar ... ; with echo $i; , run it and see... that would be the candidates for tar ring