wget pause resume

Pause/Resume Downloads With ‘wget’

You have to admit when it comes to downloading, nothing beats wget. However almost every time I say this I find someone complaining about a pause option. So here’s a little less known trick for beginners.

press 'Ctrl + C' to pause the download which you started normally using something like this:
wget some_random_archive_file.zip

Now to resume it go to the same location where you were downloading and wget the download file with -c option.
wget -c some_random_archive_file.zip

And your download will resume from where it was paused. Enjoy! 🙂

System administrator

SSH One Computer From Another On Same Newtork

If you have authorized username and password for a different machine(computer) connected on the same network, you can easily ssh into it to access its contents.

For clarity, machine we are using to ssh is referred Machine 1 and machine we have to ssh into is referred Machine 2.

Now here’s how to do it.

First get the IP of the Machine 2. To find IP run the following(in Machine 2):
ifconfig                       #ipconfig for windows

It will output something like:
eth0 Link encap:Ethernet HWaddr 5x:xx:xx:xx:xx:xc
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr: Mask:
inet6 addr: ::1/128 Scope:Host
RX packets:4309 errors:0 dropped:0 overruns:0 frame:0
TX packets:4309 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:539900 (539.9 KB) TX bytes:539900 (539.9 KB)

wlan0 Link encap:Ethernet HWaddr 28:e3:47:6d:29:2c
inet addr: Bcast: Mask:
inet6 addr: fe80::2ae3:47ff:fe6d:292c/64 Scope:Link
RX packets:5906878 errors:0 dropped:0 overruns:0 frame:0
TX packets:4779402 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5143419880 (5.1 GB) TX bytes:619868581 (619.8 MB)

As we can see the IP of the machine for wlan0 is

Now run the following from Machine 1:
ssh <usser>@<ip-address>

For eg:
ssh shivam@

When asked enter the password for the user and you can now remotely access Machine 2 from Machine 1.

Ruby on Rails


FTPS is an extension to the commonly used FTP that adds support for the Transport Layer Security (TLS) and the Secure Sockets Layer (SSL) cryptographic protocols.

While FTPS using clients like FileZilla, we generally prefix our host with ‘ftpes://’:

Net::SSH is the most popular ruby library for ssh and ftp purpose. It however is not so helpful when it comes to FTPS. We will use Net::FTPFXP RubyGem instead.

Installing Net::FTPFXP is simple. Run:
gem install ftpfxp

Now to establish the connection, do the following:
require 'net/ftptls'
ftp = Net::FTPTLS.new()
ftp.passive = true
ftp.connect('host.com', port_number)
ftp.login('Username', 'Password')

Port number by default is 21.

System administrator

Reading File Permissions in Linux

Linux is based on the idea that the same system is going to be used by different users. With different users accessing the same system, there arises the need of permission. Think of it like this, you are sharing a room with different person/people in a hostel. There are a few things that are common to all, say table, chair, etc. But you still need some personal space (most likely your cupboard in this analogy) where you keep things that are accessible only by you.

Same concept can be applied in case of files present in your linux system. There are different users who can locate these files, but depending upon the type of permission those users can read them or modify them.

To check the permissions of files in a particular folder, run this:
ls -l
You will get something like this as output:
-rw-rw-r-- 1 shivam users 4004 May 8 20:19 CONTRIBUTING.md

Lets understand it backwards i.e right to left.
CONTRIBUTING.md: is the name of the file.
May 8 20:19: represents the time this file was last modified/created.
4004: is the size of the file in bytes.
users: is the group of users to which this file belongs.
shivam: is the owner of the file.
1: is the number of files.

Now comes the file permissions.
starting ‘-‘ means its a file. Had it been a directory, you would have found a ‘d’.
Now, ‘rw’ represents the permissions of the owner. In this case the owner has both read and write permissions.
Second ‘rw’ represents the permission of group of users. Here as you can see even the group users have both read and write permissions(not quite secure, eh?).
Finally the ‘r’ is the permission for everyone else, i.e. they can only read the file and cannot edit it.

