Disk space is cheap, but there are still situations where you'd like to reclaim space. For me, one of them is getting the maximum of the free Dropbox account I use to synchronize my applications between work and home. Hey, don't say my sysadmin I do this, he'd get a heart attack from the sole thought of a virus among my tools collection.
Of course {zip/rar}ing everything is a no-go; nobody wants to have to open an archive before being able to launch an application. So what?
Enter UPX, the reference packer for executable files. UPX compresses executable files (mostly .exe and .dll under Windows), but contrarily to zip/rar/whatever, it keeps them executable, also preserving their properties (icon, version...). All this at the cost of a completely unnoticeable performance hit when starting the application. Sounds good? Let's compress everything executable in this Dropbox that is dangerously close to reaching its 2GB limit.
"<upxFolder>\upx.exe" -9 -v *.exe *.dll
Woot, you already gained 50MB by just compressing big ol'Inkscape.
Of course you now want to do this on ALL the executables in a folder. But you're lazy, and the perspective of running this line inside hundreds of subfolders leaves you bleak. Lucky you, I'm lazy too, so I dug Stack Overflow to assemble a script that will do the operation recursively.
for /r /d %%x in (*) do (
pushd "%%x"
"<upxFolder>\upx.exe" -9 -v *.exe *.dll
popd
)
pause
Final notes:
"<upxFolder>\upx.exe" -d problematicFile.exe
to get an uncompressed version. Note it won't be byte-identical, if you want to be able to get back to byte-identical versions, you should add the --exact
switch at compression time.Ronan is a geek and musician living in Montreal. He likes scaring wary sysadmins with 2GB folders full of false positives and writes about software, music and life at flying molehill.
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.
Sorry, but this is the worst tip ever!
Read on http://www.jrsoftware.org/striprlc.php#execomp why exe compressors are bad:
“Upon startup of a compressed EXE/DLL, all of the code is decompressed from the disk image into memory in one pass, which can cause disk thrashing if the system is low on memory and is forced to access the swap file. In contrast, with uncompressed EXE/DLLs, the OS allocates memory for code pages on demand (i.e. when they are executed).
Multiple instances of a compressed EXE/DLL create multiple instances of the code in memory. If you have a compressed EXE that contains 1 MB of code (before compression) and the user starts 5 instances of it, approximately 4 MB of memory is wasted. Likewise, if you have a DLL that is 1 MB and it is used by 5 running applications, approximately 4 MB of memory is wasted. With uncompressed EXE/DLLs, code is only stored in memory once and is shared between instances.”
So while saving diskspace you’re hogging up your memory.. i wouldn’t recommend this tip to anyone!
Of course it is a trade-off.
– As said multiple times in the article, I don’t recommend doing this all the time, only in cases with heavy storage space constraints
– Upon startup: again, I’m repeating myself, but I didn’t feel any difference. Please do some benchmarks and see by yourself.
– Memory: dunno.
Rather than worrying about it manually or compiling scripts, you could just use the PortableApps.com AppCompactor and have it handle all that for you:
http://portableapps.com/apps/utilities/appcompactor
Regarding the issues with UPX compressing, portable apps (and apps within a DropBox) don’t share EXEs and DLLs anyway, they all use their own copies within their own directories. Any shared DLLs would be those used by Windows (ie on the machine itself) and would not be compressed. So that point doesn’t apply to this instance. It is true that a compressed EXE/DLL will consume more RAM, but that’s the tradeoff for smaller apps.
Thanks John, I added a link to AppCompactor in the article. I still like relying on a simple script for batch operations, but some people will sure prefer the GUI way.
WTF is this ‘article’ good for?
UPX has been around for nearly 15 years.
Grow up you wannabe admins.
To “Anonymous” it good for a F in WTF. Some of us haven’t heard of it, like me. And it’s nice info. As to being a wannabe admin – yep. So? I still make more than you. What about it?
Who is storing executable files in DropbBox in place of data files? Someone who is on the limit of disk space? Really?