Skip to content

Finding files on Linux with the longest names

File names on Linux systems can be as long as 255 characters. While determining which files in a directory have the longest names might not be the most exciting task at hand, doing this with a script poses some interesting challenges that invite equally interesting solutions.

To start, consider passing the output of the ls command, which is used to list files, to a wc command that counts the characters like this:

$ ls myreport.txt | wc -c

If you counted the letters in “myreport.txt” by looking at “myreport.txt”, you likely noticed that there are 12, not 13 letters in that file name. This is because, just as in the command below, echo sends the requested text through the pipe along with a newline character at the end.

To read this article in full, please click here

Source:: Network World – Linux