Find the answer to your Linux question:
Results 1 to 6 of 6
Hi All, How to find the file which is having a maximum character in filename(length of file name)? using a shell script???...
  1. #1
    Just Joined!
    Join Date
    Aug 2008
    Posts
    49

    how to find file of having maximum Char_filename?

    Hi All,
    How to find the file which is having a maximum character in filename(length of file name)? using a shell script???

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    What maximum character? What are you talking about?

  3. #3
    Just Joined!
    Join Date
    Aug 2008
    Posts
    49
    for example i have 10 files and 10 sub dir's in Current dir. In that one file having a longest name..."abcdefghijklmnopqrstuvwxyz.txt".

    In my curent dir how to find the file wich is having longest file name(having maximum char length)???It should recursively all the dir and find out.

    Is it clear???

  4. #4
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    The more clearly you can describe your problem, the more likely you are to get an answer.

    Code:
    find -type f | awk '{ if (length($0) > longest) { name = $0; longest = length(name); } } END { print name; }'

  5. #5
    Just Joined!
    Join Date
    Aug 2008
    Posts
    49
    Thank you for the answer...

    It's working fine...but i have more than one file which is having same maximum length...at that case its displaying finally only one name....what shall i do for that...

    Example file name is

    abcdefgh.c = 10 char
    a1234523.c = 10 char

    Its displaying only one name... what shall i do for that????

  6. #6
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Instead of using a scalar variable to store the longest file name, you will need to use an array that may contain one or several file names.

Posting Permissions

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