If the location DATA/AAA/INPUT contains n files (the file names are random job names), I need to create tar files for all the n files in the DATA/AAA/OUTPUT location with a common name format.

So, if there were n files in INPUT, then the OUTPUT location should have n tar files in the format:

log1.tar, log2.tar, ... , logn.tar.

FILE_NAME_PREFIX=EDWETLLogs today=date '+%d_%m_%Y'; count=ls -lrt /DEVL3/EW/EWD1/DATA/AED/INPUT | wc -l i=1 while [[ $i -le $count ]] do if [ $i -le 9 ];then

    tar czvf /DEVL3/EW/EWD1/DATA/AED/OUTPUT/${FILE_NAME_PREFIX}_${today}_0${i}.tar.gz /DEVL3/EW/EWD1/DATA/AED/INPUT        
    tar czvf /DEVL3/EW/EWD1/DATA/AED/OUTPUT/${FILE_NAME_PREFIX}_${today}_${i}.tar.gz /DEVL3/EW/EWD1/DATA/AED/INPUT 



i tried the above code but the output it produces is it compresses all files into one single tar file

  • What have you tried yourself? Please post your attempts and explain why they don't do as you expect. – Greenonline Feb 16 at 15:25
  • Why create tar archives of each file? Can't you just compress them with gzip or some other compressor tool? – Kusalananda Feb 16 at 15:44
$ cd /path/to/DATA/AAA/INPUT
$ for file in *; do tar cf ../OUTPUT/"${file}".tar "${file}"; done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.