LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   a script to pack different folders to a zip file (https://www.linuxquestions.org/questions/linux-software-2/a-script-to-pack-different-folders-to-a-zip-file-4175578204/)

alaios 04-24-2016 07:12 AM

a script to pack different folders to a zip file
 
Hi there lovely community.
In the past (with your help) I have written a bash script that backs up my thesis and send it over email for remote backup.

I want to change the below line
tar -jcvf "$COMPRESSEDFILENAME" "$THESISFOLDER"

so it does not take all my thesis folder but only the
*.tex files and two subfolders and compresses them
to a single compressed file.
Reason is that these are the most important parts and that would keep the overallsize of the compressed file at reasonable size levels.
Can you help me tweak he above line?
Regards
Alex

HMW 04-24-2016 11:30 AM

Hi!

Well, consider this directory:
Code:

ls
bar.tex  dir1  dir2  foobar.txt  foo.tex

Given your requirements, you could specify everyting on a single line like this:
Code:

tar -cvf mytarball.tar *.tex dir1/ dir2/
bar.tex
foo.tex
dir1/
dir2/

Double check to see that only the .tex files and the directories were added:
Code:

tar -tf mytarball.tar
bar.tex
foo.tex
dir1/
dir2/

In other words, simply specify what you want to add using wildcards or full paths and you're good to go!

Best regards,
HMW

PS. I ignored the -j (bzip) option for easier viewing of this example. DS

petelq 04-24-2016 11:48 AM

You can also set up a text file listing the files and/or the directories to be zipped save it as , say, 'backup-in' and then your backup script would be something like
Code:

tar -czf your_backup_filename -T /path/to/backup-in
If it's easier to list the ones that don't go in do
Code:

tar -czf filename -X /path/to/backup-out
and create a text file (called backup-out, of course).

alaios 04-25-2016 05:28 AM

thanks for the answers,

what would be your suggestions for also doing an ftp send of the zipped file? which command line client to use?

Alex

alaios 04-25-2016 08:29 AM

tar -jcvf "COMPRESSEDFILENAME_SHORT" "$THESISFOLDER/*.tex" "$THESISFOLDER/chapters" "$THESISFOLDER/appendices"


tar complains about the

"$THESISFOLDER/*.tex" -->No such file or directory.
What I want is to just grap the .tex files inside the folder

petelq 04-25-2016 04:28 PM

Quote:

Originally Posted by alaios (Post 5536201)
tar -jcvf "COMPRESSEDFILENAME_SHORT" "$THESISFOLDER/*.tex" "$THESISFOLDER/chapters" "$THESISFOLDER/appendices"


tar complains about the

"$THESISFOLDER/*.tex" -->No such file or directory.
What I want is to just grap the .tex files inside the folder

Try
Code:

...$THESISFOLDER"*.tex" ... etc
It also makes a difference how you set your thesis folder variable - you may be putting in 2 "/"'s.

And by the way, you may not have liked my text file approach, but just in case, my second choice code missed out the folder to backup and then the text file tells tar what to leave out.

alaios 05-09-2016 10:37 AM

it keeps complaining

tar: /home/removed_this_part_Thesis/*.tex: Cannot stat: No such file or directory

otherwise the path is correct . I think it is more that it doe not undertand the wildcard

keefaz 05-09-2016 12:18 PM

Try with the quotes around the wildcard removed, like tar -jcvf "$COMPRESSEDFILENAME" $THESISFOLDER/*.tex

alaios 05-12-2016 03:29 AM

great thanks it worked.
Can I also get some hints on how to do ftp uploading of my zip files?
Alex

pan64 05-12-2016 03:33 AM

probably rsync would be much better (instead of tar/ftp).


All times are GMT -5. The time now is 09:10 PM.