Tips for Linux / Unix Systems Administrator

How to un-mount the unresponsive media drive

First, let’s simulate it. Stick a disk in your CD/DVD drive, open up a terminal, and mount the CD/DVD drive. If your system automatically mount, then you can skip the mounting part.

root@server:~# mount /media/cdrom
root@server:~# cd /media/cdrom
root@server:~# while [ 1 ]; do echo "All your drives are belong to us!"; sleep 30; done

Now lets open up a second terminal and try to eject the media drive:

root@server:~# eject

You’ll get a message saying the “device is busy”. Before you free it, let’s find out which process is using it.

root@server:~# fuser /media/cdrom

You will see the process that being accessing the CD/DVD drive. Now as a root, you can exercise your godlike powers and kill processes:

root@server:~# fuser -k /media/cdrom

The above command will kill all processes that using /media/cdrom. Now we can safely eject the media

root@server:~# eject

How to get your screen back when it’s hosed

When we working on some text files, sometime we might accidentally open a binary file. Try this:

root@server:~# cat /bin/cat

Behold! Your terminal looks like garbage. Everything you type looks like you’re looking into the Matrix.
So, usually we will close the terminal and open a new one. But, actually there is command that will “clear” the screen.

root@server:~# reset

Now your screen is back to normal. This is much better than closing the window and then logging in again, especially if you just went through five machines to SSH to this machine.

How to change hostname

In Debian / Ubuntu, you can change the hostname using the following method.

root@server:~# echo "SERVER_FQDN" > /etc/hostname

In Red Hat / CentOs, you need to edit/set HOSTNAME in /etc/sysconfig/network file


The server’s hostname will be updated after a reboot.

How to disable sending an email after a cronjob is completed

By default, cron jobs send an email to the user account executing the cronjob. If this is not needed put the following command at the end of the cron job line:

> /dev/null 2>&1

How can i ping a block of hosts?

If you have the fping command installed on your machine you can ping to a specific block of hosts. Just include the “-g” switch in the command:

root@server:~# fping -g is alive is alive is unreachable

How to remove files names begin with a dash ( – ) character?

rm ./-filename

Using the redundant ./ directory information prevents the dash from occurring at the beginning of the filename, and being interpreted as an option of the rm command.