If you’ve had the same Ubuntu installation for a while and have just been upgrading to newer releases, you may have noticed that a lot of older kernel versions are piling up in your grub menu and on your system.
How to remove older kernels from Ubuntu
This can be done by using the Synaptic Package Manager, however I will show you how it is done on the command line.
First, find out what kernel you are currently running:
# uname -a
Linux foogazi 2.6.24-19-generic #1 SMP Wed Jun 18 14:43:41 UTC 2008 i686 GNU/Linux
From the output you can see that you are currently using the 2.6.24-19-generic kernel.
Next, let’s take a look at all of the kernel versions you have installed:
# dpkg -l | grep linux-headers-*
linux-headers-2.6.24-16 2.6.24-16.30 Header files related to Linux kernel version
linux-headers-2.6.24-16-generic 2.6.24-16.30 Linux kernel headers for version 2.6.24 on x
linux-headers-2.6.24-19 2.6.24-19.34 Header files related to Linux kernel version
linux-headers-2.6.24-19-generic 2.6.24-19.34 Linux kernel headers for version 2.6.24 on x
linux-headers-generic 18.104.22.168.21 Generic Linux kernel headers
Now all you need to do is remove the old versions with apt-get. Since we’ve noted with uname -a that we are currently running 2.6.24-19-generic we want to make sure we do not remove it. All of the others can be removed.
# sudo apt-get remove linux-headers-2.6.24-16 linux-headers-2.6.24-16-generic
Now the older kernels are gone. Repeat the apt-get remove step to remove any others you may have. Remember to not remove your current kernel.
Important note: It is a good idea to keep at least one old kernel version around in case anything breaks in your current kernel and you are unable to boot into it. An example would be that you boot into your current kernel but recieve a kernel panic. With an old kernel still available you can reboot the computer and select the older kernel version from the Grub menu and still access your system to find out what is going on.
I don’t know about you but I find the login sound on Ubuntu pretty annoying. Here is a quick, nice and easy way to disable it.
How to disable Ubuntu Login and Logout sounds
Navigate to System > Preferences > Sound then click the Sounds tab.
Set the Log Out and Log In sounds to “No Sound” to disable the login and logout sounds in Ubuntu.
If you want to delete your bash history, there are a few options you have. First you must understand that the history of your bash session is stored into RAM and then written to ~/.bash_history when you log out of the bash session. So even if you delete the ~/.bash_history file, your current bash session will still be written to history once you log out.
Delete bash history
To delete the bash history for your current session as well as old sessions, you should do two things:
Delete the .bash_history file:
# rm -rf ~/.bash_history
Clear the current history stored in RAM:
# history -c
Stop writing to .bash_history for good
If you don’t want to log any history for good, you can do one of two things; turn it off for all users, or turn off logging history for a single user.
Turn off bash history for all users:
Append “unset HISTFILE” to /etc/profile:
# echo "unset HISTFILE" >> /etc/profile
Turn off bash history for a specific user:
Append “unset HISTFILE” to /home/USER/.bash_profile:
# echo "unset HISTFILE" >> /home/USER/.bash_profile
That’s it! Now you have successfully deleted the bash history and stopped logging to bash history.
Here is a quick tip on how to use sed to replace a line in a text file from the command line, without opening it.
Replace a Line in a File
First, replace the text you want with sed and output it into a temporary file to ensure that it is correct:
# sed -e 's/original-text/new-text/' textFile > newFile
newFile and make sure that the line is correctly replaced:
# more newFile
textFile with the
# mv newFile textFile
Here is a quick tip on how to use sed to add a line into the middle of a text file from the command line, without opening it.
To clarify, let’s say you have a text file that has four lines:
Using sed, you can append a line anywhere you want with a simple command without even knowing the line numbers.
Add a Line into the Middle of a Text File
For this example, lets say we want to append a new line under Line3Text:
# sed '/^Line3Text/a NewLineText' textFile > newFile
You’ll notice that we output the results to a
newFile so that we can make sure the new line appended correctly before overwriting the original file. If you check the
newFile, you should see a correct output, then you can overwrite the original
# mv newFile textFile
Here is a quick Linux tip to log your boot messages in Ubuntu. This is great for checking for any errors or failed startups that may be happening during boot.
# vi /etc/default/bootlogd
You’ll see the following lines:
# Run bootlogd at startup ?
Change No to Yes:
# Run bootlogd at startup ?
Now every time your computer restarts, a /var/log/boot file will be created.
Here is a quick tip on how to find out what host IPs are on your subnet using nmap. This is useful to find out what IPs are being used or just to know how many devices are connected to the subnet.
How to find out what IPs are being used on your subnet
# nmap -v -sP 192.168.1.0/24
You can replace the 192.168.1.0/24 address with whatever your IP and subnet is.
Also, for a cleaner output that removes the lines that tell you an IP is not used, try the following:
# nmap -v -sP 192.168.1.0/24 | grep -v "appears to be down"
If you’re looking to get rid of the annoying system beep in Ubuntu, here is how to do it from both the command line, and from the Gnome desktop.
Disable the System Beep from the Command Line
#sudo vi /etc/modprobe.d/blacklist
And then add:
#pc speaker beep
Save and quit the file:
Now, remove the pcspkr module:
sudo rmmod pcspkr
Disable the System Beep in Ubuntu from the Gnome Desktop
This way is much easier. Simply navigate to System -> Preferences -> Sound then navigate to the System Beep tab. Uncheck the box labeled “Enable the System Beep” and click close.
Here is a quick Linux tip to block incoming access to port 80 using iptables.
iptables -A INPUT -j DROP -p tcp --destination-port 80 -i eth0
The code above will drop all tcp packets coming into your Linux computer on device eth0 on port 80. If your Internet connection runs through a device other than eth0, go ahead and make the adjustment.
To remove the iptables rule use the following code:
iptables -D INPUT -j DROP -p tcp --destination-port 80 -i eth0
For more information on using iptables visit the iptables man page.
Here is a quick tip on how to display the top largest files and directories within my home directory:
# du -hs /home/adam/* | sort -nr | head