Changing the permissions
You can change the permissions of the file using the chmod command which changes the permission for the site.
For example.
sudo chmod 0600 CONTRIBUTING.md

Now if you do ls -l, you will get
-rw------- 1 shivam shivam 4005 May 24 22:47 CONTRIBUTING.md
meaning only the owner had read and write permissions. Other cant even read it.

Different file permissions and there meaning are as follows:

Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
755 (rwxr-xr-x) The file’s owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
700 (rwx——) The file’s owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
666 (rw-rw-rw-) All users may read and write the file.
644 (rw-r–r–) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
600 (rw——-) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.
System administrator

Grub2: Boot in recovery mode, Like a boss!

There are 1000 things that can go wrong ultimately leading to server crash/freeze. Some of the most common reason are : network problems, system overload, configuration errors, hardware issues, out of disk space etc.

When things go wrong we restart server in recover mode. Sometimes by default on reboot, grubs menu shows up with no timeout. This can prevent you from automatically rebooting your servers (as grub will infinitely wait for a user input).

You certainly in most of the cases want to avoid such situation. This can easily be done in a few steps.

Open the file /etc/default/grub with an editor and add the variable GRUB_RECORDFAIL_TIMEOUT as following:


where N =  desired timeout in seconds. This will make the grub wait for N secs and then continue with default choice.

In case you do not want any timeout at all, set it to -1.


If you want to completely disable the menu (even for failed startup), set it to 0


Now save the file and update grub by:

sudo update-grub

This will apply your changes to the grub as desired.


Moving complete mysql from one server to another without mysqldump

Whenever it comes to transfer database (mysql) from one server to other, the first obvious choice that comes to one’s mind is mysqldump. All you need to do is run the command:

mysqldump -u root -p --opt [database name] > [database name].sql

It will output a sql file for your database. Scp the sql file to your new servers, create a database with the same name in the new machine and run this:

mysql -u root -p newdatabase < /path/to/newdatabase.sql

All is well unless your database is of limited size. But suppose your database is in GBs meaning you’re f’ckd!! This method will still work but it will take years (not literally) to generate all the tables and fields in the new database using the dumped sql file. Also it will eat up a lot of resources on your new server.

The alternative is rather way too simple. All you need to do is go to your mysql data directory. If you are using ubuntu, most probably you are looking for this location:


Before proceeding ahead, you may want to stop your mysql server. Just run this:

sudo service mysql stop

Also as we are going to access files that need root permissions, better do:

sudo bash

We will now zip all the contents of the mysql data directory.

zip -r completemysql.zip /var/lib/mysql/*

This is will create a zip file containing all you mysql data. Now scp this to the new servers (or machine).
Once you ssh to your new server with the zip file already t transferred in its home. Unzip it in a directory(we name it ‘database’)

unzip completemysql.zip -d database

Now delete all the log files from the unzip location ( ~/database in our case).
It should look something like:

rm ib_logfile0 ib_logfile1

Before proceeding ahead we need to stop the mysql server. Run:

sudo service mysql stop

to confirm the mysql server stopped do:

mysqladmin -u root -p status

If this gives an error, it means the mysql server is not running, which is what we want in our case.
Now copy all the files from ~/database directory to the mysql data directory of this machine.

cp -R ~/database/* /var/lib/mysql/

We are almost there, if at this moment you start your mysql server and try show databases it will list all your databases from the previous server. However when you try to access them, you may not be able to do so and get following permission error :

ERROR 1018 (HY000): Can't read dir of './<your_database_dir>/' (errno: 13)

This is because the owner of the copied files is the ‘root’ and we need to make it ‘mysql’. We can resolve this by:

chown -R mysql:mysql /var/lib/mysql/
chmod -R 755 /var/lib/mysql/

Now start the mysql server and its done.

sudo service mysql start