From Script | Spoken-Tutorial
Jump to: navigation, search

Title of script: Basic Commands in Linux

Author: Anirban Roy Choudhury

Keywords: Shell,commands,options,help,apropos,man

Resources for the tutorial:File:Resources for Basic Commands in

Visual Cue
Display Slide 1 Dear friends, welcome to a spoken tutorial on the Linux Operating System.
In this tutorial, we will study some basic commands.
Display Slide 2 I am using Linux Operating System
We assume that you know how to get started with the Linux operating system.
If you are interested, it is available through another spoken tutorial, on the website
Display slide 3 In this tutorial, we will see what are commands and what is a command interpreter.
Then we will learn about how to find help in Linux using the man command.
Display slide 4 Now the first question is, "what are commands?".
In simplest terms we can say that Linux commands are words that when keyed in cause some actions to take place.
Linux commands are seldom more than four character in length like ls, who, ps etc.
The commands are in lower case and they are case sensitive. Let us see an example .
Go to the applications menu.
Open a terminal window Select accessories and then click on terminal from the available options
Now we can see a prompt ($) and a cursor blinking next to it. This is where we need to type in a command.
Type at the command prompt


and press enter

Type in the words who and press enter.

We can see the name of the users logged in. Actually we have just executed a command called who which shows who are logged into the system.
Display Slide 5 But which entity is converting these commands which are nothing more than a few letters into actions?
This is the job of the Command Interpreter, also called the shell.
We can define a shell as a program that acts as the interface between us and the Linux system, allowing us to enter commands for the operating system to execute.
On Linux it’s quite feasible to have multiple shells installed, with different users able to pick the one they prefer.
On Linux, the standard shell that is always installed as /bin/sh is called bash (the GNU Bourne-Again SHell), the GNU suite of tools.
The commands we would be covering in this tutorial are generic and can run on most of the Linux shells, with slight variations.
Nevertheless, we would be using the bash as the shell for demonstration in this tutorial.
It is because bash is the most popular shell and portable to almost all UNIX.
Other shells include the Bourne shell (sh) which is the original Unix shell, C Shell (csh) and Korn shell(ksh)
Type at the command prompt
echo $SHELL

To see which shell we are using go to the terminal and type the command echo space dollar in capital SHELL and press enter)
Normally the output is /bin/bash which gives us the bash shell. There are ways by which we can activate different shells. Those will be covered in an advanced tutorial.
Commands are actually files containing programs, often written in C.
These files are contained in directories. To find out where a command is stored, we can use the type command.
Type at the command prompt type ps Type at the command prompt type space ps and enter.
This shows that ps is actually a file stored in the /bin directory.
When we key in a command at the command prompt, the shell searches for a file matching the command name in a list of directories.
If it is found, then the program corresponding to that file is executed, else a command not found error is given.
The list of directories searched is specified by the PATH variable, as we will see later.
Type at the command prompt echo $PATH For now, if we want to see this list, just type the command echo space dollar PATH in capital and press enter
Display slide 6 Talking of commands, there is one important thing that we need to know.
Linux commands are of two types: External commands and internal commands.
Now external commands are those which exist as separate files/programs.
Most commands in Linux are of this nature. But there are some commands whose implementation is written within the shell and they do not exist as separate files. These are internal commands.
The echo command, which we will see later, is in fact an internal command.
Go to the terminal and type at the command prompt type echo Go to the terminal and type at the command, type space echo and press enter.
The output shows echo as a shell bulletin. So instead of giving a file name it shows that the echo command's implementation is internal to the shell. So it is called internal command.
Display slide

Another important thing which we need to understand is the structure of commands.
Commands can be of one word or multiple words, separated by white spaces.
In the second case the first word is the actual name of the command while the other words are called arguments.
Arguments can be options or expressions or file names.
A command can perform different tasks depending on the option specified. They are generally preceded by a single or double minus sign(-), called short and long option, respectively.
Type at the command prompt Go to the terminal window and type the commands and see their outputs.
Type clear to clear the terminal window
ls Then type ls and press enter
Again, type clear and press enter
ls -a Type ls space minus a and press enter.
Type clear to clear the terminal window
ls --all Now type ls space minus minus all and press enter.
ls -d Again, type clear to clear the terminal .Now type ls space minus d and press enter.
At this point it is enough to understand how the command's behavior changes with change of options
Display slide 8 In Linux we have a larger number of commands, each of which have many different options.
Commands can also be combined together as we will see later. So how do we keep so much in mind? In reality you don't have to. This is because of the excellent online help facility available in Linux.
The man command provides documentation on just about every available command on the system.
Type at the command prompt
man ls
For instance, to know about say, the ls command, all you have to do is to go to the terminal and type man command with ls as argument that is type man space ls and press enter
press q Press q to come out.
Display Slide 8

man is the system’s manual pager. Each argument given to man is normally the name of a program, utility or function.
The manual page associated with each of these arguments is then found and displayed. A section, if provided, will direct man to look only in that section of the manual.
The default is to search in all of the available sections, following a pre-defined order and to show only the first page found, even if page exists in several sections. You can use man command to know more about the command man itself.
Type at the command prompt
man man
Go to the terminal and type man space man and press enter.
Press q Press q to come out of it.
Display Slide 8 man command has many options.
Here let me tell the most useful ones. Sometimes we know what we want to do but do not know the exact command. Then what can we do? man provides the -k option which takes a keyword and return a list of commands and their brief purpose.
Type at the command prompt

man -k directories

For example, create a directory, we may not know the exact command, so we can go to the comand prompt and type man space minus k space directories and press enter.
Now we can search each of these commands to see what we actually need.
The same thing can be achieved using apropos command.
Type at the command prompt apropos directories Type at the command prompt apropos space directories and press enter to see the output.
Some times we do not need too much details. We only need to know what a command does. In that case we can use the whatis command or man -f. Both give one line description about the command.
Go to the terminal

Type at the command prompt


Go to the terminal type clear to clear the terminal window

Type at the command prompt whatis ls now type whatis space ls and press enter
Some commands have many options. We may want to obtain a list of the different options that a command has. Then we use the --help option.
Type at the command prompt
ls --help
Go to the command prompt and type ls space minus minus help and press enter
I will scroll up so that u can see all the options on this manual page
Display slide 9 Thats it for this part of the Linux Spoken tutorial. Spoken Tutorials are a part of the Talk to a Teacher project, supported by the National Mission on Education through ICT.

More information on the same is available at the following link Thanks for joining us This is Anuradha Amrutkar signing off. Good bye

Contributors and Content Editors

Nancyvarkey, PoojaMoolya