LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-24-2016, 08:12 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
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
 
Old 04-24-2016, 12:30 PM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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

Last edited by HMW; 04-24-2016 at 12:31 PM. Reason: Added PS
 
Old 04-24-2016, 12:48 PM   #3
petelq
Member
 
Registered: Aug 2008
Location: Yorkshire
Distribution: openSUSE(Leap and Tumbleweed) and a (not so) regularly changing third
Posts: 565

Rep: Reputation: Disabled
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).
 
Old 04-25-2016, 06:28 AM   #4
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
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
 
Old 04-25-2016, 09:29 AM   #5
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
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
 
Old 04-25-2016, 05:28 PM   #6
petelq
Member
 
Registered: Aug 2008
Location: Yorkshire
Distribution: openSUSE(Leap and Tumbleweed) and a (not so) regularly changing third
Posts: 565

Rep: Reputation: Disabled
Quote:
Originally Posted by alaios View Post
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.
 
Old 05-09-2016, 11:37 AM   #7
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
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
 
Old 05-09-2016, 01:18 PM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 760Reputation: 760Reputation: 760Reputation: 760Reputation: 760Reputation: 760Reputation: 760
Try with the quotes around the wildcard removed, like tar -jcvf "$COMPRESSEDFILENAME" $THESISFOLDER/*.tex
 
Old 05-12-2016, 04:29 AM   #9
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
great thanks it worked.
Can I also get some hints on how to do ftp uploading of my zip files?
Alex
 
Old 05-12-2016, 04:33 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 17,557

Rep: Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930
probably rsync would be much better (instead of tar/ftp).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script to FTP Zip File mpfeiffer311 Programming 11 10-21-2013 09:14 AM
Required script zip file rename with the contain of file dhirendrs Linux - Newbie 1 06-28-2013 01:03 PM
zip file script with date concatenation - centOS sarelnet Linux - General 4 01-19-2012 09:26 AM
Script to traverse into sub-directory and replace line of file inside zip Marshalle Linux - General 2 08-28-2010 12:38 AM
How to pack in several volumes with ZIP (PKWARE)? frenchn00b Linux - General 6 05-31-2009 06:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration