Linux Tips and Tricks

Linux Tips and Tricks

Let it Snow

December18

Hi,

we all started to celebrate the Christmas. Today we will see the command xsnow

In the ubuntu system, type the below command to install the xsnow command

$sudo apt-get install xsnow

Once the package is downloaded and installed, open the console and type the below command.

$xsnow

Once you executed the command, you can see wonderful snow flakes in your desktop and santa claus will be traveling in his moose vehicle and you can see Christmas trees.

you have the blow options in this command.

1) change the snow flakes count ( default is 100 )
2) change the snow flakes color
3) change the tree color
4) background color
5) santa size
6) no trees, no santa

If you want to execute this command in background, then type the below command.

$xsnow &

If you want to stop the snow, then type kill the xsnow PID

ps -ef | awk '/xsnow$/ {print $2}'

Once you found the PID of the xsnow, then issue the kill command.

kill -i PID

Happy Christmas 🙂

posted under Uncategorized | 2 Comments »

Command Line Download Manager

December13

aria2 is a lightweight multi-protocol & multi-source download utility operated in command-line. It supports HTTP/HTTPS, FTP, BitTorrent and Metalink. aria2 has built-in JSON-RPC and XML-RPC interface. You can manipulate aria2 via these interfaces.

How to install the aria2 ?

In ubuntu system type the below command.

1
$ sudo apt-get install aria2

Once the aria2 is installed, you can use this to download the files from the url.

Download the awk one liner script

1
$ aria2c http://www.pement.org/awk/awk1line.txt

Download from 2 websites ( http & ftp )

1
$ aria2c http://one/a.txt ftp://two/b.txt

Download using 2 connections per host

1
$ aria2c -x2 http://one/a.txt

BitTorrent

1
$ aria2c http://test.com/test.torrent

Metalink

1
$ aria2c http://test.org/one.metalink

Download URIs found in text file

1
$ aria2c -i url.txt
posted under Uncategorized | No Comments »

Create Ringtone From MP3 File

December12

Today we are going to see, how to create a ringtone from the MP3 file.

we are going to use the command called “cutmp3”

open the Terminal and type “cutmp3” ( without double quotes )

1
2
3
4
5
6
$ cutmp3
 
cutmp3  version 2.0.2  
 
Usage:  cutmp3 -i file.mp3 [-a inpoint] [-b outpoint] [-f timetable]
               [-o outputprefix] [-e] [-c] [-C] [-q]

If cutmp3 is not installed in your system, then type the below command ( in ubuntu )

1
$ sudo apt-get install cutmp3

Now, we can see, how to cut the mp3 file.

1
2
$ cutmp3 -i test.mp3 -a 0:01 -b 0:20
  saved 0:01.00 - 0:20.00 to 'result0001.mp3'.

-i input file. ( mp3 file )
-a starting point
-b ending point

So, in the above example, i extracted the data from 0:01 second to 0:20 seconds. And the resultant output is saved as “result0001.mp3”

If you want to give the output filename, then use -O (upper case) option.

1
2
3
 
$ cutmp3 -i test.mp3 -a 0:01 -b 0:20 -O output.mp3
  saved 0:01.00 - 0:20.00 to 'output.mp3'.

we have some other aruments also

1
2
-I print the information of the mp3 file.
-f filename ( filename should have the valid time frame. eg: 0:01 1:03 )
posted under Uncategorized | No Comments »

view non-printable characters

December8

we can use cat command and od commands to see the non-printable characters.

Let me explain how to create some non printable characters.

1) open the console and type the below.
2) echo “Hello <ctrl + v> <ctrl +m> World” > myfile.txt

Note :– <ctrl+v> means press control key and v in the keyboard.

3) Once the file is created, use cat command to view the file contents

1
2
3
4
$ echo "Hello ^M World" > myfile.txt
 
$ cat myfile.txt
 World

4)As you notice, Hello word is disappeared.

5) use the -v option in the cat command.

1
2
$ cat -v myfile.txt
Hello ^M World

6) Now you can see the word “Hello” but after that you can see some special character (^M) which is not printed while using the cat command
7) now we can use od command to see the special characters.

1
2
3
$ od -c myfile.txt 
0000000   H   e   l   l   o      \r       W   o   r   l   d  \n
0000016

You can clearly see there is come special character \r present between the Hello and World.

Control-M is carriage return without linefeed.

How to remove the special characters ?

In this case, we can remove \r (which is clearly found by od -c command )

1
2
3
4
5
6
7
$ cat -v myfile.txt 
Hello ^M World
 
$ sed -i 's/\r//' myfile.txt 
 
$ cat -v myfile.txt 
Hello  World
posted under Uncategorized | No Comments »

Step by Step :: Password less ssh login

November10

First we will see, how to install the openssh in your ubuntu machine.

1) Type the below command in your console

1
$ sudo apt-get install openssh-server openssh-client

2) Once it get installed, see whether you have the sshd dameon is running in your system or not.

1
2
$ps -ef | grep ssh
root      3878     1  0 23:26 ?        00:00:00 /usr/sbin/sshd -D

3) Now you are ready to use the ssh connection. Lets test the ssh connection to the localhost itself.

1
2
3
4
5
6
$ ssh localhost
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is 99:4c:e7:56:8e:ec:81:67:87:95:38:26:35:01:a1:e4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
kamaraj@localhost's password:

Now provide the password for your user account. And it will get into the system (in this case its localhost)

4) How to set password less connectivity ?

5) create public key and private key for the host by using the below command.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#Goto the home directory and execute the below ssh-keygen command
$ cd 
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kamaraj/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identificat ion has been saved in /home/kamaraj/.ssh/id_rsa.
Your public key has been saved in /home/kamaraj/.ssh/id_rsa.pub.
The key fingerprint is:
16:fc:a9:bc:d9:fe:f1:12:0f:05:88:04:b4:8c:5b:97 kamaraj@Kamaraj
The key's randomart image is:
+--[ RSA 2048]----+
|     .oo.. .     |
|     o o... .    |
|    . + E    .   |
|     o . o .  .  |
|    .   S o  .   |
|       o .  o    |
|        o   .+   |
|         +  .o.  |
|        o.o....  |
+-----------------+

6) Now you can see a .ssh folder is created in your home directory and you can see some files inside the .ssh folder.

Note : .ssh is hidden folder

1
2
3
4
5
kamaraj@Kamaraj:~/.ssh$ ls -lrt
total 16
-rw-r--r-- 1 kamaraj kamaraj 1106 Nov 10 23:26 known_hosts
-rw-r--r-- 1 kamaraj kamaraj  397 Nov 10 23:28 id_rsa.pub
-rw------- 1 kamaraj kamaraj 1675 Nov 10 23:28 id_rsa
1
2
~/.ssh/id_rsa : private or identification key
~/.ssh/id_rsa.pub : public key

7) create a new file called authorized_keys2 in .ssh folder and copy the contents of id_rsa.pub.

1
cat id_rsa.pub >> authorized_keys2

8) That’s all. Now try the ssh command.

1
2
3
4
5
6
7
$ ssh localhost
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-12-generic i686)
 
 * Documentation:  https://help.ubuntu.com/
 
Last login: Thu Nov 10 23:48:00 2011 from localhost
$

This time ssh command didn’t ask the password.

If you want to connect to some other machine, then scp the id_rsa.pub file to the destination machine and put it under the .ssh folder in the name of authorized_keys2.

posted under Uncategorized | No Comments »

Deadly Commands in Linux

October13

1) The below command deletes everything recursively and forcefully.

1
sudo rm -rf /

2) Data on device mentioned after the mkfs command will be destroyed and replaced with a blank filesystem

1
2
3
mkfs
mkfs.ext3
mkfs.anything

3) Forkbomb: Executes a huge number of processes until system freezes, forcing you to do a hard reset which may cause corruption, data damage, or other awful fates.
In Bourne-ish shells, like Bash: (This thing looks really intriguing and curiousity provokes)

1
:(){:|:&};:

In Perl

1
fork while fork

4) Using the below command, raw data will be written to a block device that can usually clobber the filesystem resulting in total loss of data.

1
any_command > /dev/sda
posted under Uncategorized | No Comments »

Bash Tricks

September25

Bash Tricks

list the alphabets ‘A’ to ‘Z’

1
2
$ echo {A..Z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

list the alphabets ‘Z’ to ‘A’

1
2
$ echo {Z..A}
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A

list the alphabets ‘a’ to ‘z’

1
2
$ echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z

list the alphabets ‘z’ to ‘a’

1
2
$ echo {z..a}
z y x w v u t s r q p o n m l k j i h g f e d c b a

list the numbers 1 to 15

1
2
$ echo {1..15}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Adding number in the back

1
2
$ echo {1..15}1
11 21 31 41 51 61 71 81 91 101 111 121 131 141 151

Adding number in front and back.

1
2
$ echo 2{1..15}1
211 221 231 241 251 261 271 281 291 2101 2111 2121 2131 2141 2151

Apply it for copy command

1
2
3
4
5
$ cp {A,C}.txt
 
$ ls -lrt [AC].txt
-rw-r--r-- 1 kamaraj kamaraj 12 Sep  6 23:08 A.txt
-rw-r--r-- 1 kamaraj kamaraj 12 Sep 25 22:52 C.txt
posted under Uncategorized | 2 Comments »

Compare md5 of two files in shell script

September21

What is MD5?
The MD5 Message-Digest Algorithm is a widely used cryptographic hash function that produces a 128-bit (16-byte) hash value. Specified in RFC 1321, MD5 has been employed in a wide variety of security applications, and is also commonly used to check data integrity. <<More>>

md5deep or md5sum commands are used to get the MD5 value for the files.

If you dont have these commands in your ubuntu, then type the below command and install the md5deep package.

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo apt-get install md5deep
[sudo] password for kamaraj:
Reading package lists... Done
Building dependency tree       
Reading state information... Done
................
......................
Selecting previously deselected package md5deep.
(Reading database ... 251462 files and directories currently installed.)
Unpacking md5deep (from .../md5deep_3.4-3_i386.deb) ...
Processing triggers for man-db ...
Setting up md5deep (3.4-3) ...
$

Once installed, type the below command and check whether you have md5deep and md5sum commands in your system.

1
2
3
4
5
6
7
8
9
10
11
$ md5sum --version
md5sum (GNU coreutils) 7.4
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
 
Written by Ulrich Drepper, Scott Miller, and David Madore.
 
$ md5deep -v       
3.4

Now create some text files or take any existing file. Now, we will find out the MD5 value for that file.

I have a file called A.txt and now we will find out the MD5 value for that file.

1
2
3
4
5
6
7
8
9
10
11
12
13
$ cat A.txt
A
B
C
D
E
F
 
$ md5sum A.txt
6af4cbb084064df395d07ecac556de95  A.txt
 
$ md5deep A.txt
6af4cbb084064df395d07ecac556de95  /home/kamaraj/Desktop/Scripts/A.txt

How to compare the two MD5 values?

1
2
3
4
5
6
7
8
9
10
11
$ a=$(md5deep -q A.txt)
 
$ b=$(md5deep -q B.txt)
 
$ [ "$a" = "$b" ] && echo  "Equal" || echo "Not Equal"
Equal
 
$ b=$(md5deep -q  C.txt)
 
$ [ "$a" = "$b" ] && echo  "Equal" || echo "Not Equal"
Not Equal
posted under Uncategorized | No Comments »

Sending email via gmail in linux

September19

Sending email via gmail in linux

1) Make sure you have Heirloom mailx. How to test it ?
simply enter the below code in your command prompt

