Results 1 to 6 of 6

Thread: script to know if some files have more than 256 characters

  1. #1
    Join Date
    Jul 2011
    Location
    Slovakia
    Beans
    327
    Distro
    Kubuntu

    script to know if some files have more than 256 characters

    Hi,

    i'm wondering if someone has already wrote a script to check content files from directories if all file are no more than 256 characters long name.
    If yes, i would like to display the files that need to be shortened.

    thx
    Tech Review ➡️ https://geni.us/CQVVM

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: script to know if some files have more than 256 characters

    You want to print the name of all files whose filename is longer than 256 characters. Have I got this right? The following will do this for your HOME directory and everything below it. For other directories, replace ${HOME} with whatever you want.
    Code:
    find ${HOME} | awk -F'/' '{if (length($NF) > 256) { print }}'
    Edit:
    My mistake, I took it to mean the name only, rather than the full path. Such names cannot exceed 255 characters on most current systems. The above code checks the length of the name part, not including any path.
    Last edited by spjackson; September 28th, 2015 at 11:10 AM.

  3. #3
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: script to know if some files have more than 256 characters

    You should also be able to show the files with long names using find by itself

    Code:
    find . -regextype posix-basic -regex '.\{256,\}' -print

  4. #4
    Join Date
    Jul 2011
    Location
    Slovakia
    Beans
    327
    Distro
    Kubuntu

    Re: script to know if some files have more than 256 characters

    basically input should be the folder where i should find all filenames being more than 256 characters long (including sub directories)
    Tech Review ➡️ https://geni.us/CQVVM

  5. #5
    Join Date
    Jul 2011
    Location
    Slovakia
    Beans
    327
    Distro
    Kubuntu

    Re: script to know if some files have more than 256 characters

    using something like
    find . -regextype posix-basic -regex '.*/.\{255,\}'
    do the trick... except that it does not include the path
    Tech Review ➡️ https://geni.us/CQVVM

  6. #6
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: script to know if some files have more than 256 characters

    I'd not sure I follow, but if you want to check just the file name, while descending into the subdirectories, you'd still need find.
    But pipe it into grep so as to select only the long filenames

    Code:
    find . | grep -P '[^/]{255,}$'

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •