Unix Questions & Answers - Part 2

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

Unix Questions & Answers - Part 2

Postby wacky » Wed Jul 29, 2009 2:13 am

6) How would you remove blank lines from a file?

grep "^$" filename > filename.new

Can also use sed and awk

7) How would you list the files in the current directory sorted by size?

ls -l | sort -k 5 -n[r]

8) How would you display the routing table?

netstat -r

9) What is a sparse file. Give a common example of it being used?

A record based file where the contents may be written to certain offsets
based on the record number and the record structures length. This could
mean that the file appears larger than it actually is , this is normally
achieved using system calls such as fseek() and fsetpos().

lastlog & coredumps are typical examples.

10) How would you find the time/date of the last reboot?

who -b

Please feel free to comment on any of this.
Last edited by wacky on Mon Aug 03, 2009 2:22 am, 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:42 am

ok waiting 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

Re: Unix Questions - Part 2

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

Dear wacky,
Salam,

wacky wrote:6) How would you remove blank lines from a file?


You can use either sed, grep for this purpose.

# sed '/^$/d' file > newfile

or

# grep -v '^$' file > newfile

wacky wrote:7) How would you list the files in the current directory sorted by size?


# ls -lS

wacky wrote:8) How would you display the routing table?


# route -n

wacky wrote:9) What is a sparse file. Give a common example of it being used?


Not sure about that ...

wacky wrote:10) How would you find the time/date of the last reboot?


# uptime

or

# w

wacky wrote:Please don't post your answers here. I'll put the answers here in a couple of days' time.


I saw this after writing whole post so i think i should let it go.

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 1 guest