0

I am trying tar files from a directory which has files starting with same pattern then multiple spaces in between. e.g.:

ABCDEFGH Mar 09 20:02:00 2023 log.TXT.0
ABCDEFGH Mar 09 20:05:00 2023 log.TXT.0
ABCDEFGH Mar 09 20:06:00 2023 log.TXT.0
ABCDEFGH Mar 09 20:07:00 2023 log.TXT.0

The tar file, named TXT_log_09032023.tar, takes only one of those files, remaining are omitted or overwritten.

Already tried quoting the file name, IFS=$'\n', IFS=$(echo -en "\n\b") etc.

I am using find to find files older than 3 days and -exec tar uf to update the tar file. In this way, it's only taking first file. Before that, touch the tar file to update it subsequently.

2
  • 3
    I don't see how this could go wrong. And it's also not clear where you need to set IFS. Please show us the actual command you are executing to create that tar. We can't debug what we can't see! Mar 11, 2023 at 7:30
  • IFS=$(echo -en "\n\b") DT=$(date +%d%m%Y) touch TXT_Logs_${DT}.tar find . -name "*TXT*" -mtime +3 -exec tar uf TXT_Logs_${DT}.tar {} \;
    – JitheshPP
    Mar 14, 2023 at 0:39

1 Answer 1

0

Should be simple as:

$ ls -1
'ABCDEFGH Mar 09 20:02:00 2023 log.TXT.0'
'ABCDEFGH Mar 09 20:05:00 2023 log.TXT.0'
'ABCDEFGH Mar 09 20:06:00 2023 log.TXT.0'
'ABCDEFGH Mar 09 20:07:00 2023 log.TXT.0'

$ tar cf /tmp/tar.tar *

$ tar tf /tmp/tar.tar
ABCDEFGH Mar 09 20:02:00 2023 log.TXT.0
ABCDEFGH Mar 09 20:05:00 2023 log.TXT.0
ABCDEFGH Mar 09 20:06:00 2023 log.TXT.0
ABCDEFGH Mar 09 20:07:00 2023 log.TXT.0
1
  • Thanks for the answer. I have updated the question with more details. tar uf is making my day tough.
    – JitheshPP
    Mar 13, 2023 at 9:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .