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???...
- 08-12-2008 #1Just 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???
- 08-12-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
What maximum character? What are you talking about?
- 08-12-2008 #3Just 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???
- 08-12-2008 #4Linux 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; }'
- 08-12-2008 #5Just 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????
- 08-12-2008 #6Linux 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.


Reply With Quote