Bash: Command to Find the Length of a String

If you are on the bash shell and want to know what is the length of a string, then you can make use of the wc command.


bash-3.2$ echo -n "This is my string" | wc -c


We need the -n flag or else a new-line character will get added to the length.

Bash Command to Find Length of a String in Terminal

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap