Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-30-2010, 06:35 AM   #1
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
Old 11-30-2010, 07:36 AM   #2
Registered: Mar 2006
Location: Czech Republic
Distribution: Gentoo, Chakra
Posts: 957
Blog Entries: 14

Rep: Reputation: 135Reputation: 135

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"

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

Rep: Reputation: Disabled
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?

Old 11-30-2010, 07: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
for thing in /test/*/*
  gzip -c ${thing} > /destination/folder/$(basename ${thing}).gz
Old 11-30-2010, 05:02 PM   #5
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 05:18 PM.
Old 11-30-2010, 05:22 PM   #6
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, 05:23 PM   #7
Senior Member
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello lano,

one solution would be:
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!


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


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

All times are GMT -5. The time now is 02:50 PM.

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