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.
Unix Questions & Answers- Part 1
Unix Questions & Answers- Part 1
Last edited by wacky on Thu Jul 30, 2009 11:53 pm, edited 1 time in total.
-
- Subedar
- Posts: 355
- Joined: Sat May 07, 2005 11:54 am
- Location: Lahore
- Contact:
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
Rana Tanveer
+923224194457
Linux Student
For Affordable Web Development http://www.affordableprogrammers.com
http://www.qualityprogrammers.com
yes, but those questions are so trivial that you'd better know the answers.being a system admin, no one remember the exact command, every one google out for exact syntax what he is looking for
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"?
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
-
- Site Admin
- Posts: 5132
- Joined: Fri May 02, 2003 10:24 am
- Location: Karachi
- Contact:
Re: Unix questions - Part 1
Dear wacky,
Salam,
or
# tr "\n" " " < file > newfile
or
# awk '{ str1=str1 $0 }END{ print str1 }'
Best Regards.
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 :
# ls -ltwacky wrote:1) What switches can you give to the ls command to sort the output in time-modified order?
It will save all the work into a file, it will be good for assignments in Colleges & Universities.wacky wrote:2) What does the script command do?
# tar zxvf wacky.backup.tgzwacky wrote:3) I have a file called wacky.backup.tgz ,how would you extract the contents of this file?
# ls /etc/*hostname*wacky wrote:4) How would you list the names of the files in /etc that contained the string 'hostname' ?
# tr -d '\012' < file > newfilewacky 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?
or
# tr "\n" " " < file > newfile
or
# awk '{ str1=str1 $0 }END{ print str1 }'
Best Regards.
Farrukh Ahmed