LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-30-2010, 05:35 AM   #1
lano
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Rep: Reputation: 0
coding needed


Hello everyone.

I need a little help with a code im working on.

i need to copy from multiple folders (everything inside the folders - eg. everything inside /test/folder1 /test/folder2 /test/folder3 )

after copying the files i would need to gzip the files into a compressed file.

I need to do it as one swift movement if possible

I need to know how to copy from multiple directories and then imediately gzip the files copied hopefully without having to copy to a different directory and then gzip.

the folder i need the compressed file in has lots of other files inside that i dont wish to be gzipped ...

Thanks in advance
Lano
 
Old 11-30-2010, 06:36 AM   #2
serafean
Member
 
Registered: Mar 2006
Location: Czech Republic
Distribution: Gentoo, Chakra
Posts: 952
Blog Entries: 14

Rep: Reputation: 135Reputation: 135
Hi,

Homework? Show us what you have, or give us a hint as to how you intend to do it; we won't do your homework for you. I also defeats the point of homework : teach yourself something. if we do it for you, you'll just use the code not completely knowing what it does.

Tips : read up on the "cp", "gzip" and "tar" commands. Also read up about shell pipes.
your script most likely will begin with "#!/bin/bash"

Serafean
 
Old 11-30-2010, 06:37 AM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Hello lano and welcome to LQ,

I'd like to help you with a simple solution (there is one), but we are not here to do your homework. Could you please post your own code at first and show us that you've done some research on your own?

Markus
 
Old 11-30-2010, 06:39 AM   #4
Andrew Benton
Senior Member
 
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 64
Maybe something like
Code:
for thing in /test/*/*
do
  gzip -c ${thing} > /destination/folder/$(basename ${thing}).gz
done
 
Old 11-30-2010, 04:02 PM   #5
lano
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Original Poster
Rep: Reputation: 0
all i really need to know is if i can use the cp command to copy from multiple folders and then gzip all those files in one go ... not suppose to use the tar command from what i gather ... and im not asking for help with the whole thing ... just the part that confuses me. cant just gzip it all cos then it would remove all the files in the folder and thats not a good thing.

im thinking something like
cp /test/folder1 /dest | cp /test/folder2 /dest | cp /test/folder3 /dest
thats where i get stuck ...if i then use a gzip command would it take all the files copied and gzip them?

Last edited by lano; 11-30-2010 at 04:18 PM.
 
Old 11-30-2010, 04:22 PM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Still, is this homework?

Also, please use proper capitalization, and punctuation. It really makes it much easier to read.
 
Old 11-30-2010, 04:23 PM   #7
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Hello lano,

one solution would be:
Code:
for i in 1 2 3; do cd folder$i; for k in *; do cp $k ../newdir; gzip ../newdir/$k; done; cd ..; done
where newdir is the directory where the zipped files are after zipping them. The code is one line!

Markus

Last edited by markush; 11-30-2010 at 04:25 PM.
 
  


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
sample obs coding needed psd_prasad Programming 2 02-16-2010 12:36 PM
Erc+bitlbee encoding problem (Lisp coding help needed) Zmyrgel Linux - Software 0 03-16-2009 09:55 AM
Coding a WM? SocialEngineer Programming 1 05-20-2005 08:32 AM
Bash Coding Help neoific Linux - Software 1 11-11-2004 07:24 PM
Need linux coding help iqbal Programming 1 07-21-2004 02:28 PM

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

All times are GMT -5. The time now is 07:14 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration