Unix Questions & Answers- Part 1

General discussion about Linux, Linux distribution, using Linux etc.

Unix Questions & Answers- Part 1

Postby wacky » Tue Jul 28, 2009 1:42 am

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.
wacky
Naik
 
Posts: 94
Joined: Thu Jun 10, 2004 7:42 pm
Location: London, UK

Postby ranatanveer » Thu Jul 30, 2009 5:34 am

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
ranatanveer
Subedar
 
Posts: 355
Joined: Sat May 07, 2005 11:54 am
ICQ: 133032001
Website: http://www.affordableprogrammers.com
WLM: ranatanveer@gmail.com
Yahoo Messenger: ranahard@yahoo.com
Location: Lahore

Postby lambda » Thu Jul 30, 2009 8:46 am

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"?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Re: Unix questions - Part 1

Postby LinuxFreaK » Thu Jul 30, 2009 8:21 pm

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
LinuxFreaK
Site Admin
 
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
ICQ: 82075802
Website: http://www.linuxpakistan.net/wiki/index.php?pagename=LinuxFreak
WLM: f4fahmed@hotmail.com
Yahoo Messenger: f4fahmed@yahoo.com
AOL: linuxpakistan@aol.com
Location: Karachi


Return to “%s” General

Who is online

Users browsing this forum: No registered users and 2 guests