1
2
3
$mailx -v
mail: invalid option -- v
Try `mail --help' or `mail --usage' for more information.

If you get the above error message, then you need to install the Heirloom mailx.

2) How to install it ? (i am using ubuntu)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ sudo apt-get install heirloom-mailx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libgsasl7 libmailutils2 libntlm0
................
.............
................
The following packages will be REMOVED:
mailutils
The following NEW packages will be installed:
heirloom-mailx
................

3) Once the package is installed, check whether you have any file called .mailrc in your home directory.

1
2
$ ls -l ~/.mailrc
ls: cannot access /home/kamaraj/.mailrc: No such file or directory

4) If you have any file, then just open and put the below contents. Otherwise create a new file called .mailrc

1
2
3
4
5
6
7
8
account gmail {
set smtp-use-starttls
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=abcd@gmail.com
set smtp-auth-password=mypassword
set from="ABCD "
}

5) Just change the contents of the below lines.

1
2
3
set smtp-auth-user=YOUR-GMAIL-ID
set smtp-auth-password=YOUR-GMAIL-PASSWORD
set from="NAME"

6) Its the time to test. Now trigger the below command from your command prompt.

1
 
1
2
3
4
5
6
7
8
9
10
11
$ echo "Test Email" | mailx -v -A gmail -s "test" yyyyyyyy@gmail.com
Resolving host smtp.gmail.com . . . done.
Connecting to 74.125.45.109 . . . connected.
250 2.0.0 OK 1316447647 s8sm2760907ani.3
 
...............
............
............
 
 >>> QUIT
 221 2.0.0 closing connection s8sm2760907ani.3

7) Now check your gmail inbox (sent items).

posted under Uncategorized | 4 Comments »

Passwordless FTP setup – Linux

September15

Normally when you are using ftp command, it will ask username and password to connect to that specified ftp host.

we will see how to setup the password less FTP setup.

Today i installed the FTP server in my ubuntu.

In the terminal type the below command and provide the password to install the FTP server.

1
$ sudo apt-get install vsftpd

After that open the below file and modify the anonymous_enable value to YES

1
2
3
4
$ sudo vi /etc/vsftpd.conf
 
# Allow anonymous FTP? (Disabled by default)
anonymous_enable=YES

Now restart the vsftpd service by using the below command.

1
2
3
4
5
6
7
8
9
10
#before restart - PID is 3599
$ ps -ef | grep vsftpd
root      3599     1  0 23:25 ?        00:00:00 /usr/sbin/vsftpd
 
$ sudo restart vsftpd
vsftpd start/running, process 3691
 
#after restart - PID is 3691
$ ps -ef | grep vsftpd
root      3691     1  0 23:33 ?        00:00:00 /usr/sbin/vsftpd

All set to go. Try to connect to your localhost.

username : anonymous
password : anonymous

1
2
3
4
5
6
7
8
9
10
$ ftp localhost
Connected to localhost.
220 (vsFTPd 2.2.2)
Name (localhost:kamaraj): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

So, now successfully connected to our localhost ftp server.

Now, we will see how to setup passwordless ftp configuration.
It is very simple.

create a file .netrc under your home directory.And put the contents which is shown as below.

The format is : machine login password

1
2
3
4
5
$ pwd
/home/kamaraj
 
$ cat .netrc 
machine localhost login anonymous password anonymous

Note: Make sure .netrc is atleast having the read permission (400) permission for the user.

That’s all.

Now, we will try to login into localhost.

1
2
3
4
5
6
7
8
$ ftp localhost
Connected to localhost.
220 (vsFTPd 2.2.2)
331 Please specify the password.
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

This time ftp didn’t ask the username and password.

Have Fun 🙂

posted under Uncategorized | No Comments »
« Older EntriesNewer Entries »

Recent Comments

    Categories