Command to find file/path lengths that are too long for burning to DVD?

15,815

Solution 1

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

Solution 2

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:
15,815

Related videos on Youtube

Highly Irregular
Author by

Highly Irregular

Am currently focused on WordPress website maintenance, management, security, and development. Experience in database driven web application programming, with interests in Bitcoin & cryptocurrencies, intuitive user experiences, PHP, databases, regular expressions, sustainability, and ethics. May have some availability for contract work; feel free to get in touch. Tokens of appreciation are very welcome if you've appreciated my assistance: BTC 1ExE5rD3n3dvmbSXBDtnLLjgGnPkBmfpk3

Updated on September 18, 2022

Comments

  • Highly Irregular
    Highly Irregular almost 2 years

    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
    
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 11 years
    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.
  • Highly Irregular
    Highly Irregular over 11 years
    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
  • Dmitriy Korobskiy
    Dmitriy Korobskiy over 7 years
    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.