≡ Menu

line numbers

PHP: GeSHi Syntax Highlighter Enable / Disable Line Numbers

I'm using GeSHi under php to highlight a source code. How do I turn on or off line numbers using GeSHi?
[click to continue…]

Iptables: Unblock / Delete an IP Address Listed in IPtables Tables

I am a brand new user of a Linux iptables and I can't find how to instruct my iptables to delete or unblock an IP address listed in iptables firewall. I'm using Debian Linux version. Can you help please?
[click to continue…]

How To Show Line Numbers In vi / vim Text Editor

How do I display vi / vim text editor line numbers while writing a shell script or c program? How can I turn on or off this feature on Linux, Apple OS X, or Unix-like operating systems?
[click to continue…]

Shell Script To Number Lines Of Files

Q. How do I number each line of a text file? How do I write a shell script to display text file with line numbers added?
[click to continue…]

VI / Vim Print Line Numbers on Hardcopies / Printer

How do I print line numbers on the printer for my c / java / c++ code written using vi or vim text editor under Linux / UNIX like operating system?
[click to continue…]

UNIX / Linux: vi / vim perform search and replace operation

Q. I’ve just installed CentOS Linux server and started to use vi text editor to make changes to config files. How do I perform search and replace operation using vi / vim text editor?

A. vi (vim) is not difficult to learn, the vi editor is well known and used for both writing code and editing config files.

VI search and replace command format

Simple format is as follows:

VI search and replace command examples

Let us say you would like to find a word called "foo" and replace with "bar".

First hit [Esc] key

Type : (colon) followed by %s/foo/bar/ and hit [Enter] key.
Above command will replace first occurrence of word foo with bar on all lines. The % is shorthand for all lines.

To replace all occurrences of word foo with bar on all lines, use the g option (which indicates all occurrences on a line).

Note that the g can be replaced with a number 1,2,...N to change only the n'th occurrence on each line.

Use find and replace on line ranges (match by line numbers)

You can also make changes on range of lines i.e. replace first occurrence of foo with bar on lines 5 through 20 only, enter:

Following command will replace first occurrence of foo with bar starting at the current line for the next 100 lines:

Match by words

Finally, you can match by words i.e. replace first occurrence of foo with bar starting at at the next line containing a word "test":
As usual you can specify ranges:

Please note that all search/replace commands should be start with the [ESC]: keystroke combination only.

Linux Firewall: Display Status and Rules of Iptables Firewall

Q. How do I display / list all rules in the selected chain? How do I find out which rules are active? What is blocked and opened with my firewall?

A. To List all rules in the selected chain use the -L option. If no chain is selected, all chains are listed. As every other iptables command, it applies to the specified table. The -n option help to print IP addresses and port numbers in numeric format.

To check the status of your firewall and all rules, enter:
# iptables -L -n
$ sudo iptables -L -n

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
droplist   all  --  
droplist   all  --  
ACCEPT     all  --  
ACCEPT     all  --  
ACCEPT     all  --
DROP       all  --
DROP       all  --
DROP       all  --
DROP       all  --
LOG        all  --           LOG flags 0 level 4 prefix `DROP List Block'
DROP       all  --

The --line-numbers option adds line numbers to the beginning of each rule, corresponding to that rule's position in the chain. The -v option makes the list command show the interface name, the rule options (if any), and the TOS masks. The packet and byte counters are also listed, with the suffix K, M or G for 1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see the -x flag to change this).
# iptables -L -v -n --line-numbers

Linux and UNIX view command-line history

Q. How do I view command line history? I am using Cent OS Linux system.
[click to continue…]