Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Mar 162010
 

Check what Linux kernel modules are loaded

Answer:

To find out what Linux kernel modules are loaded:

#  lsmod

Module                  Size  Used by
ipt_REJECT              3584  1
ipt_LOG                 6404  1
xt_limit                3236  2
xt_tcpudp               3616  10
xt_state                2432  6
ipt_addrtype            2912  4
ip6_tables             22576  0
nf_nat_irc              2688  0
nf_conntrack_irc        6552  1 nf_nat_irc
nf_nat_ftp              3584  0
nf_nat                 22164  2 nf_nat_irc,nf_nat_ftp
nf_conntrack_ipv4      16376  8 nf_nat
nf_defrag_ipv4          2400  1 nf_conntrack_ipv4
nf_conntrack_ftp        9016  1 nf_nat_ftp
...

To find out more information for a specific module

#  modinfo ip6_tables
filename:       /lib/modules/2.6.31-14-server/kernel/net/ipv6/netfilter/ip6_tables.ko
description:    IPv6 packet filter
author:         Netfilter Core Team 
license:        GPL
srcversion:     17E938A990111BB4A2F854B
depends:        x_tables
vermagic:       2.6.31-14-server SMP mod_unload modversions
Mar 092010
 

Speedup sed search and replace

Answer:

If you have a very large file, sometimes you can speed up sed by using the following method:

Original method:

# sed 's/foo/bar/g' filename

Optimized method:

# sed '/foo/ s/foo/bar/g' filename

The second method is faster since substitution is only performed when the search string is found.

Feb 132010
 

How to shutdown a frozen Linux System?

Answer:

Similar to this post, but this time you are going to shutdown a frozen Linux system.

  1. Hold down the Alt and SysRq (Print Screen) keys
  2. While holding those down, type the following in order: REISUO
  3. You computer will shutdown now

The last letter O tell the system to shutdown. Replace by the letter R if you want reboot instead.

Feb 062010
 

Wait for a process terminated

Answer:

wait command allow you to monitor the termination of a process and quit afterward.

It is very useful when you want to trigger some action when a particular process terminated.

E.g. Send an email when a long running process of PID 5870 terminated

#  wait 5870 && echo Finished | mail -s Task [email protected]