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.

send a mail in command line in Ubuntu

Reading Time: < 1 minute  By default the binary "mail" is not installed on Ubuntu. At least it’s not on my brand new Ubuntu 10.10.
You need to setup the package mailutils.

apt-get install mailutils

Then you can send an email using the command line:

ls | mail blabla@gmail.com

How to follow the progress of a gzip or tar

Reading Time: < 1 minute

First you need pv, Pipe Viewer

[bash]$ apt-get install pv
[bash]$ SIZE=`du -sk some-folder | cut -f 1`
[bash]$ tar cvf - some-folder | pv -p -s ${SIZE}k | gzip -c > folder.tar.bz2

extract one file from a tar.gz

Reading Time: < 1 minute You can simply use the following syntax:

[root@blub ~]# tar tzvf mytar.tar.gz
That will show you the list of files in the tar. t means test
 
[root@blub ~]# tar tzvf mytar.tar.gz myfile.txt
 -rw-rw-r-- scm/scm 373093723 2010-09-17 17:58:21 myfile.txt
You can do the same with a target file and test that one specific file really belong to a tar.gz

Finally you can extract that single file.

How to check if Virtualization is supported for your CPU

Reading Time: < 1 minute

Many ways
1. Use the following command:

Make a virtual machine out of a G4L archive

Reading Time: < 1 minute So I took a backup of a disk using G4L.
Let’s import it into a virtual machine on a RedHat running Xen.

virt-install --import --file <myfile> --prompt

answer the few questions.
Choose "Fully Virtualized".
Turn the SELinux into permissive mode in order to configure the network. This is a known bug and it looks like it’s not corrected yet.

setenforce Permissive

Once the import is done your virtual machine should pop and boot properly.

 

Transfer a very big file very fast

Reading Time: < 1 minute

ssh server "gzip -c remote_file " |gunzip > local_file

Secure connection without a password

Reading Time: < 1 minute

There are numbers of tutorials on the net on how to configure access from one machine to another without typing a password.
Here is the real way to do it.
First generate a pair of keys:

ssh-keygen -t rsa 

It’s important to choose a passphrase. Don’t leave it blank.
Then you need to copy the public key to the other server

ssh-copy-id -i .ssh/id_rsa.pub>

Make sure that ssh-agent is running.
Add a key using ssh-add

ssh-add

Try connecting
Should be working.

get the console from a VT

Reading Time: < 1 minute

xterm -C

opens an xterm with console messages

finding a file in a bunch of rpm

Reading Time: < 1 minute Sometimes it can be hard to resolve a dependency with rpms.

rpm -qpl *

will show the list of all the files installed with a list of rpm in the running directory.

rpm -qpl * | grep libcc

will show me the files that resolve a specific dependency.