Difference between revisions of "BOSS-Linux/C2/General-Purpose-Utilities/English"
Nancyvarkey (Talk | contribs) (Created page with "Pending") |
PoojaMoolya (Talk | contribs) |
||
Line 1: | Line 1: | ||
− | + | '''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]] | ||
+ | |||
+ | {| style="border-spacing:0;" | ||
+ | | style="border-top:0.035cm solid #000000;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| <center>'''Visual Cue'''</center> | ||
+ | | style="border:0.035cm solid #000000;padding:0.097cm;"| <center>'''Narration''' | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Display Slide | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Hello, welcome to this spoken tutorial on General Purpose Utilities in Linux. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| In this tutorial we will make ourselves acquainted with some of the most basic yet heavily used commands of Linux. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| The main motivation of this is to give you a headstart about working with Linux. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Switch to the terminal | ||
+ | |||
+ | Type at the prompt | ||
+ | |||
+ | echo Hello World | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| This command is used to display some message on the screen. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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 | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| This prints the customary Hello World message on the screen. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | echo $SHELL | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| We can also use the echo command to display the value of a variable. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Type at the prompt '''echo dollar SHELL''' and press Enter. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| This outputs the present shell being used. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Display Slide 2 | ||
+ | |||
+ | (click to talk about next escape sequence)r | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| We can also use escape sequences with echo command. For this in Linux we need to use the '''-e''' option. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | echo -e 'Enter a command\c' | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | uname -r | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| You may want to know what version of Linux Kernel you are running. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| To know this and many other characteristics of our machine we have the '''uname''' command.Type at the prompt | ||
+ | |||
+ | '''uname space hyphen r .''' | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | ''' who am I''' | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| To know what is your username, type '''who am I ''' and press Enter. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | passwd | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| When you type this command you would be asked to type the current password. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Display Slide 3 | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Keep Slide 3 | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Now who is a root user? He is a special person with special privileges. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| To draw an analogy we can say a root user is similar to a user in Windows with Administrator status. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| We may be interested in knowing the system date and time. For this we have the date command. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | date | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Type date in the terminal and press Enter. It will show you the present system time and date. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| As we can see the date command gives both date and time. This is a very versatile utility and has many options as well. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | date +%T | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | date space plus 'percentage ' sign capital T and press enter | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| It gives us only the time in hh:mm:ss format. | ||
+ | |||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | date +%h | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Type at the prompt, date space plus 'percentage sign' small h and press enter | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| This gives the name of the month | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | date +%m | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | date +%y | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | |||
+ | date space plus percentage sign small y and press Enter. It gives last two digit of the current year. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | date +”%h%y” | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | cal | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| To see the calander of any | ||
+ | orbitary month say december 2070 | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | cal 12 2070 | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Type at the prompt | ||
+ | cal 12 2070 and press enter | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| This gives the calendar of December 2070 | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Before moving ahead let us discuss a little bit about files and directories. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Display Slide 4 | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Display Slide 5 | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Next what is a directory? A directory can be understood as a collection of files and other (sub)directories. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| And a directory helps us in organising our files in a systematic manner . This is like what we call folders in Windows. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | echo $HOME | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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 | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | pwd | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| The next command helps us to see the directory we are currently working in. Its pwd that stands for present working directory. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | ls | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Type the command ls and press enter. Now observe the output. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Files and subdirectories are generally shown with different colours. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | ls --all | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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 | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| This shows all the files including the hidden files(hidden files here are filenames starting with dot (.)) | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| If we not only want to see the file but also get more information we can use the hyphen l option. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | ls -l | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Just type the command ls hyphen l and press enter. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | ls -l > fileinfo | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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''' | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | cat fileinfo | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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. | ||
+ | |||
+ | |||
+ | |||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | cat file1 | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Infact the other main use of cat is to create a file. For this type cat greater than file1 | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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 | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Press Ctrl+d | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| If a file by name say file1 already exists, then the user input will be overwritten on this file. | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type at the prompt | ||
+ | |||
+ | cat >> file1 | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| If you wish to append to the end of an existing file file1 ,type at the prompt cat double right angle bracket file1 | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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 . | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Display Slide 6 | ||
+ | | style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| 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 http://spoken-tutorial.org/NMEICT-Intro] This is Shambulingayya from IIT Bombay signing off . Thanks for joining. | ||
+ | |||
+ | |} |
Latest revision as of 12:43, 12 November 2014
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
|
|
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
|
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. |