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 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.

share|improve this question
1  
Hmm downvote because we don't need this? Or newbie questions are discouraged? Or this is a duplicate? – Tim Feb 28 at 19:17
7  
Possible duplicate of What is a terminal and how do I open and use it? – muru Feb 28 at 19:55
3  
Eh.. How do you run a command? A: Use a terminal. Then: What is a terminal, etc.? It follows trivially. – muru Feb 28 at 19:57
5  
@muru no. This is a question that is simply saying how to run a command... I thought that we were here to help people new to Ubuntu too, no? Why the angst towards people who don't know things? I think the answer clearly explains that it's good for launching a GUI program... – Tim Feb 28 at 20:02
1  
Excellent! Favourited, bookmarked and bounty added!!! ;-) – Fabby Mar 3 at 12:31
up vote 35 down vote accepted
+50

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!

share|improve this answer
3  
FN is easy to confuse with laptop key Fn. I'd rather provide a concrete example instead, like F2 for tty2. Also, I may have overseen, but I've not found where you mention how to go back to X from the VT. If a user is really a newbie as you suppose in the question, then they must learn how to go back to "warm and safe" GUI. – Ruslan Feb 28 at 19:07
3  
@Tim I would suggest you to put a warning on your What is a tty? paragraph explaining how to come back to the GUI before explaining how to access ttx: some people (e.g. younger I) do not read explanations until the end of the paragraph but rather directly try commands... and stays blocked on command-line mode! – ebo Feb 29 at 8:37
1  
+1 for having files from 2005 on your desktop – fiveclubs Feb 29 at 15:25
    
This answer misses the point of the question. Too lengthy. – mbiber Mar 5 at 2:00
    
@mbiber This answered my question pretty well. If you have any specific suggestions as to where it could be cut down, please say. I think I managed to condense a lot of information pretty well - but if it could be better I'm happy to listen :) – Tim Mar 5 at 12:36

Types of commands vary somewhat. They can be single line, like

 echo 'HelloAskubuntu' # Print 'HelloAskubuntu' 

single line with redirection to other commands

echo 'Hello World' | wc # count number of lines, words, and chars in 'Hello World'

multiline with redirection

$> bash << END                                                                 
> echo one
> echo two
> echo three
> END
one
two
three

Or multiline in form of scripts (which in terms of Windows language is batch files). Scripts are just files with lists of commands in them, that are executed sequentially. These are effectively custom build programs/software, analogous to building your own electronics out of existing spare parts.

Regardless of the type of command, you will need access to a command line, commonly known as Terminal. There is either TTY terminals on Ctrl+Alt+F[1-6] keyboard shortcuts (exit those with Alt+F7), or you can use GUI app by pressing Ctrl + Alt + T.

Terminals typically run software known as shell. The shell interprets the commands and executes them. Some shells are compatible with each other for the most part like bash, ksh, mksh, zsh , while tcsh and csh are quite different. They all have different features, and often are used for different tasks.

Either a script or a command have to be executed in shell. Some commands are physically present executable files on disks, like /bin/ls. Other commands are aliases or functions that are lists of existing commands. They exist only in the settings of the shell. For example, for bash it would be .bashrc settings file. Real executables can be run with the name or full path, like ls or /bin/ls respectivelly.

Scripts can be run with full path, or if they are stored somewhere that your shell knows about ( and it knows about only things in the PATH variable, which you can read with echo $PATH ). For example, I can run my script by going to my bin directory and running it with ./ operator, like so

 cd $HOME/bin; ./helloworld.sh

Or give terminal full path

 /home/Serg/bin/helloworld.sh
share|improve this answer
    
This answer misses the point of the question. Too lengthy. – mbiber Mar 5 at 1:58
    
I can add tldr at the top – Serg Mar 5 at 2:08

To run a command you need to open a terminal window. You can find the terminal among your applications like you would any other. Copy and paste the grayed text into the terminal window after opening it and then press Enter key to execute. You will probably see some text output during and after execution. This is feedback from the command you just ran.

Command is an instruction you give to a computer - you tell it to do something. You are already familiar with some commands, you use them while using your computer all the time. For example clicking on buttons in your GUI (graphical user interface), like web browsers, is the same thing - telling your computer to do something.

If you require more information you can find it at What is a terminal and how do I open and use it? and https://help.ubuntu.com/community/UsingTheTerminal

share|improve this answer

Your Answer

 
discard

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.