Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have firefox already running on my system, and now in minimised state. What I want is to close the current tab running in firefox. How can I do this by simply using commands in terminal?

share|improve this question
Referring to this:…, it may be difficult if not impossible to close tabs from a terminal. – i08in Feb 15 '14 at 17:07

To keep Firefox minimized after closing its current tab (according to OP, see the comment) use the following commands in a terminal,

wmctrl -a firefox; xdotool key Ctrl+w; wmctrl -r firefox -b add,shaded

How it works

wmctrl -a firefox

Go to the window with a name containing 'firefox' in it

xdotool key Ctrl+w

Send the keystroke Ctrl+W to firefox which is the shortcut to close current tab in firefox.

wmctrl -r firefox -b add,shaded

Shade a window with a title that contains the word 'firefox' in it.

To know more about these see man xdotool and man wmctrl

Alias for above command

You can make an alias for the above commands, say the alias name be cfct ( Close Firefox Current Tab) in ~/.bashrc or better in ~/.bash_aliases from a terminal as,

echo -e "\nalias cfct='wmctrl -a firefox; xdotool key Ctrl+w; wmctrl -r firefox -b add,shaded'" >> ~/.bash_aliases
. ~/.bash_aliases

If you don't have ~/.bash_aliases replace ~/.bash_aliases in the above commands with ~/.bashrc


open a terminal and enter


And it will close Firefox’s current tab instantaneously.

Note: You need to have wmctrl and xdotool installed in your system. To install them use,

sudo apt-get install wmctrl xdotool
share|improve this answer
the browser window gets opened, which is not supposed to. how to avoid this? – shivshnkr Feb 15 '14 at 20:37
Quite unreliable in that it sends Ctrl+W to the last opened window, regardless if it is Firefox or not. – minerz029 Feb 16 '14 at 6:42
@minerz029 You are correct. check my edits. – souravc Feb 16 '14 at 6:48
Can i choose another tab than the current? – erm3nda Apr 15 '15 at 17:02

You can install this Add-on: and enable it with Tools->MozRepl->Start. After that you can script Firefox from outside. Create following test.js file:


And run it following way:

nc localhost 4242 < test.js
share|improve this answer

Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:


and click on the tab you want to close.

share|improve this answer
firefox is minimised, i have already stated. – shivshnkr May 15 '13 at 6:29
Also: xkill would kill the whole Firefox and not only one tab. – André Stannek May 15 '13 at 6:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.