Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

2 Answers 2

up vote 4 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
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. –  Gilles Jan 14 '13 at 1:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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