Linux Amazing Tips and Tricks

Linux is all about sharing and improvising. We are sharing some useful Linux tips and tricks for all those who want to try out new things in open source technology. These tips have been shared by our readers.

Find out the elapsed time of a running process

There are a lot of processes running on your Linux system. Here is a command that will let you know how long the process has been running:

#ps -eo “%p %c %t”|grep “sshd”

In response to the above command, you will get the following output:

2850 sshd 172-01:37:22
29532 sshd 125-09:07:10

In the above command %p is pid, %c is command and %t is elapsed time.
Linux, Linux Tips and tricks, Useful Linux Tips, Linux tips for beginners, Operating system, Linux operating system

Mounting a remote filesystem with ssh

Although running the scp or ssh command is very convenient, mounting the remote servers filesystem on the local system has solved many problems for me.
Here is how this can be done. To mount the remote filesystem to a local Linux workstation, you need to install the sshfs. To install, you can choose to use the package manager of your distro or you can compile and install manually. More details can be found at http://fuse.sourceforge.net/sshfs.html
After the installation is complete, you can run the following command on your Linux workstation:

sshfs username@hostname:/ /

That’s it, so enjoy! (Of course, you should have the required permissions.)


Low-level HDD formatting

You often have a hard disk drive that needs to be formatted such that all data in it gets destroyed. Here is a command that can erase all data from your HDD.

#dd if=/dev/zero of=/dev/hda bs=1M

This will format your primary HDD (hda) to a low level using dd. This will fill the entire disk with a sequence of zeros. In case you want to mix zeros and ones to fill the HDD, you can use the following command:

#dd if=/dev/urandom of=/dev/hda bs=1M

Note: Please be very careful while using dd as the wrong use of this command can erase all your valuable data.


Encrypt an image using the command line

First, get a PNG image file and run the following command:

$echo p4ssw0rd|convert vizay.png -encipher - hidden.png

…where p4ssw0rd is our secret key for encryption and hidden.png is the encrypted image.
Now, to confirm the encryption, check whether or not the image can be seen as earlier by running the following command:

$display hidden.png

This should display the scrambled image and not the actual one if everything is fine.
Now, let’s decrypt the image by running the following command:

$echo p4ssw0rd|convert hidden.png -decipher - new.png

Here new.png is our decrypted image.
Running the command below will display the original image:

$display new.png

The new.png will be same as the original image, vizay.png

No comments:

Post a Comment