BOSS-Linux/C2/General-Purpose-Utilities/English

From Script | Spoken-Tutorial
Revision as of 12:43, 12 November 2014 by PoojaMoolya (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Title of script: General Purpose Utilities in Linux

Author: Anirban Roy Choudhury

Keywords: Commands, echo,date, time, calender,cat,passwd,root user, files, directories,

Resources for the tutorial:File:Resources for general purpose utilities in linux.zip

Visual Cue
Narration
Display Slide Hello, welcome to this spoken tutorial on General Purpose Utilities in Linux.
In this tutorial we will make ourselves acquainted with some of the most basic yet heavily used commands of Linux.
The main motivation of this is to give you a headstart about working with Linux.
Switch to the terminal

Type at the prompt

echo Hello World
The first command that we will see is the echo command. However note that Linux command are case sensitive.

Here all command and their options are in small letter unless otherwise mention.

This command is used to display some message on the screen.
Switch to the terminal . A general procedure to open a terminal is already explained in another spoken tutorial.

Type at the prompt echo Hello World and press Enter

This prints the customary Hello World message on the screen.
Type at the prompt
echo $SHELL
We can also use the echo command to display the value of a variable.
Type at the prompt echo dollar SHELL and press Enter.
This outputs the present shell being used.
Display Slide 2

(click to talk about next escape sequence)r

We can also use escape sequences with echo command. For this in Linux we need to use the -e option.
Common escape sequences include \t for tab, \n for new line and \c is a escape sequence which when used causes the prompt to be displayed on the same line.
Type at the prompt
echo -e 'Enter a command\c'
This can be useful if say we want a prompt message before entering something.

Type at the prompt

echo space hyphen e within single quote Enter a command backslash c and press Enter We will see that the prompt will be display after printing Enter a Command on the same line.

Type at the prompt
uname -r
You may want to know what version of Linux Kernel you are running.
To know this and many other characteristics of our machine we have the uname command.Type at the prompt
uname space hyphen r .
Type at the prompt

who am I

To know what is your username, type who am I and press Enter.
This in fact comes from the who command that enlists all the users currently logged into the system in case your system is a multiuser system.
Type at the prompt
passwd
Sometimes your login password may get compromised and/or you may want to change it. For this we have the passwd command.

Type at the prompt passwd and press Enter.

When you type this command you would be asked to type the current password.
Here I would be typing my system's current password. When that is correctly entered ,you will have to enter your new password and then retype it to confirm.
Display Slide 3 But what if we have forgotten our current password? Then also the password can be changed without knowing the current password, but that can only be done by the root user.
Keep Slide 3 Now who is a root user? He is a special person with special privileges.
To draw an analogy we can say a root user is similar to a user in Windows with Administrator status.
We may be interested in knowing the system date and time. For this we have the date command.
Type at the prompt
date
Type date in the terminal and press Enter. It will show you the present system time and date.
As we can see the date command gives both date and time. This is a very versatile utility and has many options as well.
Type at the prompt
date +%T
Type at the prompt
date space plus 'percentage ' sign capital T and press enter
It gives us only the time in hh:mm:ss format.
Type at the prompt
date +%h
Type at the prompt, date space plus 'percentage sign' small h and press enter
This gives the name of the month
Type at the prompt
date +%m 
Type at the prompt
date space plus percentage sign small m  and press Enter. It gives the month of the year  in numerical format. Here it is showing 02 for the month of February. Match this according to the  output you are getting.
Type at the prompt
date +%y
Type at the prompt


date space plus percentage sign small y and press Enter. It gives last two digit of the current year.

Type at the prompt
date +”%h%y”
We can combine these options as well. For Example, Type at the prompt
date space plus within double quotes percentage small h percentage small y and press Enter. Here it is showing February 11.
Type at the prompt
cal 
Another related command is the cal command. Though not as common this helps you to see the calender of any month and any year.

To see the current month of a year type at the prompt cal and press Enter.

To see the calander of any

orbitary month say december 2070

Type at the prompt

cal 12 2070

Type at the prompt
cal  12  2070 and press enter
This gives the calendar of December 2070
Before moving ahead let us discuss a little bit about files and directories.
Display Slide 4 In Linux almost everything is a file. Now the question is what is a file? In real file a file is where we store our documents and papers. Similarly a Linux file is a container for storing information.
Display Slide 5 Next what is a directory? A directory can be understood as a collection of files and other (sub)directories.
And a directory helps us in organising our files in a systematic manner . This is like what we call folders in Windows.
Type at the prompt
echo $HOME
Then when we login into the Linux system we are by default in a home directory. To see the home directory type
echo dollar HOME and press enter
Type at the prompt

pwd

The next command helps us to see the directory we are currently working in. Its pwd that stands for present working directory.
Once we know of our directory we would also want to know what are the files and subdirectories in that directory. For this we have the ls command which is probably the most widely used command in Unix and Linux.
Type at the prompt

ls

Type the command ls and press enter. Now observe the output.
Files and subdirectories are generally shown with different colours.
Type at the prompt

ls --all

ls is a very versatile command and has many options. Let us see some of them, Type at the prompt

ls space hyphen hyphen all

This shows all the files including the hidden files(hidden files here are filenames starting with dot (.))
If we not only want to see the file but also get more information we can use the hyphen l option.
Type at the prompt

ls -l

Just type the command ls hyphen l and press enter.
It gives us the file permissions, file owner's name, last modification time,file size in bytes etc. Explanation of the fields of this option is beyond the scope of the present tutorial. Ls can be gives with many option which we can see later.
Instead of just displaying all these information on the screen, we may store it in a file. In fact we can store the output of any command in a file in this way.
Type at the prompt

ls -l > fileinfo

Just type the command followed by the right angle bracket and the file name. Say we write ls hyphen l right angle bracket space file info and press Enter. Now all the files and directories information will be directed into the file names fileinfo
Type at the prompt

cat fileinfo

But how do we see the content of this file? For this we have the cat command. Just type cat and the name of the file here it is fileinfo and press enter. Now you can see its contents.


Type at the prompt

cat file1

Infact the other main use of cat is to create a file. For this type cat greater than file1
Now when we press enter the command waits for input from the user. Whatever we type will be written into the file. So type some text. Now press enter key to indicate the end of the input. Now press Ctrl d key together
Press Ctrl+d If a file by name say file1 already exists, then the user input will be overwritten on this file.
Type at the prompt

cat >> file1

If you wish to append to the end of an existing file file1 ,type at the prompt cat double right angle bracket file1
Likewise there are several other commands that we could have discussed, but we would keep it to this for now. In fact even for all the commands discussed there are many options and possibilities untouched here .
Display Slide 6 This brings us to the end of this 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 http://spoken-tutorial.org/NMEICT-Intro This is Shambulingayya from IIT Bombay signing off . Thanks for joining.

Contributors and Content Editors

Nancyvarkey, PoojaMoolya