Advertisement

Linux Advance Interview Question And Answer ( Linux Advance Command) Linux Series- 2

Linux Advance Interview Question And Answer ( Linux Advance Command) Linux Series- 2

50)Now append data in new.txt file using cat command.
->$cat>>new.txt
I love apples.

51)How to add line numbers to non blank lines.
->$cat -b filename
52)How to add line numbers to blank as well as to non blank lines.
->$cat -n filename
53)Which command is used to sort a file?
->$sort file_name
54)How we can sort files f1.txt ,f2.txt, f3.txt
->$sort f1.txt f2.txt f3.txt
55)How to sort a file content in reverse order?
->$sort -r filename
56)How to sort a file without caring about case sensitivity?
->$sort -f filename
57)How to sort numerical data on the basis of their true value in maths?
->$sort -n filename
58)Suppose you have file named as data.txt and having content
apple,1020,aurangabad,Maharashtra
mango,422,washim,Gujarat
potato,85,pune,Goa
Sort the data according to third column
->$sort -t "," -k3 data.txt
59)Sort the data in data.txt according to second column
->$sort -t "," -k2 data.txt
60)Sort the data in data.txt according to the second column,but on the basis of
mathematical value.
->$sort -t "," -nk2 data.txt
61)Sort the data in data.txt according to the second column,but on the basis of
mathematical value but in reverse order.
->$sort -t "," -nrk2 data.txt
62)Sort the file and also print the no of occurence of elements.
->$sort filename | uniq -c
63)Sort the file and also show no duplicates and print the duplicate elements.
->$sort filename | uniq -cd
64)Sort the file and also show duplicate elements.
->$sort filename | uniq -d
*** Important
How to switch to command mode:
From Insert Mode: If you are in insert mode (where you can type and edit text),
press the Esc key. This will take you back to command mode.
From Visual Mode: If you are in visual mode (used for selecting text), press the Esc
key to exit visual mode and return to command mode.
From Replace Mode: If you are in replace mode, press the Esc key to exit replace
mode and return to command mode.
Once you are in command mode, you can use various navigation and editing
commands to manipulate text or save the file, as mentioned in the previous
response.
65)In vi mode, which symbol along with the colon is used to save the data?
-> :w
66)In vi mode which symbol along with colon is used to quit without saving the
data?
-> :q!
67)In vi mode which symbol along with colon is used to save the data and quit
from the file?
-> :wq
68)In vi mode which symbol along with colon is used to quit without saving the
data?
-> :q!
69)In vi mode, how can we go to the 10th line?
-> :10
70)In vi mode, how can we go to the last line?
-> :$
71)In vi mode ,if we want the numbering for each line for an example
hello ---> 1 hello
hii 2 hii
3
how are you 4 how are you
which command can be used?
->:set nu
72)Now we want to remove the numbering which we set in earlier question,then
which command can be used?
->:set nonu
73)How to search in a file opened using vi mode?
->/search_word
74)For example, let's say you have a file named example.txt with the following
contents:
This is an example text file
with some random words in it.
If you want to search for the word "example" in a case-insensitive manner, then
which command can be used?
->:set ic
/EXAMPLE
75)How to turn off case-insensitive search.
->:set noic
76)How to replace an existing word with a new word in vi mode?
->%s/existing_word/new_word
77)How to replace a existing word with new word in vi mode(Replace all
occurrence in each line)
->%s/existing_word/new_word/g
78)What is the difference between %s/existing_word/new_word and
%s/existing_word/new_word/g?
->
1. `%s/existing_word/new_word`: This is a basic search and replace operation
that replaces the first occurrence of "existing_word" with "new_word" in a given
text or string. It's typically used with tools or functions that support basic text
replacement. If multiple instances of "existing_word" exist in the text, only the
first occurrence is replaced.
2. `%s/existing_word/new_word/g`: The addition of the "g" at the end of the
expression stands for "global." When used with search and replace functions or
regular expressions, this will replace all occurrences of "existing_word" with
"new_word" in the given text. It doesn't stop after the first occurrence; it
continues searching and replacing until it reaches the end of the text or string.
Here's a simple example to illustrate the difference:
Suppose you have the text: "apple orange apple banana apple" and you want to
replace "apple" with "fruit."
- Using `%s/apple/fruit`, you'll get: "fruit orange apple banana apple" (only the
first "apple" is replaced).
- Using `%s/apple/fruit/g`, you'll get: "fruit orange fruit banana fruit" (all
occurrences of "apple" are replaced).
The "g" modifier makes the replacement operation global, affecting all instances
of the search term in the text.
79)Write a command to replace a word madhu with lalita (Replace all occurrences
within 20 and 30th line)
->20,30s/madhu/lalita
80)Command mode (Movement of cursor around the file) "h" is used for
->Move one char left side
81)Command mode (Movement of cursor around the file) "j" is used for
->Move one line down
82)Command mode (Movement of cursor around the file) "k" is used for
->Move one line up
83)Command mode (Movement of cursor around the file) "l" is used for
->Move one char right side
84)Command mode (Movement of cursor around the file) "w" is used for
->Move one word in forward direction
85)Command mode (Movement of cursor around the file) "b" is used for
->Move one word in backward direction
86)Command mode (Movement of cursor around the file) "$" is used for
->Move to the last char of the lineCommand mode
87)Command mode (Movement of cursor around the file) "^" is used for
->Move to the begining char of the current line
88)Command mode (Movement of cursor around the file) "0" is used for
->Move to the very begining of the current line
89)Command mode (Movement of cursor around the file) "G" is used for
->Move to the last line of the file
90)Command mode (Movement of cursor around the file) "gg" is used for
->Move to the first line of the file
91)Write a command to move 5th char left side
->5h
92)Write a command to move 6 line down
->6j
93)Write a command to move 3 line up
->3k
94)Write a command to move 4 char right side
->4l
95)Write a command to move 5 word in forward direction
->5w
96)Write a command to move 8 word in backward direction
->8b
97)Which char is used to copy
->y
98)Which char is used to paste
->p
99)Which char is used to delete
->d
100)How to search a word in command mode
->/word

Post a Comment

0 Comments