would like to tar files ending with same timestamp in to a single tar


Question [would like to tar files ending with same timestamp in to a single tar] has 3 solution 2020-08-19 04:28:10 linux

I got a list of log files and all these files end with a timestamp. For each day I have bunch of log files all ending with same timestamp For a week I have long list of file all with time stamps.

The challenge is, I would like to use tar command to archive set of files ending with same timedate stamp as one tar file.

Henc end up with tar files for every day accordingly.

How can I achieve this please? some sort of string matching wild card, I'm new to linux help please.

File Examples: enter image description here


Question [would like to tar files ending with same timestamp in to a single tar] solution number 1

First, get a list of unique timestamps. Then, for each timestamp archive all files with that timestamp:

printf %s\\n *.log | grep -Eo '\.[0-9]{8}_' | tr -d ._ | sort -u | while read timestamp; do
   tar cf "$timestamp.tar" ./*"$timestamp"*.log
done

Here I assumed that the timestamps always have 8 digits, always start with . and always end with _ (as shown in your screenshot).


Question [would like to tar files ending with same timestamp in to a single tar] solution number 2

Is seems that you are looking for using logrotate


Question [would like to tar files ending with same timestamp in to a single tar] solution number 3

# get all dates
all_date=`find -type f | awk -F '_'  '{print $2}'`

# make a dir to save tar files
mkdir tarfiles

# archive
for d in $all_date ; do
    tar zcvf tarfiles/$d.tar.gz *$d*
done

.htaccess .net .net-core 2d 3d 3d-printing abp abstract-syntax-tree actions-on-google actionscript-3 activemq acumatica adobe-xd aframe ag-grid air airflow ajax akka alert alexa algorithm alignment allure amadeus amazon-cognito amazon-deequ amazon-dynamodb amazon-ec2 amazon-ecs