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.

Dec 222010
 

Get HTTP request with nc command

Answer:

nc command is a very useful tool for network diagnosis, e.g. when you want to know the exact requests sent by your HTTP client (e.g. browser) to your web server, you can easy test with nc.

1. In your server, start nc and listen on port 80

# sudo nc -l -p 80

2. In your browser, type the server IP address.

3. In your shell, HTTP requests will be printed.

GET / HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090712 Firefox/3.5.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Dec 062010
 

Executing jobs in parallel using GNU parallel

Answer:

GNU parallel is a tool for executing jobs in parallel. It is not part of standard Linux distribution yet, so it is so worth to install it.

You can download the latest version from: http://ftp.gnu.org/gnu/parallel/

E.g.

# wget http://ftp.gnu.org/gnu/parallel/parallel-20101202.tar.bz2
# tar -jxvf parallel-20101202.tar.bz2
# cd parallel-20101202
# ./configure
# make && sudo make install

Example usages:

#  echo -e "a\nb\nc"  | parallel echo "foo"

foo a
foo b
foo c
Dec 042010
 

Simple port forwarding using SSH

Answer:

Assume you are working at office, you want to browse the example.com securely, you can do so by using a computer at home (e.g. HOME_IP)to build a secure tunnel using ssh.

# sudo ssh -L 80:example.com:80 HOME_IP

Then in your browser, type http://localhost and you can view the example.com securely.

Nov 132010
 

Display the current hard limit of my Linux server

Answer:

The hard limit of your Linux operating system is the maximum server limit that can be set without tuning the kernel parameters in proc file system.

To show it, you can use the ulimit command:

#  ulimit -aH

core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 20
file size               (blocks, -f) unlimited
pending signals                 (-i) 16382
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) unlimited
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
Nov 102010
 

Display non-printable character in vim

Answer:

To display non-printable characters, such as control characters in vim, you can try the tricks below:

1. Press [ESC] to get into command mode

2. Enter :set list

If you want to turn off the non-printable character, enter :set nolist will revert the option set above.