Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to burn a DVD from Windows but it fails because the full path name length exceeds the limit of something like 255 characters.

Our files are stored in Debian Linux (accessed by Windows using samba), so to avoid running some dodgy Windows app to find long path names I'd prefer to find them using a Linux command.

What command could I run to output a list of the relative path and file names for a given folder, sorted by the length of each (in descending order)?

The output should look something like this:

92 ./site/testapidocs/wjhk/jupload2/policies/class-use/DefaultUploadPolicy_WithoutAlertBox.ht
83 ./site/testapidocs/wjhk/jupload2/upload/class-use/PacketConstructionThreadTest.html
76 ./site/apidocs/wjhk/jupload2/upload/helper/class-use/ProgressBarManager.html
52 ./site/xref/wjhk/jupload2/gui/JUploadFileFilter.html
31 ./site/samples.java/applet.jnlp
17 ./site/index.html
share|improve this question
up vote 8 down vote accepted

With GNU find (on Linux or Cygwin), you can look for files whose relative path is more than 255 characters long:

find -regextype posix-extended -regex '.{257,}'

(257 accounts for the initial ./.)

share|improve this answer
Useful! It appears there is also a restriction (in Windows, at least) that when burning DVDs no filename (or folder name?) can be longer than 106 characters. A small modification to your regex would find those cases too. Thanks – Highly Irregular Jan 14 '13 at 3:06

I found 2 ways of doing this:

find . | perl -pe 'print (length($_)-1)." ";' | sort -rn | less
find . | awk '{print length,$0}' | sort -rn | less

My first attempt (find . | perl -pe 'print length;' | sort -rn | less) at the command using perl reported a character count that's too high by one, as I think it includes a newline character in its count? It can probably be done more cleanly than my above method, but I got the result I needed.

share|improve this answer
Indeed your first perl attempt included the newline. You could write perl -l -pe 'print length': the -l makes perl automatically strip off the newline character. – Gilles Jan 14 '13 at 1:35

protected by Community Jun 4 at 3:10

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.