How do I output coloured text to a Linux terminal?

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for How do I output coloured text to a Linux terminal?

How to Jazz Up Your Linux Terminal with Coloured Text 💥🌈

Have you ever looked at your plain old black and white Linux terminal and thought, "Hmm, this is lacking some pizzazz?" Well, worry no more! I'm here to show you how to make your terminal come alive with colourful text that will leave your friends in awe. 🤩🌟

Unleash the Colours! 🎨

Before we dive into the technicalities, let's first determine whether your terminal supports colour codes. If it does, you're in luck! If not, don't worry, I'll also show you a handy workaround. 😉

Checking Terminal Support 🛠️

To determine if your terminal supports colour codes, you can use the tput command. Simply run the following command in your terminal:

tput colors

If your terminal supports colours, it will output a number greater than 0, indicating the number of supported colours. This means you're ready to rock and roll! 🤘🎸

💡 Fun Fact:

If the tput colors command doesn't work for you, it's likely that your terminal doesn't support it. But fret not, my friend! You can still embrace the colours with a handy workaround. Keep reading! 🙌

Adding Colour to Your Life 🌈

Now that we know our terminal can handle colours, let's dive into the exciting part: actually adding colour to our text! There are a few ways to accomplish this, but I'll guide you through the most commonly used methods. 🔍✍️

Method 1: ANSI Escape Codes 🎭

ANSI Escape Codes are a sequence of special characters that tell your terminal to perform certain actions. In our case, we'll be using them to change the colour of our text. Here's an example:

echo -e "\e[31mHello, colourful world!\e[0m"

In this example, \e[31m changes the text colour to red, and \e[0m resets it back to the default colour. Feel free to experiment with different numbers and codes to unleash your creativity! 🎨🖌️

Method 2: tput Command 🖌️

Remember our good friend tput? It also comes to the rescue when it comes to adding colours. Here's how you can use it:

echo "$(tput setaf 3)Hello, colourful world!$(tput sgr0)"

In this example, $(tput setaf 3) changes the text colour to yellow (since we used 3), and $(tput sgr0) resets it back to the default colour.

Time to Get Your Hands Dirty! 💪

Now that you know how to add colours to your terminal text, it's time to unleash your creativity and take your terminal game to the next level! Experiment with different colours and combinations to find the perfect look for you. 🎨✨

💡 Pro Tip:

If you want to use colours frequently, consider creating some handy aliases or functions in your shell's configuration file (e.g., .bashrc or .zshrc). This way, you can easily use your custom colours with minimal typing. Efficiency at its finest! ⚡🚀

I hope you found this guide helpful and that you're now ready to bring your Linux terminal to life with vibrant colours! 🌈✨ Don't forget to share your creations with the world and inspire others to join in on the colourful fun! Remember, the sky's the limit when it comes to adding creativity to your command line. 🌄

Now, go ahead and show off your technicolour skills! Share your colourful terminal screenshots on social media using the hashtag #TerminalTones, and let's brighten up the world one command at a time! 😍📸

Happy coding, colourful folks! 🎉💻

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my