Ubuntu – How to run a command

command lineexecute-command

I am a new user, who has just been told to run / execute a command. The answer has some text with a grey background like this text here or

sometimes this text here.

However, I don't know what "run" or "command" means in relation to Ubuntu.

How do I do this?


This is intended for use as a Q&A you can link to when you tell someone to run a command.

Best Answer

What is a command?

Commands, and the command line, are another way to tell the computer what to do. For example, you can click the google chrome icon, or you can run the command google-chrome.

This may seem a silly thing to do, but when you click the icon, that's what the computer does! It also is much easier to do some tasks with the command line.

For example, installing programs can be quicker and easier - just use sudo apt-get install program, rather than navigating through the software center.

And if my Bluetooth stops working, I run a command to fix it - that's the only way!

Anyway, how do you run a command?

This is also simple, although there are many ways to do it.

Simply, you open a Terminal and type (or copy / paste) the command in, then press Enter. In the image, I've run the command ls Desktop/ which will list all files on my desktop. Note that to paste you press Ctrl + Shift + V in the terminal.

By default you open the terminal by pressing Ctrl + Alt + T, or opening the Dash and searching for "Terminal".

What is a tty?

Sometimes, you may be told to run a command in the tty - often followed by a number, for example tty2. The GUI runs on tty7.

To access this, you press Ctrl + Alt + FX - where FX is replaced with the Function key that corresponds to the number. For example, to access tty2 you would press Ctrl + Alt + F2.

You have to login to this, but some things need the tty to work.

To get back to the GUI (if the instructions say to), press Ctrl + Alt + F7. If nothing appears - it's just a blank screen, press Ctrl + Alt + F8. If neither work, you may need to restart - but ask the person who is helping you by commenting below the answer!

What about GUI (Graphical User Interface) programs?

The terminal can also launch GUI programs. This can have the advantage of viewing the output the program gives - for example running software-centre looks like this:

You can also provide extra "arguments" - also known as "parameters" and "options" to the command.

For example, if I run google-chrome --app=http://youtube.com it opens a window without the URL bar or the tabs:

Bear in mind, if you close the terminal, you also lose the Google Chrome window...

One final method

This is only good for GUI programs, like Chrome, Firefox and Gedit. However, it also means you don't have a terminal lying around - which you could accidentally close. It's no good for sudo apt-get install program or similar, because you can't type your password after running it.

Press Alt + F2, and a "Run Dialouge" appears - a bit like the run window on Windows:

Ubuntu:                                                                                    Windows:

You can type any command into here, and it will run it!

My pronouns are He / Him

Related Question