Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Question:

Question: Listing files with long names or paths (255 chars or more)

Hi all,

I've been given the task of moving the data off our mac file servers to a windows server, and this introduces the issue of long file/path names.

http://vlaurie.com/computers2/Articles/filenames.htm

Just wondering if there is a program or terminal command I can run, that will list all files that either have names too long, or have a name/path combination that is too long, so I can go and rename/action them?

Multiple XServes, Mac OS X (10.6.4)

Posted on Sep 22, 2010 9:49 PM

Reply
Question marked as Solved
Answer:
Answer:
find . -name \* -type f | perl -ne 's/(.*)/print length($1), " $1\n"/e' | sort -nu

Find files of any name starting from here (your current working directory), pass to Perl regular expression which replaces the entire line with the length of the line and the original line, thus making it ready for the sort (numerical, biggest last).

Posted on Sep 22, 2010 10:46 PM

Question marked as Helpful

Sep 29, 2010 8:54 PM in response to Bizarro In response to Bizarro

Bizarro wrote:
Ah that did the trick πŸ™‚ The order is reversed though now, is it possible to have the longest ones at the bottom? And somehow exempt lengths longer than 230 characters from the results?


Remove the 'r' from the options. Try this:

sudo find . -name \* -type f | perl -ne 's/(.*)/print length($1), " $1\n" if (length($1)>230)/e'

Sep 29, 2010 8:54 PM

There’s more to the conversation

Read all replies
Question marked as Solved

Sep 22, 2010 10:46 PM in response to Bizarro In response to Bizarro

find . -name \* -type f | perl -ne 's/(.*)/print length($1), " $1\n"/e' | sort -nu

Find files of any name starting from here (your current working directory), pass to Perl regular expression which replaces the entire line with the length of the line and the original line, thus making it ready for the sort (numerical, biggest last).

Sep 22, 2010 10:46 PM

Reply Helpful

Sep 29, 2010 6:50 PM in response to Bizarro In response to Bizarro

The only bug I have found with this command is that it doesn't appear to report multiple files/paths with the same length.
Eg if there is two files with a path length of 272 characters, only 1 will appear in the results. Once you correct that filename and run the command again, the other one will appear.
Is there an easy fix? Cheers πŸ™‚

Sep 29, 2010 6:50 PM

Reply Helpful

Sep 29, 2010 7:01 PM in response to Bizarro In response to Bizarro

I realized after the fact that I mean to use 'sort -nr' rather than 'sort -nu'. The 'u' is for unique, hence duplicates are ignored. 'r' is to reverse the order.

The other potential issue is that things like spaces are represented as %02D, i.e. 4 characters, rather than 1. I'm not sure which representation is correct.

Sep 29, 2010 7:01 PM

Reply Helpful
Question marked as Helpful

Sep 29, 2010 8:54 PM in response to Bizarro In response to Bizarro

Bizarro wrote:
Ah that did the trick πŸ™‚ The order is reversed though now, is it possible to have the longest ones at the bottom? And somehow exempt lengths longer than 230 characters from the results?


Remove the 'r' from the options. Try this:

sudo find . -name \* -type f | perl -ne 's/(.*)/print length($1), " $1\n" if (length($1)>230)/e'

Sep 29, 2010 8:54 PM

Reply Helpful (1)
User profile for user: Bizarro

Question: Listing files with long names or paths (255 chars or more)