Home‎ > ‎Basics‎ > ‎

Command Line Interface (CLI) Linux beginners guide

Terminal is a prompt that you enter your text commands in.

  1. You may initiate command line by running it in a separate window inside graphical mode. Recommended for beginners.
  2. Or you may switch entirely to command line by pressing Ctrl + Alt + F1 to F4, but read first: to come back to graphical mode, press Ctrl + Alt + F7. Not recommended for beginners.

U
ser may open more than one terminal at once and run simultaneously different commands, scripts or applications in each of them.

To open terminal in Ubuntu GNOME graphical mode as a separate window, press Ctrl + Alt + T or in Dash Home, select Terminal. This is a more comfortable way of using terminal, you may run multiple windows with terminal in them, running terminal within graphical mode has its advantages, as it may be copied from and pasted to with help of a mouse cursor. To exit the terminal, you may use exit command or just close the window with mouse.

Basics

In terminal:

mike@PM01:~$

In above terminal output, mike = username, PM01 = computer name, ~ = home folder and $ = ordinary user.

root@PM01:/#

In above terminal output, root = username, PM01 = computer name, / = main root folder, # = super user (root).

root@PM01:/home/Downloads#

In above terminal output, root = username, PM01 = computer name, /home/Downloads = current folder you are working in, # = super user (root).

Understanding instructions on this website

$ lshw

Means to run the lshw command as a ordinary user, we will intentionally leave out mike@PM01:~

# lshw

Means to run the lshw command as a super user, we will intentionally leave out root@PM01:/home/mike, because it is just a distraction, you will have there your own user and computer name.

In Ubuntu, terminal window can be configured with different colours, scrolling, font, ... in Edit > Profile Preferences. You may add new Tab to your terminal by File > Open Tab (Shift + Ctrl + T), you may also open multiple instances of terminal windows, or place various terminals in different desktops.

Copying and pasting in terminal

To paste into the terminal with mouse is easy, for example right-click and paste, or middle mouse button click or with mouse that has only two buttons, use them both to paste.

Using keyboard Shift + Ctrl + V or use Shift + Insert, using Windows standard Ctrl + V does not work.

Copying is done using Shift + Ctrl + C or Shift + Insert, or with a right-click on a mouse.

To run your command, hit Enter

Hitting Enter button on your keyboard will pass your command line from terminal to the operating system for processing, you will be prompted to enter more commands upon it is finished processing your command.

To STOP executing a command, use Ctrl + C

This will try to stop the currently performed task and return you to the prompt state before hitting Enter.

Useful TIPs for working with command line

Working with the text in command line

Use the Left and Right arrow keys to move in the line, use Backspace to delete characters from right and Delete key to delete character from the left.

Home key moves the cursor to the beginning of a line, End moves cursor to the end.

Esc + b moves to the beginning of the current or previous word.

Ctrl + k deletes all characters from the cursor to the end of the line, Ctrl + u deletes all characters from the cursor to the beginning of the line.

Ctrl + w deletes the word before, Windows (Super) key + Alt + b puts cursor back one word, Windows (Super) key + Alt + f moves the cursor forward on word.

History

Looking four commands you entered previously into the CLI

To scroll trought the commands you have entered previously, use Up or Down keys on your keyboard.

Displaying previous commands, that you have typed in the CLI

Enter the history command to display a complete and numbered list of commands from history.

$ history

or use less option for scrollable list

$ history | less

or search for 'something' in the history file and expect only the matching lines as a outcome.

$ history | grep something

Search in the list of history of commands

Press Ctrl + r and as you start typing characters one by one, a match of the command entered by you in past will be displayed on the right of the semicolon. Use backspace to delete last characters if you make a mistake.

Run specific command from the numbered history list

When you enter the history command, you will get output with number and a line, to run a command with a specific number, use ! followed by the number of the command in the line.

$ !4331

Autocomplete commands or filenames

Use Tab key on your keyboard to autocomplete the command for you, if there are more option, you will be served with a list, otherwise your command will be completed for you, this is one of the biggest time-savers. 

Clear screen

mike@PM01:~$ clear

To clear text in terminal window, you may use command clear, that clears screen similar to cls command in Windows terminal or MS DOS, leaving the cursor at the top of the terminal.

If you find this useful, please hit the +1 button in the right menu bar, thank you.