Students frequently turn to Computer Class 11 GSEB Solutions and GSEB Computer Textbook Solutions Class 11 Chapter 6 Basic Ubuntu Linux Commands for practice and self-assessment.
GSEB Computer Textbook Solutions Class 11 Chapter 6 Basic Ubuntu Linux Commands
Question 1.
What is command prompt?
Answer:
Prompt command executes our specific task. It suggest that now interface is ready to dialogue with user in interface format. Once prompt command is seen, we can type any command.
Question 2.
DescrIbe shell. Name any three Linux shells.
Answer:
Shell
- Shell is command line interface.
- It is programmed for user for mutual dialogue.
- It is command language interpreter that gives, accepts and interprets it.
- Shell implements according to given instruction and to show result it consults kernel.
- There may be many shells available to work on Ubuntu Linux system, but on any given system the number of shells will vary. Some prevalent shells available with Linux are as under:
- Bourne shell (sh)
- C shell (csh & tcsh)
- Corn shell (ksh)
- Bash shell (sh)
- Abbreviated name with sh is Bourne shell. It is the primary shell of Unix used as command line interface. It provides basic organization for shell script programming.
- Last bash shell is a new addition of Bourne shell. At present bash is considered as authentic shell for Linux system.
- C shell known as csh is a shell on Linux system itself. New edition of csh is known as tcsh.
- Corn shell is known as ksh. It is made of features of sh and csh.
Question 3.
How shells interpret command? Explain with suitable figure.
Answer:
Shell
- Shell is command line interface.
- It is programmed for user for mutual dialogue.
- It is command language interpreter that gives, accepts and interprets it.
- Shell implements according to given instruction and to show result it consults kernel.
- There may be many shells available to work on Ubuntu Linux system, but on any given system the number of shells will vary. Some prevalent shells available with Linux are as under:
- Bourne shell (sh)
- C shell (csh & tcsh)
- Corn shell (ksh)
- Bash shell (sh)
- Abbreviated name with sh is Bourne shell. It is the primary shell of Unix used as command line interface. It provides basic organization for shell script programming.
- Last bash shell is a new addition of Bourne shell. At present bash is considered as authentic shell for Linux system.
- C shell known as csh is a shell on Linux system itself. New edition of csh is known as tcsh.
- Corn shell is known as ksh. It is made of features of sh and csh.
Question 4.
Write the steps used to start a terminal In Ubuntu Linux.
Answer:
Starting up the Terminal
- In Linux terminal a separate window is given for opening graphics interface command line console.
It appears like text monitor and functions similarly. - To open terminal window give command application → accessories → terminal, or press Ctrl + Alt + t at a time.
- Once window is clearly seen certain letters and figures and some special signs and at last $ will be followed by cursor.
- Here administrator@ubuntu:~$_ the first word is username i.e. administrator. There after there is sign @. It is followed by the name of the computer system one is working on is shown. For example here it is Ubuntu and lastly you see a sign. After the sign the name of the directory is shown however here you see That is because the tasking begins only from home directory.
- Then $ sign is seen which is called command prompt. It shows that now interface is ready to dialogue with user in the form of commands. Command is a programme which completes a specific task.
Question 5.
Explain following command in detall:
Is, cat, we, chmod
Answer:
Moving Around the File System
- 1s command gives us list of present directory or files / directories available in it.
Command : $1s
Output :
Explanation : Here, the list of files in current directory files and directories in it will be shown. - Let us make a new file ( hidden )
Command : $cat > Kumar,
Type, kumar Prakashan is a wellknown Publisher and give Ctrl + D
Example : A hidden file named Kumar will be made.
Now on giving Is and viewing list. Kumar named file will not be seen in it. - To view list of Hidden File, 1s – a (a for all) command will be given.
Command : $ 1s – a
Output :
Explanation : On giving 1s – a files with .and… and will be shown along with ordinary files too. $ls – r $1s – r will show files in reverse order.- $1s = \ will show time based file list.
- $1s – F All executive files will be shown by * and directory by ‘ / ’ signs.
- $1s – I will show in detail long lasting files. There will be one file on one line.
- List of other options used with Is is shown in the following list.
Option | Usage |
1s ~ | Lists the files that are in user’s home directory. |
1s – [svics]* | Lists all the file in which the first character of the filename matches with any of the given alphabets within the square brackets. The remaining part of filename can contain and valid ASCII character. |
1s [n-s] [5-7]?? | List all files with 4 character filename. With the condition that the first character is in the range n to s, second character is in the range of 5 to 7, whereas the third and fourth characters are any valid ASCII character. |
1s -r | List the files by sorting them in reverse order. |
1s -t | List the files by sorting them based on their modification time. |
1s -f | List the files and mark all executable files with *and directories with / symbol. |
1s -l | List one file per line. |
Some Options of 1s Command
Working With Files
- To prepare text file in Linux, generally nano, pico, vi, vim, ed and such other text editors can be made. Still if user wants to make file more spedily he uses cat command.
- By cat command new file can be made. At the end of file new information can be added and by merging two files a new file can be made. For example, here we go into Directory of Gujarat and make there file of Abad.
- Making a new file
Command : $cat > Abad seen. Here write Data for File
Then give Ctrl + D
Output :
Explanation : New file Abad will be made.
Note : Here the sign ‘>’ used in command is called redirection sign. - Viewing data of file made :
Command : cat Abad.
Output : Will show the writing in the file.
Explanation : For viewing writing in Abad file. - For adding more information at the end of the file :
Command : $cat >> Abad. At the end of the file, type additional information.
Give Ctrl + D and come out.
Explanation : New writing will be added at the end and to view it give $ cat Abad and view output.
Note : Here instead of ‘>’ sign ‘>>’ redirection sign will have to be used. If there is an existing file on giving command cat > filename, new writing will be written on the previous writing. - Merging files :
Commanad : Give $cat > file 1 and type the writing given below. - We have started ubuntu Linux commands :
Command : Give $cat > file2 and type as under.
We have learnt cal, date, be, echo, passwd, clear, man, pwd, commands
Command : Scat filel file2 > file3
Explanation : File3 will be a new file. The writing of filel and file 2 will be seen in it.
Command : $cat file3 and view output.
Counting Letters, Words and Characters in a File (wc)
- wc command is used to calculate total number of lines, words and letters in a file.
- wc command is accompanied by three options.
- To know number of lines -l is used.
- To know number of words -w is used.
- To know number of letters -c is used.
- For example, to know the number of letters in Abad file give following command.
Command : wc-c Abad
Output : 80 Abad
Explanation : Will show calculation of number of letters. - Give following command if all information is required at a time. wc -lwc Abad
Changing Permissions (chmod)
- 1s-1 in which (1 = long listing). When list is seen through this in one line list of 1 file is seen.
Command : 1s-1
Output :
Explanation : The list of details in the present directory will be seen. - Here in our file method total information about an object is given. Object means a file, a directory or a process as seen in the figure above.
- Here you can see administrator as owner of object.
- The size of object is seen by ‘size
- The date of object is seen by ‘date
- The time of object is seen by’time
- Name of object is seen by’ name of file or directory
- Now let us understand permission of file.
- First box of figure shows type of object.
- If there is hyphen(-) in the first box, it indicates files.
- If letter’d’ is there, it indicates directory.
- If letter ‘p’ is there, it indicates process.
- In Linux for any object three permissions are given.
- Permission for reading is known as (read permission) -r.
- Permission for deleting and writing is known as (delete and write permission) -w.
- Permission for implementation is known as (execute permission) -x.
- When there is -it means that no specific permission is granted.
- In figure boxes 2, 3, 4 give owner and user permission.
- Boxes 5, 6, 7 is permission given to group of users.
- Places 8, 9, 10 clarify permission granted to some user or a group of them for use of file.
- Here we can give or remove ownership by giving -r, -w, or -x.
- Similarly, this permission can be granted in terms of numbers too. To show number type permission depends on 8 in Octel Number System.
- For this see the table below:
Permission in Text Mode | Permission in Octal Mode | Meaning |
— | 0 | No permission assigned |
–x | 1 | Only execute access is allowed |
-w- | 2 | Only write access is allowed |
-wx | 3 | Write and execute access are allowed |
r– | 4 | Only read access is allowed |
r-x | 5 | Read and execute access are allowed |
rw- | 6 | Read and write access are allowed |
rwx | 7 | Everything is allowed. |
Octal Numbers and Permission
Changing Permission(chmod)
- We use command chmod to change permission. It is also known as change mode option.
- Remember the following Table for giving permission.
Category | Operation | Permission |
u-user | + assign permission | r – read permission |
g-group | – remove permission | w – write permission |
o-other | = assign absolute permission | e – execute permission |
a-all |
Abbreviation Used by chmod
Example-1 : Firstly, see only that file list for which permission is to be granted.
Command : 1s – 1Abad
Output : -rw – -r – – r – – administrator administrator 750 2013-05-21 Abad
Explanation : Now you will not be able to write in this file. The reason for that it there, additionally, it will not also allow to delete this file.
Example-2: Now if permission to owner, group, and others for execution is to be granted, give the commands as under:
Command : chmod ugo+ x Abad
Output : -r -x r-x r-x
Explanation : Give 1s- 1 Abad. Then on looking into execution, permission in all the three will be seen.
Now, we take up an example in the form of numbers.
Example-3 : Firstly, we remove all the permissions from Abad file, because if no permission is to be granted 0 number is to be given.
- Give chmod 000 Abad
- Output : – – – – – – – will be seen.
- For numbers see table with eight digit numbers. Give number to grant permission to user, groups or others as you wish.
- For example, here there number 6 for granting permission to user to read and write.
- There is number 1 for execute permission to group.
- If others are to be given permission to read and execute the number is 5.
Command : on giving chmod 615 Abad
Output : -rw— xr-x will be seen.
Question 6.
What is the meaning of internal commands in Ubuntu Linux ?
Answer:
Command Syntax
- The construction of Linux command is uniform. It has three parts.
(1) Name : Name of Command
(2) Option : We have to attach additional options that which modify the bahaviour of commands.
When options are to be shown, the process begins with With command there may be zero or more options. Generally, the option is one letter or number. For example, cut-d, here cut is a command and -d is option.
(3) Arguments :-
- Zero or more informational units enabling command to complete its task
- There may be zero or more arguments to complete any task
- In the matter of argument a given command may not take any attached value. Some commands take it in a specified number, whereas some commands take it in any number.
-
- Linux command can be classified in two ways.
(1) Internal Command :
- Those commands which can be directly implemented are called internal command. These commands do not generate any new process.
- For example, the following will be stated on typing $type pwd.
pwd is a shell bulletin.
(2) External Command :
The majority of commands used in Linux are external commands. Such command as are in binary file in a separate way or /shin,/ use/sbin or usr/local/bin. They are stored in directory. They are implemented by kernel and make a process ID. To know whether command is external or internal type command is used. Its syntax is $type command.
- For example,
Command : $type info
Output : info is/user/bin/into
Command : $type cal
Output : cal is/ user/bin/info
Command : $type cp
Output : cp is/bi/cp
All these are internal commands.
However, when we give,
Command : $type pwd
Output : Output pwd bulletin is shown, which is internal command.
Question 7.
How can you find help for any command in Ubuntu Linux ?
Answer:
Getting Help on the Linux Commands
- To obtain information about any command in Linux two inbuit commands are given.
(1) Help (2) man.
(1) AIl option and we use in – h (- help) in Linux support Linux option.
Output :
Explanation : This brief description will show how to use.
(2) man : man is short form of manual. It activate and manual for command.
Output :
Explanation : cp (Copy) will give total information about command. This information may spread in to more than one page. For this on giving Enter key lines will be scrolled one by one. On giving f it will be forward Page. On giving b it will be backforward page. To come out of is press Key q.
- Whatis command :
This command gives and description of any command in only one line. It excludes other information.
Command : Whatis cat
Output :
Explanation : One line information about cat will be shown. - apropos command :
- Sometimes, it so happens that we do not know what to look for about a specific command. At that time we can use apropos command.
Command : $ apropos echo.
Output :
Explanation : You will be shown information of command of the information containing word echo.
Here if on giving command and move, copy, file a very long, list will be shown.
Question 8.
Explain different wildcard characters, giving suitable example.
Answer:
Pattern Matching – The Wildcards
- →* and ? are letters known as wildcard letters. We use them to locate files specially patterned files.
- For example, $1s a* → Will show flies beginning with a.
- $1s ??? → Will show files having three letters.
- $1s ?K* → First letter can be any, second will be K and thereafter any number of letter can be there any number of times.
- $1s[ackr]* → First letter can be any, second will be K and thereafter any number of letter can be there any number of times. First letter will show file names beginning with a or c, or k or r.
- $1s[! ackr]* → Will show file names beginning with letters other than letters a,c,k,r.
- $1s[C-K]* → Will show file names beginning with letters C to K.
- $1s[! C-K] → Will show file names other than those beginning with first letters C to K.
Wildcard | Pattern to be matched |
* | Any number of characters including none |
? | A single character |
[abc] | A single character – either a, b or c (user can use other characters also). |
[!abcl | A single character other than a, b or c (user can use other characters also). |
(p-s] | A single character within the ASCII range of the characters p to s (user can use other characters also) |
[!p-s] | A single character that is not within the ASCII range of the characters p to s (user can use other characters also). |
The Wildcard Characters
Question 9.
Explain the use of pipes, giving suitable example.
Answer:
I/0 Redirection
- We know that standard input device is keyboard and standard output device is monitor. But sometimes, redirection of input or output is helpful in going to file or printer.
- syntax: Give command > filename. For example, 1s > Note
- Here, when Is command is executed, then in place of output monitor a file named Note will be made.
For this give cat Note and see output. It is possible to have other examples too. - For example, cal>Temp, date>Temp 1.
cal test 1> temp3 - In the above example, the current month calendar will go to file Calendar Temp, today’s date will go to Tempi and data of testl will go to file named temp3, which means that by this command file itself will be copied.
- and< less than symbol shows redirection of input.
- Syntax: command<filename
- For example, here instead of wc-1 < in Abad operating system, we shall give instruction from Abad to
obtain input. For example, cat<filename.
Piping :- Piping facility is helpful in joining Linux command to file. The facility of transmitting output of one command as input of another command is known as piping facility. For this there is piping (|) sign is typed.
- For example, on giving $1s | output command of Is will give wc command as input. It means that it will calculate say the number of lines in Is command.
Question 10.
What is redirection ? Explain giving suitable example.
Answer:
I/0 Redirection
- We know that standard input device is keyboard and standard output device is monitor. But sometimes, redirection of input or output is helpful in going to file or printer.
- syntax: Give command > filename. For example, 1s > Note
- Here, when Is command is executed, then in place of output monitor a file named Note will be made.
For this give cat Note and see output. It is possible to have other examples too. - For example, cal>Temp, date>Temp 1.
cal test 1> temp3 - In the above example, the current month calendar will go to file Calendar Temp, today’s date will go to Tempi and data of testl will go to file named temp3, which means that by this command file itself will be copied.
- and< less than symbol shows redirection of input.
- Syntax: command<filename
- For example, here instead of wc-1 < in Abad operating system, we shall give instruction from Abad to
obtain input. For example, cat<filename.
Piping :- Piping facility is helpful in joining Linux command to file. The facility of transmitting output of one command as input of another command is known as piping facility. For this there is piping (|) sign is typed.
- For example, on giving $1s | output command of Is will give wc command as input. It means that it will calculate say the number of lines in Is command.
Question 11.
List the filter commands used in Linux.
Answer:
Filters
- Filters are such commands as accept data from keyboard, undertakes process on it and shows results on monitor. Here we shall consider filters head, tail, cut, paste, sort and uniq.
Displaying lines from top of the file (head) : - Head command is used to view the needed lines from the beginning of the file.
- If we write head without giving any option, by default the first ten lines are shown.
- Example-1 : We have file named cities. It has 15 lines.
Friends, if possible write 1 Abad 2.Baroda 3.Surat., and so on. Thereby the output is immediately known.
Command : $head Cities
Output : First 10 lines will be seen.
Example-2 : If first three lines are to be viewed.
Command : head-3 Cities
Output : The first three lines will be seen.
Explanation : Here with head command one number is required to be given as argument.
Displaying lines from bottom of the file (tail) :
Tail command acts opposite to head command.
Example-1 : Suppose that there are 15 lines in file named Cities.
If we give $tail Cities the last 10 lines will be seen.
Example-2 : If we give -5 Cities, last five lines will be seen.
Example-3 : On giving $tail+5-n Cities all lines after 5 will be seen.
Here lines 5 to 15 will be seen.
Pattern Matching (grep)
To locate any keyword in file command grep is used. This command operates on the basic concept of search globally for a regular expression (g/re/p) and locates regular expression from the whole document and when it is located it shows the relevant line.
Open file giving Scat command.
(1) Command : $grep “Trishsa” Student
Output :
(2) Command : $grep “Commerce” student
Output :
Explanation : Will show all the records of commerce. 4 records are there because 2 are in upper case.
(3) Command : $grep -c “commerce” student
Output : 2
Here the answer is 2. -c means count means commerce will calculate record. Do not consider uppercase “commerce.”
(4) Command : $grep -i “commerce” student
Output :
Explanation : Here record will show 4.-i means ignore the case. So here all commerce will be shown.
(5) Command : $grep -ni “commerce” student
Output :
Explanation : Here -n means number is also shown which means the serial no in data too is shown. Here 1,2, 4, 6 are shown further.
(6) Command : $grep -v commerce student
Output :
Explanation : V means inverse (Opposite). Here all records except commerce will be shown. If we give -vi capital commerce will not be shown.
(7) Command : $grep -w “commerce” student
Output :
Explanation : grep “commerce” student will show output that will have only such record as will show desired whole word.
(8) Command : $grep -o “commerce” student
Output :
Explanation : Only word will show. If we give-oi all words with commerce will be shown.
(9) Command : $grep -1 “volleyball” student
Output : student
Explanation : Only file name will be shown.
Note : It is not mandatory to write keywords between ” “.
- There would be no difference in output if you write $grep Abad student or $grep “Abad” student.
- Out of the following options you can select any number of options at a time.
Option | Usage |
-c | Return only the number of matches, without quoting the text |
-i | Ignore case while searching |
-l | Return only file names containing a match, without quoting the text. |
-n | Return the line number of matched text, as well as the text itself. |
–v | Return all the lines that do not match the text. |
-w | Return lines which display only whole words |
-o | Shows only the matched string |
Options of grep Command
- In grep command regular word cluster can be shown. For example, the words beginning with Ab and ending in S.
Command : $grep “Ab.*S” student
Explanation : In repetitive word clusters, generally the following are found as shown in the table.
Repetition Operator | Meaning |
? | The preceding item is optional and matched at most once. |
* | The preceding item will be matched zero or more times. |
+ | The preceding item will be matched one or more times. |
[n] | The preceding item is matched exactly n number of times. |
{n,} | The preceding item is matched n or more number of times. |
{,m} | The preceding item is matched at most m number of times. |
{n,m} | The preceding item is matched at least n number of times, but not more than m number of times. |
Note : Here, we find those words, which define in red color.
Question 12.
Choose the most appropriate optain from those given below :
1) Which of the following command is used to count the total number of lines, words, and characters contained in a file ?
(A) countw
(B) wcount
(C) wc
(D) wordcount
Answer:
(C) wc
2) Which of the following command is used to removes files ?
(A) dm
(B) rm
(C) delete
(D) erase
Answer:
(B) rm
3) Which of the following command is used to removes the directory ?
(A) rdir
(B) remove
(C) rd
(D) rmdir
Answer:
(D) rmdir
4) Which of the following command is used to count just the number of lines contained in a file ?
(A) wc -r
(B) wc -w
(C) wc -c
(D) wc -l
Answer:
(D) wc -l
5) The command chmod 761 letters is equivalent to which of the following access rights ?
(A) chmod u=7, g = 6, o = 1
(B) chmod a = 761
(C) chmod u = rws, g = rw, o = x
(D) chmod 167
Answer:
(C) chmod u = rws, g = rw, o = x
6) Which of the following refers to the maximum length of a filename in Linux ?
(A) 8
(B) 10
(C) 200
(D) 255
Answer:
(D) 255
7) The hierarchy of a series of directories branching in a system starts from which of the following directories ?
(A) \home
(B) \root
(C) /home
(D) /root
Answer:
(D) /root
8) Which of the following command is used to copy a file ?
(A) tar
(B) cpio
(C) cp
(D) copy
Answer:
(C) cp
9) Which of the following command is used to display your current working directory ?
(A) path
(B) pwd
(C) prompt $p$g
(D) dir
Answer:
(B) pwd
10) Which of the following command is used for searching a pattern in a file ?
(A) grep
(B) find
(C) lookup
(D) All of the above
Answer:
(A) grep
11) Which of the following is not a redirection symbol ?
(A) >
(B) <
(C) *
(D) >>
Answer:
(C) *
12) Which of the following syntax is correct to assign a read permission on a user file ?
(A) chmod r filename
(B) chmod u+r filename
(C) chmod filename r
(D) chmod filename u+r
Answer:
(B) chmod u+r filename
13) Which of the following refers to the minimum arguments of cp command ?
(A) One
(B) Two
(C) Three
(D) None of these
Answer:
(B) Two
14) The mv command in Linux is used for which of the following purpose ?
(A) To rename a directory
(B) To move a file
(C) To copy a file
(D) All of the above
Answer:
(D) All of the above
15) Which of the following command is used to view one page content on the screen at a time ?
A) More
(B) more
(C) PAGE
(D) page
Answer:
(B) more
Computer Class 11 GSEB Notes Chapter 6 Basic Ubuntu Linux Commands
Listing the Shells Available on the System
Cat command is used to view all the shells in the system.
Command : $cat/etc/shells
Output :
Explanation : List of all the shells present in your computer.
Determining the Default Shell
- With every Ubuntu Linux account there is a specific shell. Every time that one logs in, this predetermined shell is used by default. It is also known as environmental variable.
- Predetermined value of Shell is stored in an environmental variable.
- To show the value of any variable echo command is used.
Command : $echo $SHELL
Output :
Explanation : To know predetermined shell.
Changing the Current Shell
- If you want to work with any other shell interface, instead of the one by default, then type the name of that shell on command line.
- For example, if you want to use C shell, type csh. If you want to use corn shell, then type ksh and if you want to return to shell predetermined, then type exit against command prompt or give Ctrl + d.
Note : This modification in shell is temporary, which means that so far as you are on command line, it will continue.
Issuing General Purpose Commands
- To give command you have to type its name followed by necessary options and assigned value.
- Having typed some initial letters of some command and give Tab key to enable shell to give the
remaining information automatically. - Calender (cal)
- cal command is used show calendar of a specific month or that of the whole year.
Command : $cal
Output :
Explanation : Will show calendar of current month.
Command : $cal 5 2013.
Explanation : Will show calendar of May.
Command : $cal 2013.
Explanation : Will show calendar of twelve months of 2013.
Conunand : $cal 2013
Explanation : Will show Pagewise calendar of 2013
In the above command we have combined two commands cal and more. Here with more cal command result is obtained as input. When two commands are combined there pipe( ) sign between them.
- cal command is used show calendar of a specific month or that of the whole year.
- Date Command
- By using date command date and time of computer system are shown. Command Output
Command : $date
Output :
Explanation : The present date and time of computer system are shown.
Note : Specific formed indicators can also be used after date command as argument. At the beginning
of every form + sign, then % sign and then a letter showing specific form is typed.
Command : $date + % D
Output : 05/13/13
Explanation : The present date will be shown as MM/DD/YY.
- By using date command date and time of computer system are shown. Command Output
- After writing the following letters after $date+% the output will be shown accordingly.
- d – date of the month
- H – hour
- T – hh:mm: for the form of time
- m – month of the year
- M – minute
- D – mm/dd/yy for the date of form
- y – last two numbers of year
- S – Second
Command Line Calculator (bc)
- In Linux be a command line calculator. It calculates simple mathematical functions and also coverts one number method figures into another. The full form of be is basic calculator.
- Apart from that, this command is used in scientific calculations too.
Command : $bc-l
Output : - In figure $bc prompt is not seen on screen. That indicates that be command is now ready to receive input from you.
- In be -l is switch is used for inclusion in Standard Math library.
- Now type the formula to be calculated against blinking line(cursor) and then press Enter key.
Command : 9 * 8
Output : 72
Command : 25 + 75/5 * 10 + (50 – 20)
Output :
Note : Here we can take up calculation of addition, multiplication, subtraction and division, Trigonometrical calculation of sine, cosine, arctangent, square root and log can also be done.
Command : l(15)
Output : 2.708050
Explanation : Natural Logarithm of 15 will be shown
Command : sqrt (625)
Output : 25
Explanation : Square root of 625 is seen. - ibase and obase :
- ibase means inputbase. It permits us to arrange the number writing method in input of a given function.
- obase means outputbase. It is used in the way we want to show the result of function.
- You must know that there are four number systems.
- They are Binary, Decimal, Octel and Hexadecimal. Here any number system can converted into some other to be shown.
- Please remember that computer possesses by default → ibase and obase decimal number system.
- Now if you propose to 340 decimal into Hexa, then you have to use only obase. The reason for this is that ibase is by default decimal. (When both ibase and obase are to be changed, first give obase and then ibase.)
- Command : Give obase = 16.
- Now type the number to be converted into Hexa and give 340 ↵ Enter.
Output : 154
Explanation : Here 154 is decimal number with value 340 according to sixteen digit number system.
- Converting 110110 binary in decimal system :
Command : ibase =2 (For making input binary)
obase=10 (For having output in decimal)
Type : 110110
Output : 54
Explanation : Equivalent number of 245 is 1001000101
Displaying a Message (echo)
- To show message on terminal echo command is used.
Command : $echo “we are Indian”
Output : We are Indian
Explanation : To show on monitor the message “we are Indian”
Note : To the value of any variable too echo command can be used. - For example, to prepare a variable named A
Command : $A=100
Echo “The value of A is $A
Output : The value of A is 100
Explanation : Here, in echo letter A is typed twice. First is written in a straight forward manner.
It is a common letter. Before second A, sign $ is placed. It gives value stored in variable.
Some other command can also be used with echo command. - For example, here using date
Command : $echo “current time is ‘date + %T”
Output : current time is 16 : 30 : 45
Explanation : In echo statement what is to be implemented through Linux command is shown is reverse quote () ( on quote sign key is available. Here, shows time in Format.
Command : $echo “Today’s date is date +%D”
Output : Today’s date is 12/30/2013
Explanation : date +%D command will show date in mm/dd/yy format.
Changing Password (passwd)
By the help of the present login account password is given and it is a already given, it can be changed. Here password of administrator will be changed.
Command : $ password :
Output : changing password for administrator (current) Unix password.
Here give old (current) password. If it is correct you will be asked to type new password and then retype the some new password.
Out Put : Enter new unix password.
: Retype new unix password.
Then a message will be sent to you as under : Password update successfully.
Note : By administrator password of some other user can also be changed. For this, after command password the name of user should be typed.
Clearing the Screen (clear)
When screen is packed with letter and numbers it be comes difficult to read result. For this clear command is given. That erases the writing on screen.
(For example if username is Krupa and password Krupa is = given)
Working with Directories
- Linux directory is a very kind of file. It contain and several files and other directories. Here 7’ sign indicate the root directory. All the other directories are contained in root directory.
- When you login system, Linux automatically places you in root directory known as ‘Home Directory’
- It is prepared when account of a new user is opened.
- If you login name Krupa your home directory will be / home / Krupa.
- Name of default time working directory is preserved in system variable HOME.
Command : $echo$HOME
Command : / home / Krupa
Explanation : im24 - It means that directory named Krupa is in directory named home and home directory is in root directory.
Present Working Directory (pwd)
Once we login we can move from me directory to the other. But at any given time we can be in only one directory. That is known as current directory. To look in to it PWD (Present Working Directory) command is used.
Command : $pwd
Output : / home / administor / student / MCA.
Explanation : Here MCA directory is in student sub – directory. Directory named, student is in user named administrator. Which is it self in directory named home and home directory is in root directory.
Creating a Directory (mkdir)
- Here administrator is kept as username.
- mkdir (make directory) command enables and us to make new directory. The name in which directory is to be made should be placed after this command as argument.
Command : $ mkdir India
Output : Command prompt will be shown (Error will be shown only there is error in original command.)
Explanation : Directory named India will be found.
Note : If we make directory GUI only one directory will be made at a time. Whereas from command
prompt more than one directory can be made at a time.
Command : $ mkdir Australia London Newzeland.
Output : It will show command prompt.
Explanation : At a time directory named Australia, London, Newzeland will be made. Note : To see this command Is is used as discussed previously.
Change Directory (cd)
- The full name of Cd is (Change directory). By this command one can move from one directory to the other. For example, having gone into directory India, one can make directory named Gujarat, Rajashthan, Kerala.
Command : $ cd India [Directory named India is made.]
$ pwd (for viewing)
Output : / home / administrator / India
Command : $ mkdir Gujarat Rajasthan Kerala.
Explanation : Go into India and see output to ascerte on whether you have reached India or not. Now in India three given directories will be made.
Note : Here from pwd you will be shown the whole path directory in directory in directory.
Whereas Echo $ home will show only home directory. - Here username is administrator. To return to India from administrator type as under.
Command : $ cd…
Output : / home / administrator
Explanation : Directory named India will emerge. In the above command two dots (..) indicate parent directory. Remember to leave one space between cd command and…
On viewing after $pwd command we will see / home / administrator. - Example of use of Cd are stated in the following table.
Command Issued | Action Performed |
cd -/Desktop | Change directory to /home/username/Desktop, from any current path. Here the symbol -refers to home directory of the user. |
cd / | Changes directory to the root directory from any current path. |
cd | Changes directory to the home directory from any current path. |
cd – | Changes directory to the previously changed directory. |
cd/var/www | Changes directory directly of the www sub-directory with directory var. It is useful when we know the path explicitly. |
Sample cd Command
Remove Directory (rmdir)
- Full form of rmdir is Remove directory. With the help of this directory, unnecessary directory can be removed. But the directory to be removed not contain any other file or directory.
- For example if directory named Gujarati is to be removed first of all we must go to its home directory.
- If we are in / home / administrator,
Command : cd India
rmdir Gujarat
Output : Command will give prompt. [ If Gujarati directory is not empty error message will be shown.
Explanation : Gujarat – named directory will be deleted. - Note : It is possible to remove several directories at a time. For example, on giving rmdir Gujarat Rajasthan Keral command all the three directories will be removed simultaneously. You have to go to the directory in which the directory to be removed is there and then give command rmdir.
Command : $rm – r Gujarat
Output : Will give command prompt.
Explanation : Directory named Gujarat will be removed. If in Gujarat there is a file or directory it will also be removed by this command.
Naming Conventions in Linux
The following rules should be kept into consideration while making any file or directory in Linux.
- The file name of directory can be made of maximum 255 letters.
- Name cannot be given in / and blank space.
- Linux control characters and non-printable letters may be used.
For example, name Amyname^ -++, -{} (), test$#, xy.ab.ef etc an be used. - Keep names of files and directory meaningful and use so for as possible English alphabets, numbers, full point, hyphen ( – ) underscore ( ‘ – ’ )
- Linux follows ‘case sensitive’ So it will treat Kumar, KUMAR and kumar as distinctly separate.
Deleting a File (rm)
- Use command remove / delete to cancel out / delete one or more files. For example removing Abad file,
Command : $rm Abad
Explain : Abad file will be deleted
Command : $rm filel file2 file3
Example : All the three files will be deleted simultaneously. - The following table shows different options that can be used with command rm
Copying a File (cp)
- In Linux file can be copied by cp command. This cp command needs minimum of two arguments. The first argument to be copied is source file, whereas the second argument to be copied is target file.
- For example, we propose to copy Abad file as Megacity.
Command : $cp Abad megacity
Explanation : Here a new file megacity will be created and all the data of Abad will get into it.
Note : Here if the name given is in Target (here megacity) is in directory, file will be copied in
directory. If (megacity) directory is not there then alone it will copy file. If there is file with that name there will be overwriting without warning. - Copying several files simultaneously :
For example, filel file2 file3 are to be copied in directory named test.
Command : $cp file a file2 file 3 test
Explanation : Here file 1 file 2 file 3 will copied in directory named test.
Note : Here, remember that when one file is to be copied the name given target should compulsorily
be there in directory. If the directory with that name is not there, directory will have to be made giving mkdir. - Here are some examples of cp command.
Command | Description |
cp/vol/examples/tutorial/science.txt | Copies the file science.txt to current directory. The dot (.) at the end refers to the current directory. |
cp chap01 progs/unitl | A file named chapOl is copied within the directory progs with name unitl. (no directory with name Until should exist in progs directory) |
cp chap01 progs | A file named chapOl is copied within the directory progs with same name, (because progs is a directory). |
cp -r progs newprogs | The directory named progs along with all its contents is copied and stored as a directory newprogs. |
Renaming Files and/or Moving Files (mv)
- In Linux mv performs two functions.
- Changes name of file or directory.
- Move file and carries it elsewhere.
- For example, the name of Abad file is to be changed to Cleancity.
Command : $mv Abad Cleancity
Explanation : Having given Is if view, the name will have been changed to Cleancity and along with that it will be seen in directory. Thus, here no additional space will be utilized. - Moving more than one file in directory :
Command : $mv filel files2 file3 Kumar
Explanation : Here all the three files will be removed from directory named Kumar.
On viewing after giving Is this file will not be seen. To see it give cd Kumar. - This command is used to change the name of directory too.
- For Example, Gujarat directory is to be changed to modi.
Command : $mv Gujaratmodi
Piping Output (more)
- To see one page on screen at a time more command is used. To view page after it f (forward) and to see previous page b (backward) are used.
- If file named test is very big…
Command : Give $more test.
Similarly if there are many files and directories…
Command : Give $1s-1 | more
Compare Two Files (cmp)
- cmp (compare) command is used when two files are to be compared as a result standard output is presented.
- If the two files are different, the difference in first line and the difference it will be shown and if there is no difference prompt command will be directly shown.
- For example, if the writing in filel and file2 is different
Commanad : $cmp file 1 file2
Output :
Explanation : As the writing differs, mistake is shows. Now make writing identical copy any one file.
Command : cp file1 newfile1
cmp file1 new file1
Output : Command prompt will be seen
Explanation : Writing is identical, so no mistake is shown.
Difference (Diff)
- In Linux extension of cmp command is diff.
- Diff command compares writings of two files, shows them and indicates where differences are. Let us make two flies and see the difference in them.
- For example,
-
- Now give $diff test1 test2
- Output as on the opoosite side.
Output :
- Here sign < shows that letters c and d are in Test1, but not in test2 and the variations in Test 2 in the given lines are shown by sign >.
Slicing a File Vertically (cut)
- Head and tail commands cut information horizontally, whereas cut command does it with file information vertically. However, if we give Delimiter in file, cut command gives precise result. (Delimiter means to separate two fields with some signs such as, , : @ space % etc)
- First of all prepare file as under.
Give $cat>student and enter the following information.
Cutting charaters (-c) :
- To get specific letters from every line cut command is used with -c option.
Command : On giving $cut-c-17 Student the following output is viewed.
Output :
Explanation : Here on giving $cut-c-17-Student letters 1 to 17 will be shown as cut.-
- If $cut- 1-4, 20- Student is given lto 4, 20 and all letters after 20 will be seen.
- If $cut-c-8,10-15,24-Student is given firsdy 1-8, secondly 10-15, then 24 and all letters after 24 will be shown.
- But in the above examples, information is not viewed according to output field. That is because in field named data fixed length is not stored. So from certain fields data is cut according to letters. The result is not good-looking.
-
Cutting Fields (-f) :
-
- To solve the above problem we use Delimiter.
- The values separated by Delimiter are treated by cut command as separate fields. Here we have used as Delimiter.
Command : $cut-d -f -2 student
Output : First two fields will be seen.
Explanation : Here by d Delimiter is shown and -f shows order of field.
- Similarly, on giving $cut-d -f 2, 4-6 Student firstly field 3 and 4 and then 5 and 6 will be shown.
- $cut “,”-f 1, 3-4, 6-Student will show first field and then 3,4, 6, and all fields after 6.
Note : Field can be cut from any command list. For example, if from 1s-1 only permission is to be seen, from Date command only Year is to be seen, it is possible. For this,
On giving 1s-1 | cut-d ” ” -f -1, the first field of 1s-1 will be seen.
On giving date | cut- d ” ” f-7 year will be seen.- We are looking at present monitor. It is possible to undertake its file redirection. That we have seen earlier.
- For example, $cut -d ” ” -f 2, 4-6 Student >school is to be given.
- Here in place of monitor a file named school will be seen.
- For viewing this you can give Scat School.
Joining Contents (Paste) :
- By paste command two files can be combined. For this there should be equal number of lines in
both files. That gives expected result. - Here there are 7 fields in file named Student. We can move fields from 1-4 to part-1 and then field 5-7 to part 2 and then combine both files by giving paste command.
Note : Here you must have seen that Paste command pastes another file on the right side. We had combined files by cut command too. But cut command pastes second file below the first one.
Ordering Output (sort)
- By using sort command, the details in file can be organized in ascending or descending order.
- Like cut command it identifies the field and arranges data on specific field.
- When sort command is used without any option it arranges the whole line on the basis of file.
- In arrangement process firstly a blank, then numbers, then upper case and then lower case are worked out.
- $sort student [will be arranged in ascending order]
- $sort -r student [-r means will be arranged in reverse order]
- We can sort some fields along with cutting it too.
- $cut-d -f 2-4 student | sort
- Here field 2 to 4 will be shown and will sort on field 2. If the data in them are similar, they will sort in third field.
Note : Execution of sort command will not make any modification in original file. In the original file
the record will remain in its original condition. According to sort command the arrangement of record will be in execution only at the time of showing output.
- You can redirect this output towards any file.
For example, sort -r student>reverse
Character Conversion (tr)
- tr is to translate .tr command gives permission to operate with any letter in horizontal line. It is used to change pattern of letters from one kind to some other which is called translating or conversion.
- Example 1 : In file named student we have used as delimiter. But while showing output, if we want to keep space in place of delimiter, tr command will be useful. For this,
Command : $cat Student ? ? tr-s ‘[,]’ ‘[ ]’
Output :
Explanation : Here, space is seen where it is. Here -s option removes additional space. - Example 2 : If you want to see file named Student in upper case(capital letters) following command will be used.
Command : $cat Student | tr ‘ [a-z]’ ‘[ A-Z]1
Explanation : All lower case letters will be seen in upper case letters.
Note : This translation process will be done only at the time of showing output. The original data
will remain unchanged. If the output is to be stored in any file, we can redirect it towards new file.
Searching a File or Directory (find)
- Sometimes, we forget the location where we made a file. Find command is used to locate such forgotten file or directory.
- The given file or directory can also be located on the basis of its name, owner, type, permission, date, size and time and other parameters.
- Suppose, location of file named Student is to be located. In this case the following command will be written.
$find-name Student - If a file with name is there its path will be shown. If there is an error in command its message will be shown.
- If a file with this name is not there, command prompt will appear.
- Suppose we have made files named stu, student, student 1, stud, then for viewing them the following command can be given :
$find-name stu*
then here paths of all files beginning with stu will be shown. - The following command is used to know whether result is file or directory.
$find-name stu* -type f - Some such find commands and their expected results are described as under.
Command | Description |
find/ -type d | Search all directory and sub directory available on root only. |
find . -mtime -1 | Search objects modified within the past 24 hours. |
find . -mtime +1 | Search objects modified more than 48 hours ago. |
find ,/dir1 ,/dir2 -name script.sh | Search directories “,/dirl” and “./dir2” for a file “scrip.sh”. |
find -size 0 -delete | Search for files of zero byte and delete them from the disk. |
find -executable | Search for the executable file in current directory. |
find /home -user jagat | Search for the object whose owner is jagat within the home directory and its sub directory. |
find . -perm 664 | Search for object that has read and write authorization for their owner and group but which other users can only read. |
Example of find Command
Running Commands as a Superuser
- Friends, when we login and operate the account it is user’s account. Here we have limited rights.
For example, we cannot make new user, cannot change password and so on. - Here we do not get administrative rights because of which mistakenly made changes disrupt operative system.
- But user often needs many ‘administrative rights’. These are available only to user known as superuser.
- Sudo is required to be written before command to be executed to use this superuser account.
- adduser :
This command will create a new user on system
Command : $sudo adduser Vidyanagar
Output :
Explanation : Once additional information is filled new user will be there in home directory.
passwd :
For example, sudo passwd Vidyanagar (Here Vidyanagar is user.)
deluser :
By deluser any user can be deleted. Here before giving this command user’s files, home directory should be removed by giving commands -remove, -home.
who :
who command will prepare list of logged in users.
addgroup :
addgroup adds a new group under which users are divided into sub-groups. That facilitates better control.
delgroup :
delgroup deletes a whole group from command system. For this deletion, the users to be deleted should not be associated with other users group.
Installing new Software :
Give the following command to install programme skype from command prompt.
Command : sudo apt-get install skype
Here if password is demanded, superuser’s password should be given. This is first user’s password. It is given when Linux is installed.