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 292010
 

Repeat previous command in Bash

Answer:

It is easy to type !! when you want to repeat the previous executed command in Bash

# ls -l /var/log/messages
-rw-r----- 1 syslog adm 330 Mar 29 17:17 /var/log/messages

# !!
ls -l /var/log/messages
-rw-r----- 1 syslog adm 330 Mar 29 17:17 /var/log/messages
Mar 252010
 

Find out which programs are listening TCP port

Answer:

Use the command: netstat -tlnp

# netstat -tlnp

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
Mar 182010
 

Save a file in vim without the needed permissions

Answer:

Very often, you opened a file using vim, edited it and find out that the file is opened as read only, i.e. you don't have permission to make any change(s).

What will you do? Simplest method is to save it into a temp file and rename it afterward.

However, there exist a simple method that allow you to save the file anyway.

Instead of using :wq, you enter the following.

:w !sudo tee %

That is what you need.