How To Tweet From Commandline In Linux

How To Tweet From Commandline In Linux
Image source:

Nowadays, I have started to use CLI mode more than GUI in my Linux desktop. Working from commandline is fun, fast, safe and recommended way to learn Linux.  Everyday, I spend so much time on all Linux forums, popular websites, and blogs in the pursuit of CLI alternatives to GUI applications. A while ago, I wrote about a few worth mentioning command line tools such as Translate Shell (a command-line google translator), cmus (commandline music player). Yesterday, I stumbled upon a commandline Twitter client called “Twitter CLI” or just “t”. which allows us to tweet from Terminal. This is very cool application ever I have found in the recent times.

In this brief tutorial, let us see how to install and use Twitter commandline tool in Linux.

Tweet From Commandline In Linux Using “Twitter CLI”


First, make sure you have Ruby installed on your system.

On DEB based systems such as Ubuntu, Linux Mint, the following command will install Ruby:

sudo apt-get install ruby-dev

On RPM based systems such as RHEL, Fedora, CentOS, run:

sudo yum install ruby-devel


sudo dnf install ruby-devel

Now, install ‘Twitter CLI’ twitter cli using command:

sudo gem install t

This command will install ‘Twitter CLI’ tool along with all dependencies.

Note: In case, you got an error something like below, You need to add ruby to your PATH variable. If not, just skip this part, and go to the Configuration section below.

 WARNING: You don't have /home/sk/.gem/ruby/2.4.0/bin in your PATH,
 gem executables will not run.
 Successfully installed t-3.1.0
 Parsing documentation for t-3.1.0
 Done installing documentation for t after 1 seconds
 1 gem installed

In my case, I have added the following to my PATH:

echo 'export PATH="$HOME/.gem/ruby/2.4.0/bin:$PATH"' >> ~/.bashrc

To update the PATH changes, run:

source ~/.bashrc

Next, install ‘Twitter’ using command:

gem install t

Sample output would be:

 Successfully installed t-3.1.0
 Parsing documentation for t-3.1.0
 Done installing documentation for t after 1 seconds
 1 gem installed


Before you can use t, you’ll first need to register an application with Twitter. Just follow the steps below:

Sign in to the Twitter Application Management site and click “Create New App”.

Complete the required fields and submit the form. Please note that your application must have a unique name. Then, Go to the Permissions tab of your application, and change the Access setting to “Read, Write and Access direct messages”. A mobile phone number must be associated with your Twitter account in order to obtain write privileges.

Go to the Keys and Access Tokens tab to view the consumer key and secret which you’ll need to copy and paste when prompted.

We have installed “t” and we have created and registered an application in Twitter. Now, we need to authorize this tool with our Twitter account. To do so, run:

t authorize

You will see a dialog. Press ENTER key to open Twitter Developer site and copy/paste the the consumer key and secret keys when prompted.

Enter your API key: Created new window in existing browser session.
Enter your API secret: lR9kDYt710xCteU91KLuz6dTyzA

Enter the correct API key and secret key of your application and press ENTER. Next Twitter app authorization page will open. Click “Authorize app” to continue.

In the next window of your browser, you will see an Unique PIN.

You need to copy this PIN and paste it in the Terminal prompt:

Enter the supplied PIN: Created new window in existing browser session.
Authorization successful.

If you get “Authorization successful.” message, congrats! You have successfully configured “t” with your Twitter account. To authorize multiple accounts, simply repeat the last step, signing into Twitter as a different user.


To view the list of all the accounts you’ve authorized, run:

t accounts

Sample output would be:

x6j835ha49d4XqBn06k6k (active)

As you see above, I have only one authorized Twitter account. If you have authorized more than one accounts, the last authorized account will be set as active.

To set another account as active, just mention the username and its consumer key like below:

t set active senthil HKi8DfW1IlPw

All authorized account details will be stored in a file called YAML in ~/.trc file. You can view the accounts details at any time using command:

cat ~/.trc

Let us now tweet. To do so, just run:

t update "Don't go around saying the world owes you a living. The world owes you nothing. It was here first"

Sample output would be:

Tweet posted by @ostechnix.

Run `t delete status 841278688738009088` to delete.

Now, open your Twitter account and check if the tweet has been posted or not.

There it is. I have just tweeted a Mark Twain’s quote from command line. Cool, isn’t it?

The beauty of this tool is it will display how to delete your last tweet from the result itself. To delete the above tweet, I ran the following command:

t delete status 841278688738009088

It will ask you a confirmation. Just type ‘y’ and hit ENTER to delete the tweet.

Are you sure you want to permanently delete @ostechnix's status: "Don't go around saying the world owes you a living. The world owes you nothing. It was here first"? [y/N] y
@ostechnix deleted the Tweet: "Don't go around saying the world owes you a living. The world owes you nothing. It was here first"

It is simple as that.

To include special characters in your tweet, just wrap it with single quotes instead of double quotes, so those characters are not interpreted by your shell. If you use single quotes, your Tweet obviously can’t contain any apostrophes unless you prefix them with a backslash \: Look at the following example:

t update 'I\'m tweeting from the command line. Isn\'t that special?'

We know now how to post a tweet and how to delete. You might how to view a Twitter user’s complete details. It’s simple! If you know a person’s twitter username, you can view the details of his account using command:

t whois @ostechnix

Sample output:

Since Nov 11 2010 (6 years ago)
Last update How To Fix “job for netctl service failed” Error In Arch Linux (3 hours ago)
Screen name @ostechnix
Name OSTechNix
Tweets 1,369
Favorites 96
Listed 15
Following 155
Followers 292
Bio An ideal place where you can find the latest news, how-to articles, Tips & Tricks about Open Source, Technology, and Unix/Linux.
Location India

Cool, yeah?

To view an user’s stats, run:

t users -l @ostechnix

You can also view multiple users stats like below:

t users -l @ostechnix @sk

To follow an user:

t follow @ostechnix

To follow multiple users:

t follow @ostechnix @sk

List all your friends, in long format, ordered by number of followers:

t friends -l --sort=followers

List all your leaders (people you follow who don’t follow you back):

t leaders -l --sort=followers

Mute everyone you follow:

t followings | xargs t mute

Unfollow everyone you follow who doesn’t follow you back:

t leaders | xargs t unfollow

Favorite the last 10 tweets that mention you:

t mentions -n 10 -l | awk '{print $1}' | xargs t favorite

To start streaming your timeline, run:

t stream timeline

Press CTRL+C to stop streaming.

To search Twitter for the 20 most recent Tweets that match a specified query:

t search all "Linux"

The above command will list the recent 20 tweets that match a query “Linux”.

Search Tweets you’ve favorited that match a specified query:

t search favorites "Linux"

Search Tweets mentioning you that match a specified query:

t search mentions "Linux"

There are more options, but this is enough to getting started with Twitter from commandline.

To view complete list of available commands, just run:

t help


I really enjoyed tweeting from commandline. This utility is really fast and useful for those who use commandline more than GUI environment. Give it a try, you won’t be disappointed.

Well then, I leave you to get acquainted with this useful tool. I will go find more CLI alternatives to popular GUI applications and post them here from time to time. So, subscribe and bookmark our website to get daily updates about Open source, Technology, Linux and Unix related stuffs.



Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...