5 Helpful Linux Tips And Tricks



The most beautiful part of Linux is its community and the spirit of sharing. So keeping up the originality of Linux intact, here we bring to you 5 helpful Linux tips and tricks shared with us by our readers.

The fact that you can try things out yourself makes Linux and open source technology even more interesting. Keeping this fact in mind, we have been sharing some interesting tips and tricks for our readers. We continue to do that here as well. Read on...



1. SSH access on a different port

To change the default SSH port, you need to edit the SSH configuration file /etc/ssh/sshd_config
Open the configuration file in any text editor and search for the line as follows:

#port 22

Uncomment and replace 22 with the port number you'd like to run SSH on. In my case I am using Port No 2087.
Now, restart sshd by issuing the following command:

/etc/rc.d/init.d/sshd restart

To test the changes, you need to first check if the given port number is open or not. The following command will let you know if the new port is using this command:


netstat -ltn | grep 2087

In the output of the above command, the state should be LISTEN for Port No 2087.
Finally, test ssh on the new port as follows:

ssh USERNAME@localhost -p 2087


2. Get the directory size from the terminal

Getting the size of the directory is easy with the du command, but if you want to get the size of allfiles in the directory which should not include the sub-directory, you can use the command givenbelow:

$ls -hs | head -1

This will give you the desired size.

3. Adding the 'Eject' command to your menu

Sometimes it gets difficult to eject the CD ROM on your Linux-based computer. Here is a tip that allows you to add the Eject command to your menu.

Create a file called Eject CD in $HOME/.gnome2/nautilus-scripts/ directory. Now open a file in any text editor and type the following code:

#!/bin/bash
eject /dev/sr0/

Here sr0 is the device name of the CD ROM Drive.
Save and close the file.

Next, provide 'execute' permission to the newly created script:

$ chmod $HOME/.gnome2/nautilus-scripts/Eject\ CD

Now you can eject the CD from the pop-up menu displayed by right clicking on the menu.

Note: Before ejecting the CD, be sure that no program is using the CD ROM drive, because the drive does not give any error if it fails to eject the CD.


4. Execute your jobs without a hurdle

Here is a tip that will help you to keep executing jobs even after exiting the shell.
You can use the 'disown' command to run a job after you've logged out. It releases all the running jobs from ownership. You can also use the 'nohup' command, but for that, you have to specify in advance as shown below:

$ nohup nmap -vv -sP 10.13.37.1/24 &

You can now log out from the terminal. Your command will keep executing and the output will be in nohup.out

The same can also be achieved by using 'disown' as shown below:

$ nmap -vv -sP 10.13.37.1/24 -oN VizOutput.txt

Now press...

Ctrl+Z

This will suspend the running job.

After suspending the job, run the following command:

$ disown

Now you can log out from the terminal without killing the job.


5. Linux monitoring tools

You can use various Linux tools to collect systems statistics like CPU usage, memory usage, IO for hard disks, etc. A few of these are listed below:

1. top - A well known command for listing the running process with CPU and memory usage.

2. vmstat - Provides all virtual memory related information.

3. iostat - Provides IO statistics of devices and other CPU statistics.

4. free - This command displays the free, used, buffered or cached memory.

5. dstat - This is a good command to collect all the statistics in one place. It is a combination ofvmstat, iostat and the netstat commands.

6. netstat - This displays the routing table, network interface statistics and ports opened by the process.