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

2 Answers 2


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 ./.)

  • 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 Jan 14, 2013 at 3:06
  • 3
    On a Mac you can use built-in find -E . -regex ".{255,}" to list relative paths >= 253 chars. 255 is the max repetition count supported by built-in find's RegEx engine. Dec 28, 2016 at 20:50

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.

  • 1
    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. Jan 14, 2013 at 1:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .