LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2016, 10:04 AM   #1
zeroize
LQ Newbie
 
Registered: Mar 2016
Posts: 2

Rep: Reputation: Disabled
Tar multiple folder to multiple files to another directory and delete original folder


Hi People, I'm using Suse Linux and need help on the shell script

my scenario is as below. under my main folder "root" I have sub folder Folder A, B and C, and inside each subfolder comes with another sub folder named F1, F2 F3 recpectively.

/root/A/F1
/root/A/F2
/root/A/F3

/root/B/F1
/root/B/F2
/root/B/F3

/root/C/F1
/root/C/F2
/root/C/F3

I need to zip all the folder individually to another location(/zipped/) with original parent folder and name like ../A/F1.tar.gz, ../A/F2.tar.gz, ../B/F1.tar.gz, ../B/F2.tar.gz etc. Then delete the original folder.

Can anyone help me with the script?

Last edited by zeroize; 03-30-2016 at 10:10 AM.
 
Old 03-30-2016, 10:13 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
please post your command and any error message between code tags and perhaps someone will be able to help you debug.
 
Old 03-30-2016, 10:17 AM   #3
zeroize
LQ Newbie
 
Registered: Mar 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
please post your command and any error message between code tags and perhaps someone will be able to help you debug.
I have no problem using single tar commands for single folder and single output, i need help on the scripting for multiple folders and I'm weak in this.
 
Old 03-30-2016, 10:21 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
something like google "tar multiple directories"
rm --help
to get the rest of it
then
Code:
#!/bin/bash

place command line arguments in here
 
Old 03-30-2016, 08:07 PM   #5
Fred Caro
Senior Member
 
Registered: May 2007
Posts: 1,007

Rep: Reputation: 167Reputation: 167
slightly off topic but, so tar archives recursively by default

Quote:
something like google "tar multiple directories"
result from linuxquestions to that effect.

but does it just tar that directory or will it accept /*

Fred.

I suppose I could just try it!
 
Old 03-30-2016, 08:10 PM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Fred Caro View Post
slightly off topic but, so tar archives recursively by default



result from linuxquestions to that effect.

but does it just tar that directory or will it accept /*

Fred.

I suppose I could just try it!
I've personally have never had to do this so I do not know. but I'd go with your gut feeling that made you say... "I suppose I could just try it!" feeling, and that is the best way to learn... set up a few test fake directories with crap files in it then zip them all together then remove the originals via a script, or go command line first.

if you say tar -c /* think what they might equate to...

MOD: you're not OP oops

using my suggestion of search words I found this really excellent link in how to set yourself of a "test bed" to try this with. go to answer #2 to see it.

http://stackoverflow.com/questions/2...-parent-folder

Last edited by BW-userx; 03-30-2016 at 08:19 PM.
 
Old 03-31-2016, 07:36 PM   #7
Fred Caro
Senior Member
 
Registered: May 2007
Posts: 1,007

Rep: Reputation: 167Reputation: 167
BW-userx
that is cheating using '-C'
but I assume tar crosses directories, at least those that are below them by a default operation.
Man pages are a wealth of info but rather terse and don't mean much to the uninitiated or when you try to build a picture, more examples would help. Winge, winge.

Fred.
 
  


Reply



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
make multiple folder on samba linux & each folder can be access each person only Aneesh.T .S Linux - Server 1 01-31-2013 06:01 PM
Unzip multiple zip files, each to separate folder smart_sagittari Linux - Newbie 3 03-21-2012 08:41 AM
how to compress ~130GB folder and erase original files at the same time arshadul Linux - Newbie 3 04-20-2009 06:48 PM
Package Folder into Multiple tar files??? mefman Linux - Newbie 9 04-01-2008 05:38 AM
How do I decompress and desarchive multiple .tar.gz files to a single directory? Baldorg Linux - Software 7 11-27-2003 12:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:37 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