How to delete empty line with vi

Reading Time: < 1 minute

How to delete empty lines with vi?

Just type this in:

 
<esc>:g/^$/d

NOTE:  This means that all the lines that just have a carriage return on them (NO Spaces), will be removed. 

If you want to remove lines with empty spaces as well:

 
<esc>:g/^ *$/d

rename and shorten many files with bash

Reading Time: < 1 minute

Bash supports a surprising number of string manipulation functions.

For example if you want to get rid of the beginning of the name of a file or a folder on many files at a time you could do the following:

 
bash> ls
mylongfile1
mylongfile2
mylongfile3
mylongfile4
mylongfile5
mylongfile6
mylongfile7
 
bash> for i in *
> do
> mv $i ${i:6}
> done
bash> ls
file1
file2
file3
file4
file5
file6
file7
So to extract the end of a variable after a NUMBER of characters you just need to specify ${variable:NUMBER}
 

Change permanently the ethernet parameters of interface in redhat

Reading Time: < 1 minute In the file: 

/etc/sysconfig/network-scripts/ifcfg-eth0

Add the following at the end of the file:

ETHTOOL_OPTS="speed 100 duplex full autoneg off"

How to change the default runlevel on Ubuntu

Reading Time: < 1 minute  On Redhat you would simply look for the file /etc/inittab and locate the line that says:

# The default runlevel.
id:3:initdefault:

Simply replace the 3 with 2 or 4 or 5 depending what you wanna do in order to change the default runlevel.

On Ubuntu starting from some version around 6sh… whatever, no one is running that anymore anyway and those who do run it don’t need to change that. At the time I am writing this the current LTS is 10.04 and the current testing release is 10.10
So here is how to do it.