Saturday, March 16, 2019

Head Command: -
Q) What is head command ?
Ans – Head command will show 1st ten lines of a file.
Q) How you will see 1st 10 lines of a file ?
Ans - $ head <File Name><Enter – Key>
Example - $ head f1.txt
Q) How you will see 1st 15 lines of a file ?
Ans - $ head -15 <File Name><Enter – Key>
Q) How you will see 1st 30 lines of both the files file1.txt and file2.txt ?
Ans - $ head -30 file1.txt file2.txt<Enter – Key>
Here you will get 1st 30 lines of both the files with a header file name before each file records.

Tail Command: -
Q) What is tail command ?
Ans – Tail command will show last ten lines of a file.
Q) How you will see last 10 lines of a file ?
Ans - $ tail <File Name><Enter – Key>
Example - $ tail f1.txt
Q) How you will see last 15 lines of a file ?
Ans - $ tail -15 <File Name><Enter – Key>
Q) How you will see log file error message ?
Ans - $ tail –f <Log File Name> | grep error<Enter – Key>
| -> Pipe Operator
Grep -> This command is used to find all the pattern error present inside the log file.

More Command: -
Q) What is more command ?
Ans – more command is used to see the file content in page wise from top to bottom.
Example - $ more file.txt<Enter – Key>
Here you will find the 1st page. Then by clicking space bar, you will move to next page.
Q) How you will exit from more command or from the file content ?
Ans – By clicking ‘Q’ (Capital Q)
Q) How is more command is useful ?
Ans – more command search pattern in forward direction, not in backward direction.
After you open any file by help of more command, then you need to press ‘/’ (Forward Slash) and then space and then pattern. You will find the pattern, then by hitting ‘n’ you will move to next occurrence of the pattern.

Less Command: -
Q) What is less command ?
Ans – less command is used to see the file content in page wise from bottom.
Example - $ less file.txt<Enter – Key>
Here you will find the last page.
Q) How you will exit from less command or from the file content ?
Ans – By clicking ‘Q’ (Capital Q)
Q) How is less command is useful ?
Ans – less command searches pattern in forward and backward direction.
After you open any file by help of less command, then you need to press ‘/’ (Forward Slash) and then space and then pattern. You will find the pattern, then by hitting ‘n’ you will move to next occurrence of the pattern and ‘shift + n’ you will move to previous pattern.

Absolute Path and Relative Path: -
Q) What is absolute path ?
Ans - An absolute path is defined as specifying the location of a file or directory from the root directory(/).
Q) What is Relative Path ?
Ans - Relative path is defined as the path related to the present working directory(pwd). Relative Path never begins with ‘/’ (Root Directory).

PIPE (|): -
Q) What is pipe operator (|) ?
Ans – pipe operator is used to combine multiple commands at a time to get a single desired output.
Q) How to find an ip address 101.21.3.41 present in the log file f1.log or not ?
Ans – tail –f f1.log | grep 101.21.3.41<Enter – Key>
Q) How to see 15th to 27th lines present inside the file file.dat ?
Ans - $ head -27 file.dat | tail -13<Enter – Key>
Q) How to see 34th line of a file f1?
Ans - $ head -34 f1 | tail -1<Enter – Key>
Q) Store 1st 30 lines of a file file.csv into a file f1 ?
Ans - $ head -30 file.csv > f1<Enter – Key>
Q) Append 30th to 45th lines of a file file.log into a file f2 ?
Ans - $ head -45 file.log | tail -16 >> f2<Enter – Key>

No comments:

Post a Comment

Interview Questions: - (UNIX - 0) UNIX: -   Q) How to get inode number of a file/directory? Ans – $ ls –i <File/Directory_Name...