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

From Script | Spoken-Tutorial
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.
This command is used to display some message on the screen.
For example


echo Hello World

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.
For example echo dollar SHELL
This outputs the present shell being used.
Display Slide 2

(click to talk about next escape sequence)

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.

For example

echo hyphen e within single quote 
Enter a command backward slash  c and press enter.
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 .
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.

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 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 'percent' capital T
It gives us only the time in hh:mm:ss format.
Let us see few more examples in it
Type at the prompt
date +%h
date space plus 'percentage h
This gives the name of the month
Type at the prompt
date +%m 
Similarly,
date space plus percent m gives the month of the year 
Type at the prompt
date +%y
Similarly


date space plus percent y gives last two digit of the year.

Type at the prompt
date +”%h%y”
We can combine these options as well. Like
date space plus within double quotes percent h percent y . This gives us December 10. But here we need double quotes.
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.

cal

Here it shows calender of december 2010.
Type at the prompt

cal 12 2070

Similarly


cal  12  2070
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 
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 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, ls can be used with many options which we will see later.

ls 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
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.
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 greater than character and the file name. Say we write ls hyphen l greater than 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 and you can see its contents.

cat fileinfo

By giving multiple filenames the content of multiple files can be seen one after the another.
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. The input is ended by pressing Ctrl d
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

cat greater than greater than 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 . For that use the man command followed by the name of the command you want to know about.
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

Pravin1389