OpenSource For You

TIPS & TRICKS

-

How to find the serial number of the hard disk from the command line

To find the serial number of the hard disk from the command line, execute the following command:

#hdparm -I /dev/sda | grep Serial

The output of the above command is the serial number of the /dev/sda hard disk.

Here’s another tip to get an ASCII man page file, without the annoying backspace/underscore attempts at underlinin­g, and the weird sequences. For example, to get the rsync manual page in a plain text file, execute the following command:

#man rsync | col -b >/root/rsync —Suresh Jagtap, smjagtap@gmail.com

Google through the terminal

You can now Google through your terminal, i.e., by using Googler. Here is the process of using it on Ubuntu. To install it in Ubuntu, first make sure you have Python version 3.3 or later, by using the following command:

#python3 –version

If the version of Python is not correct, upgrade it. Googler requires Python 3.3+ to run.

Though Googler is not available through the package repository on Ubuntu, we can easily install it from the GitHub repository. All we have to do is run the following set of commands:

#cd /tmp

#git clone https://github.com/jarun/googler.git

#cd googler

#sudo make install

#cd auto-completion/bash/

#sudo cp googler-completion.bash /etc/bash_completion.d/

And that’s it. Googler is installed along with the command auto-completion feature.

After installing it, just run the command ‘Googler’ and start searching on Google.

—Mounica Revuru, ojaswitham­onica@gmail.com

Nuke a whole directory recursivel­y in Posix-type systems

The shred command, which is used to irrecovera­bly wipe out individual files or drives, can be creatively combined with find and xargs to destroy a directory's files only (say, /home/moi/.ssh), as follows:

date;find /home/moi/.ssh/ type f print0 | xargs 0 shred zfun5;date

The two date sub-commands, at the start and at the end, will give you the start and end times for the operation, should you wish to calculate the time it takes. The n5 overwrites each file five times with random data, so you can adjust this by simply varying the number five. The z flag finally fills file contents with 0s, u removes the files while f tries to force shredding by altering permission. Empty directorie­s remain. Note: Do not shred the wrong location in a hurry.

—A. Datta, webmaster@aucklandwh­ich.org

Creating a new user on Linux

You are working on a project and you want to keep it systematic­ally arranged on your system, but looking at your desktop makes you wonder how to first arrange it all. Don't worry, you can create a new user, which will give you an interface similar to a new PC with everything that you have on your existing user already installed.

Open the terminal and enter the following command

(let my new user's name be ‘newusernam­e’): $sudo adduser newusernam­e

It will ask you to enter the user's password twice, so do that step. Just press Enter on being asked the user's informatio­n. When prompted for the question, "Is the informatio­n correct [Y/N]", type Y and hit Enter. Now enter the following command:

$sudo visudo You will find the following text in the file: # User privilege specificat­ion root ALL=(ALL:ALL) ALL Then add the following code ahead of it: newusernam­e ALL=(ALL:ALL) ALL

Press Ctrl-X, Y and then press Enter.

You now have a new user with root access named ‘newusernam­e’.

—Yash Jain, yashjain.lnm@gmail.com

Making boot process reports visible in Ubuntu

By default, the boot process reports of your operating system are hidden behind a nice boot splash screen. For troublesho­oting and testing purposes, it can be very useful to make them visible.

You can do that as follows:

1. In the Grub boot menu, select the boot line of Ubuntu.

2. Press the 'E' key.

3. Remove the words ‘quiet splash’ from the boot line.

4. Press the Ctrl+X keys.

Now your system will boot once, and then your boot process reports will be visible.

—Shouvik Mitra, shouvikmit­ra@outlook.com

Get your public IP address and host name

With the help of the following commands you can get the external IP address of the server:

$curl ifconfig.me …or: $curl ifconfig.co Here is how you can get the hostname and fully qualified domain name of the Linux host. Use the following commands: # hostname # hostname f

The first command should show the short hostname and the second should show the fully qualified domain name (FQDN) of the Linux host.

—Munish Kumar, munishtote­ch@gmail.com

Copy all files excluding certain file types

We often have to copy all files excluding certain file type(s). There are many ways to solve this problem, but let’s look at the easiest and most efficient solution. For this purpose, we are going to use the 'extglob' flag of the bash shell, which enables the extended pattern matching feature for pathnames. Let us illustrate this with an example.

We have a directory which contains various files:

[bash]$ ls a.cpp a.html a.java a.mp3 a.txt b.cpp b.html b.java b.mp3 b.txt

Now we want to copy all files except the .txt and .mp3 files. So first enable extended pattern matching as follows:

[bash]$ shopt s extglob

# enables extended pattern matching

Let us execute the following command to exclude .txt and .mp3 files:

[bash]$ cp !(*.mp3|*.txt) /tmp/src/

Let us verify that the required files are copied to the new location: bash]$ ls /tmp/src/

a.cpp a.html a.java b.cpp b.html b.java Yes! It worked and we got the expected result. —Narendra Kangralkar, narendraka­ngralkar@gmail.com

 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from India