Compress a bunch of files individually
Hi, i'm new to the forum so please forgive me if this thread is in the wrong section.
So, i have these hundred of files i need to be compressed individually into the .zip format and i couldn't find a way to do so using the zip utility on the terminal. What i want is something like this: File 1.png -> File 1.zip File 2.png -> File 2.zip File 3.png -> File 3.zip All files have blank spaces in their names and they're all the same filetype, i think this should be taken into account. I could also compress them into the 7z format but i couldn't find how either. Thanks in advance. |
try for loops
Code:
for i in *png; do command; done Code:
for i in *png; do echo "$i".zip "$i"; done |
what command are you using to compress just one file? which shell are you using? bash?
do you need to take these files in compressed form to Windows? if not, there are better ways to compress files than ZIP format. these are PNG image files. they are already compressed. you can recompress them into JPEG format and they will use less space. but, JPEG also loses some image quality so you may not want to do that. i leave my images in the format they come in as that is usually good enough. there are ways to get them a bit smaller, but then i find it inconvenient to use them that way. |
I'm using bash in linux mint. I used .png just as an example, the files i have are a bunch of .smc and .nes files and i need them to be compressed in either .zip or .7z to take less space from a SD card.
I tried Sefyir's recommendation changing the command a bit and it worked: Code:
for i in *smc; do zip "$i".zip "$i"; done filename.smc.zip And i was wondering if it's also possible to remove the .smc from the output .zip filename? |
Deleted.
|
^ I wouldn't do it like that.
But yeah, I would write a script. Something like this: Code:
#!/bin/bash |
$ for INPUT in *.png; do OUTPUT=$(echo $INPUT | sed 's/\.png/\.zip/'); echo $INPUT $OUTPUT; done
Replace the echo command with the compression one when you're confident the parameters to the compression utility are correct. |
Quote:
Quote:
I already managed to compress all files to .7z using aforementioned command so i just installed mmv and renamed everything removing the double extensions, thanks everyone. |
Quote:
Save that text to a file, make it executable, and run it form the command line. Not really necessary in this case, but more convenient if you use that particular set of commands a lot. |
If you were using say tar, you'd change:
echo $INPUT $OUTPUT; to tar -czvpf $OUTPUT $INPUT; or I'd be more likely to keep the echo and add the other command after it, so if it took a while I'd know what was taking a while. The VAR= sets the VAR, where the $VAR returns the "value" of the VAR. Which doesn't have to be uppercase, I just do that to distinguish between variable and command. |
All times are GMT -5. The time now is 08:13 AM. |