You are not logged in.

#1 2009-10-11 14:28:27

Xi0N
Member
From: Bilbao - Spain
Registered: 2007-11-29
Posts: 832
Website

Bash - Compress all files from inside a folder

Hi!

I am looking for help on creating a script that can take all the files in a folder and compress them
In example:


In a directory i have:

file1.iso
file2.jpeg
file7.doc


I want the script to create for me:

file1.iso.7z
file2.jpeg.7z
file7.doc.7z


Thanks!

Offline

#2 2009-10-11 14:30:30

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: Bash - Compress all files from inside a folder

for f in * ; do bzip2 $f ; done

Last edited by Spider.007 (2009-10-11 14:30:46)

Offline

#3 2009-10-11 14:37:52

Xi0N
Member
From: Bilbao - Spain
Registered: 2007-11-29
Posts: 832
Website

Re: Bash - Compress all files from inside a folder

Now ill look for the way to compress to 7z and thats all....

Thanks!!!!

Offline

#4 2009-10-11 14:39:33

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: Bash - Compress all files from inside a folder

for f in * ; do 7z a $f.7z $f  ; done

probably?

Offline

#5 2009-10-11 14:47:47

Xi0N
Member
From: Bilbao - Spain
Registered: 2007-11-29
Posts: 832
Website

Re: Bash - Compress all files from inside a folder

That's what i was trying just now....... what to do for handling files with spaces in their names?
Sorry, Im a bit of a newb on bash scripting.... :S

Offline

#6 2009-10-11 15:08:16

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: Bash - Compress all files from inside a folder

for f in * ; do 7z a "$f.7z" "$f"  ; done

ps http://tldp.org/LDP/abs/html/ is a good read

Offline

#7 2009-10-11 15:15:15

Xi0N
Member
From: Bilbao - Spain
Registered: 2007-11-29
Posts: 832
Website

Re: Bash - Compress all files from inside a folder

Yeah, that did the deal...

Thanks for the P.S...... i sure need to read it........

Offline

#8 2009-10-11 16:59:43

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: Bash - Compress all files from inside a folder

Use xz-utils, it's on your system anyway. p7zip is also LZMA but a different implementation (p7zip will be able to read xz archives though if I'm not mistaken).


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

Board footer

Powered by FluxBB