You can use wc -L to report the length of the longest line in the input (excluding the newline character of a line).

$ echo 'apple' | wc -L

# last line not ending with newline won't be a problem
$ printf 'apple\nbanana' | wc -L

$ cat greeting.txt
hi there
have a nice day
$ wc -L <greeting.txt

If multiple files are passed, the last line summary will show the maximum length among the given inputs.

$ wc -L greeting.txt sample.txt para.txt
 15 greeting.txt
 26 sample.txt
 11 para.txt
 26 total

-L won't count non-printable characters and tabs are converted to equivalent spaces. You can use awk if these are not acceptable.

# tab characters can occupy up to 8 columns
$ printf '\t' | wc -L
$ printf '(\t)' | wc -L
$ printf '(\t)' | awk '{print length()}'

# non-printable characters aren't counted
$ printf '(\34)' | wc -L
$ printf '(\34)' | awk '{print length()}'

Note that the awk command in the above illustration is similar to wc -L only for single line inputs. For multiple lines, you can use the following command:

awk '{len = length(); if(len > max) max = len} END{print max}'

Multibyte characters and grapheme clusters will each be counted as 1, assuming the current locale is set appropriately:

# multibyte characters are counted as 1 each in supported locales
$ printf 'αλεπού' | wc -L

# grapheme cluster example
$ printf 'cag̈e' | wc -L

# non-supported locales can cause them to be treated as non-printable
$ printf 'αλεπού' | LC_ALL=C wc -L

Video demo:

info See also my Command line text processing with GNU Coreutils ebook.