Unix Questions & Answers - Part 2

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 2

Post by wacky »

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.
ranatanveer
Subedar
Posts: 355
Joined: Sat May 07, 2005 11:54 am
Location: Lahore
Contact:

Post by ranatanveer »

ok waiting for.
Regards

Rana Tanveer
+923224194457
Linux Student

For Affordable Web Development http://www.affordableprogrammers.com
http://www.qualityprogrammers.com
LinuxFreaK
Site Admin
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
Location: Karachi
Contact:

Re: Unix Questions - Part 2

Post by LinuxFreaK »

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
Post Reply