Quickzi: Disable Login and Logout Sound on Ubuntu

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.

Disable Login and Logout Sound on Ubuntu

Set the Log Out and Log In sounds to “No Sound” to disable the login and logout sounds in Ubuntu.

Quickzi: How To Delete Bash History

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.

Quickzi: Find out what IPs are on your subnet

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"

Quickzi: How to Disable The System Beep in Ubuntu

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

blacklist pcspkr

Save and quit the file:

:wq

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.

Disable the System Beep from the Ubuntu Desktop

Quickzi: How To Block Incoming Access to Port 80

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.

Getting help with the Linux Command Line

This is a guest post by Taylor Douglass

The command line interface (CLI) is a very powerful part of Linux. Linux beginners undoubtedly agree that at first it can seem a bit daunting and even dangerous. While it is true that there far more Linux commands available than most will ever want or need to know and that some of these commands are capable of wreaking havoc on your system if used incorrectly; it’s reassuring to know that help isn’t far away. While a new Linux user who is Internet savvy might be inclined to run straight to Google when they need help with a particular command or are searching for the command they need, this is not necessary. In fact, most of the time you don’t even need to leave your terminal. How is this possible? Simple, it’s the man command.

Getting Started With Man

Man is short for Manual, and basically means that by using the man command you are accessing the manual for a particular command. Let’s begin by exploring how man is used. Startup a terminal and type “man intro”. This brings up a basic introduction to user commands, and the CLI in general. Once you have finished reading the intro go ahead and exit the manual page by hitting the letter “q”. You should now be back at the command prompt. The next step you will want to take is to read the manual page for the man command itself. This is accomplished by typing “man man“. You may be beginning to see a pattern here. To see the manual for any command simply type “man command” at the prompt. You may also begin to notice a pattern in how the manual pages look. Most manual pages consist of several different sections. Let’s take a look at the sections available for mv command. Type “man mv” into your terminal.

Name
This section shows the command and gives a brief description of the command. In our example we see that the mv command is used to move or rename files.

Synopsis
Here you can find precise information on using the command that you are viewing. This includes all the switches and options available for the command. The first two sections (Name and Synopsis) are meant to be a quick reference for using the command that you are viewing. Further sections dive a little deeper and give you even more information.

Description
The description section breaks down all of the options available and tells you what they do. In our example with mv we can see that using the -i option prompts the user before overwriting any files that are being moved. Also note that we could also use –interactive to do the same thing.

Other sections
Other sections that you might find in the manual pages are author information, bugs, copyright, files, see also, and examples. The two that might be worth mentioning are the See Also and Example sections. See Also gives you a list of other manual pages that may be relevant to the page you are currently viewing, while the Example section gives you a real world example of using the command you are viewing.

Searching For Commands

Let’s say that you want to copy a file but you are not sure what the command for copy is. Perhaps one of the most useful features of the Linux manual pages is the ability to search them. If we look at the manual page for the command man (Again that is “man man” at the command prompt) we can see that one of the options available is -k. What this option does is allow us to search the short description for keywords and display any matches. Back to our example for finding the command to copy files, let’s get to the command prompt and type “man -k copy“. This displays all the commands that have “copy” listed in the description. If you glance through the list of commands that man -k has found you should see “cp(1) -copy files and directories“. That looks like the command we need, but to be sure let’s look at the manual page for that command to be sure. “man cp” brings up the manual page for the command cp. As you can see by looking at the name and synopsis sections, this is indeed the command we need to copy a file.

Man I’m Glad There are Manual Pages

The man command has gotten me out of a jam on more than one occasion. I recommend that if you are just beginning to explore the CLI that you do a quick check in the manual before using any command. As I mentioned before the CLI is very powerful and it’s better to be safe than sorry when using it.

Creating Custom Linux Commands

This is a guest post by Taylor Douglass

The other day I ran across a script at shell-fu that generates a random quote from their website (here). I thought it would be useful to make this a command that I could execute at any terminal at anytime. Let’s get started.

First of all you are going to need links. If you don’t have links or are not sure if you do or not, fire up a terminal and type the following:

# sudo apt-get install links

Next navigate to your /bin folder and create the file

# sudo touch shell-fu

Make the file readable and executable

# sudo chmod +rx shell-fu

Now edit the file and add the code for retrieving the shell-fu quote (I use nano for this)

# sudo nano shell-fu
# links -dump "http://www.shell-fu.org/lister.php?random" | grep -A 100 -- ----
^O (writes the file from nano)
^X (exits nano)

You now have a custom command named “shell-fu” that you can type from anywhere and retrieve a random shell-fu quote.

Quickzi: How To Remove Blank Lines from a File

If you want to remove all blank lines from a file, a quick way of doing it from the Linux command line is to use sed.

So, lets say that your file looks like this:

# vi example_file

This is an example text file.
We will be using sed to remove blank lines from this example file.

sed is a stream editor for filtering and transforming text

There are a lot of powerful things you can do with sed.

:wq

Now, to remove the blank lines in this file, we’ll use sed.

# sed -i '/^$/d' example_file

# cat example_file

This is an example text file.
We will be using sed to remove blank lines from this example file.
sed is a stream editor for filtering and transforming text
There are a lot of powerful things you can do with sed.

If you want to preserve the original file, then you can pipe the changes to a new file:

sed '/^$/d' example_file > example_file_new

Cheers!