Unix Questions & Answers- Part 1

General discussion about Linux, Linux distribution, using Linux etc.
Post Reply
wacky
Naik
Posts: 94
Joined: Thu Jun 10, 2004 7:42 pm
Location: London, UK

Unix Questions & Answers- Part 1

Post by wacky »

1) What switches can you give to the ls command to sort the output in time-modified order?

ls -t or ls -rt for reversed order. We can also add -l switch for long listing

2) What does the script command do?

script command writes all keyboard input and command output of a session to a file

3) I have a file called wacky.backup.tgz ,how would you extract the contents of this file?

tar -xzf wacky.backup.tgz

4) How would you list the names of the files in /etc that contained the string 'hostname' ?

This question is slightly confusing. String 'hostname' is in the file.

grep -l 'hostname' /etc/*


5) Given a plain text file, how would you remove all the newline characters so that the whole file appeared as one long line?

cat <filename> | tr -d '\n' > filename

There are other ways of doing this - sed, awk, perl

Please feel free to comment on any of this.
Last edited by wacky on Thu Jul 30, 2009 11:53 pm, edited 1 time in total.
ranatanveer
Subedar
Posts: 355
Joined: Sat May 07, 2005 11:54 am
Location: Lahore
Contact:

Post by ranatanveer »

being a system admin, no one remember the exact command, every one google out for exact syntax what he is looking for :)
Regards

Rana Tanveer
+923224194457
Linux Student

For Affordable Web Development http://www.affordableprogrammers.com
http://www.qualityprogrammers.com
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

being a system admin, no one remember the exact command, every one google out for exact syntax what he is looking for
yes, but those questions are so trivial that you'd better know the answers.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
LinuxFreaK
Site Admin
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
Location: Karachi
Contact:

Re: Unix questions - Part 1

Post by LinuxFreaK »

Dear wacky,
Salam,
wacky wrote:Here are some questions we ask when we're recruiting Unix sys admins. I thought they may be useful for people who are going for interviews or certifications.
I've bunched them in lots of 5 questions. Please do not post your answers here. Keep them to yourself and then compare them to the answers which I'll post in a couple of days time. Here goes :
wacky wrote:1) What switches can you give to the ls command to sort the output in time-modified order?
# ls -lt
wacky wrote:2) What does the script command do?
It will save all the work into a file, it will be good for assignments in Colleges & Universities.
wacky wrote:3) I have a file called wacky.backup.tgz ,how would you extract the contents of this file?
# tar zxvf wacky.backup.tgz
wacky wrote:4) How would you list the names of the files in /etc that contained the string 'hostname' ?
# ls /etc/*hostname*
wacky wrote:5) Given a plain text file, how would you remove all the newline characters so that the whole file appeared as one long line?
# tr -d '\012' < file > newfile

or

# tr "\n" " " < file > newfile

or

# awk '{ str1=str1 $0 }END{ print str1 }'

Best Regards.
Farrukh Ahmed
Post Reply