Ubuntu - Command Line



Ubuntu is a Linux based operating system and most Linux users are more familiar with the command line interface. In this chapter, we will go through some of the popular command line’s used in Ubuntu.

Invoking the Command Line

To invoke the command line, go to the search option and enter the command keyword in the search box.

Invoking Command Line

The search result will give the Terminal option. Double-lick to get the command line as shown in the following screenshot.

Terminal Option

Directory Listing

The easiest command to start with, is the directory listing command which is used to list the directory contents.

Syntax

ls –option directoryname

Parameters

  • Option − These are the options to be specified with the ls command.

  • Directoryname − This is the optional directory name that can be specified along with the ls command.

Output

The output will be the listing of the directory contents.

Example

In the following example, we just issue the ls command to list the directory contents.

List Directory Contents

The directory listing of the current directory will be shown as the output.

Another variant of the ls command is to list the directory, but with more details on each line item. This is shown in the following screenshot with the ls –l command.

Another Variant

Clearing the Screen

To clear the screen, we can use the clear command.

Syntax

clear

Parameters

None

Output

The command line screen will be cleared.

Command Help

To get more information on a command, we can use the ‘man’ command.

Syntax

man commandname

Parameters

Commandname − This is the name of the command for which more information is required.

Output

The information on the command will be displayed.

Example

Following is an example of the ‘man’ command. If we issue the ‘man ls’ command, we will get the following output. The output will contain information on the ls command.

Command Help

Finding For Files

We can use the find command to find for files.

Syntax

find filepattern

Parameters

Filepattern − This is the pattern used to find for files.

Output

The files based on the file pattern will be displayed.

Example

In this example, we will issue the following command.

find Sample.*

This command will list all the files which start with the word ‘Sample’.

Sample

whoami

This command is used to display who is the current logged on user.

Syntax

whoami

Parameters

None

Output

The name of the current logged on user will be displayed.

Example

In this example, we will issue the following command.

whoami

WHOAMI

Present Working Directory

This command will display the current working directory.

Syntax

pwd

Parameters

None

Output

The current working directory will be displayed.

Example

In this example, we will issue the following command.

Pwd

Present Working Directory
Advertisements