Terence Eden. He has a beard and is smiling.
Theme Switcher:

Fixing Broken Zip Files from Bandcamp - File name too long

· 300 words · Viewed ~609 times

🄯 CC BY-SA


I recently downloaded an album from Bandcamp. On trying to extract the zip file using Ubuntu, I got the error "File name too long." This is a known problem with Bandcamp.

If you have a problem with long filenames in zip files, here's how to fix it.

Quick Solution

Copied Bash to đź“‹
 Bashunzip -p -c whatever.zip "filename.ogg" > shortname.ogg

That will extract a specific file from the zip and then rename it before writing it to disk.

If you don't want to use the whole file name, you can use

Copied Bash to đź“‹
 Bashunzip -p -c whatever.zip "*a bit of the filename*" > shortname.ogg

More than one file

Amy Pond, from the TV show Doctor Who, is strapped into a chair. She is saying "OK, kid, This is where where it gets complicated"

It is impossible to rename a file inside a zip on Linux - if the name is already too long. Every app will fail if you try to do so.

In order to truncate the filenames, you need to do two things. First, get a list of all the files.

Copied to đź“‹
 zipinfo -2 example.zip

Then we pipe all of those file names into the above example and rename them.

Copied to đź“‹
 zipinfo -2 example.zip | while read i; do unzip -p -c example.zip "$i" > "${i:0:127}" ; done;

In this example, I'm using 128 characters as the maximum filename length - your requirements may be different. This also removes the file extension.

So, here's how to extract long filenames from a zip, shorten the name, and preserve the file extension.

Copied Bash to đź“‹
 Bashzipinfo -2 example.zip | while read i;
do
  long_fname=${i%.*}
  unzip -p -c example.zip "$i" > "${long_fname:0:123}.${i##*.}"
done;

Thanks to ravexina for answering this question.


Share this post on…

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

See allowed HTML elements: <a href="" title="">
<abbr title="">
<acronym title="">
<b>
<blockquote cite="">
<br>
<cite>
<code>
<del datetime="">
<em>
<i>
<img src="" alt="" title="" srcset="" width="" height="">
<p>
<pre>
<q cite="">
<s>
<strike>
<strong>

Your post must include a link to this post.

How does this work?
To respond on your own website, write a post which contains a link to this post - then enter the URl of your page here. Learn more about WebMentions.