Krishna Logo
Divied
Call: Sana @ (571) 386-2972

 

Loading
Latest News
Home Navigation Divied
INTERVIEW Navigation Divied UNIX INTERVIEW QUESTIONS
Showing 71 - 80 of 323 Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next
UNIX INTERVIEW QUESTIONS
 
71How To Check If A File Is Zipped In UNIX?
Date Posted: 07/02/2012

Ans: In order to know the file type of a particular file use the [file] command like below:
$> file file.txt
file.txt: ASCII text
If you want to know the technical MIME type of the file, use “-i” switch.
$>file -i file.txt
file.txt: text/plain; char set=us-ascii
If the file is zipped, following will be the result
$> file –i file.zip
file.zip: application/x-zip

 
 
72How To Test If A Zip File Is Corrupted In Linux?
Date Posted: 07/02/2012

  Ans: Use “-t” switch with the inbuilt [unzip] command
$> unzip –t file.zip

 
 
73How To Unzip A File In Linux?
Date Posted: 07/02/2012

 Ans: Use inbuilt [unzip] command in Linux.
$> unzip –j file.zip

 
 
74How To Zip A File In Linux?
Date Posted: 07/02/2012

 Ans: Use inbuilt [zip] command in Linux

 
 
75How To Show The Non-printable Characters In A File?
Date Posted: 07/02/2012

   Ans: Open the file in VI editor. Go to VI command mode by pressing [Escape] and then [:]. Then type [set list]. This will show you all the non-printable characters, e.g. Ctrl-M characters (^M) etc., in the file.

 
 
76How To Replace The N-th Line In A File With A New Line In UNIX?
Date Posted: 07/02/2012

 Ans: This can be done in two steps. The first step is to remove the n-th line. And the second step is to insert a new line in n-th line position. Here we go.
Step 1: remove the n-th line
$>Sed -i'' '10 d' file.txt       # d stands for delete
Step 2: insert a new line at n-th line position
$>Sed -i'' '10 i This is the new line' file.txt     # i stands for insert

 
 
Date Posted: 07/02/2012

Ans: We know we can do it by [cut]. Like below command extracts the first field from the output of [WC –c] command $>WC -c file.txt | cut -d' ' -f1 109 But I want to introduce one more command to do this here. That is by usi...  

 
 
78How To Reverse A String In UNIX?
Date Posted: 07/02/2012

Ans: Use the [rev] command.
      $> echo "Unix" | rev
       Xinu

 
 
79How To Get The Nth Word Of A Line In UNIX?
Date Posted: 07/02/2012

Ans: Assuming the words in the line are separated by space, we can use the [cut] command. [cut] is a very powerful and useful command and it's real easy. All you have to do to get the n-th word from the line is issue the following command:
Cut –f<n> -d' '
'-d' switch tells [cut] about what is the delimiter (or separator) in the file, which is space ' ' in this case. If the separator was comma, we could have written -d',' then. So, suppose I want find the 4th word from the below string: “A quick brown fox jumped over the lazy cat”, we will do something like this:
$> echo “A quick brown fox jumped over the lazy cat” | cut –f4 –d' '
And it will print “fox”

 
 
80How To Check The Length Of Any Line In A File?
Date Posted: 07/02/2012

 Ans: We already know how to print one line from a file which is this:
$> Sed –n '<n> p' file.txt
Where <n> is to be replaced by the actual line number that you want to print. Now once you know it, it is easy to print out the length of this line by using [WC] command with '-c' switch.
$> Sed –n '35 p' file.txt | WC –c
The above command will print the length of 35th line in the file.txt.

 
Showing 71 - 80 of 323 Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next
Shadow Bottom
 
 
© 2005 - 2018 Krishna Training.
Designed & Developed By BitraNet