Tag Archives: unix

Setup SSH alias


This is easy tip. But I never knew in so many years.

Tip : How to open remote shell without typing the full server and user detail. Its like SSH alias.

Open the ssh folder.

cd /home/ganu/.ssh/
touch config
vi config

Then add the following lines in the config file

Host host1
  User=ganu
  Hostname=some.server.com
Host host2
  User=user2
  Hostname=some.host.server.com

Then save this file and just type

ssh host1

It will ask for password. And you are done.

Happy Bash.

How to enable Apache mod_rewrite in openSUSE


I got a situation where my Apache mod_rewrite module was not enabled for my openSUSE machine.
Here is the simple way to do it.

First check which apache modules are enabled in your machine.

ankur@ankur:/srv/www/htdocs> grep "^APACHE_MODULES" /etc/sysconfig/apache2
APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl userdir php5"

Second Change the apache2 config for modules and restart your apache.

ankur@ankur:/srv/www/htdocs> sudo vi /etc/sysconfig/apache2
ankur@ankur:/srv/www/htdocs> sudo /etc/init.d/apache2 restart
Syntax OK
Shutting down httpd2 (waiting for all children to terminate) done
Starting httpd2 (prefork) done

Finally, chech you module is installed.

ankur@ankur:/srv/www/htdocs> grep "^APACHE_MODULES" /etc/sysconfig/apache2
APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl userdir php5 rewrite"

huh!! Its working.

Happy Apache.

Quick Tutorial – How to zip and unzip files under unix environment


Linux support zip and unzip facility.
All you need to install zip and unzip via apt-get in your debian/ubuntu linux.
The same is available via yum or zypper.

Some examples for zip and unzip.

1. Creates the zip archive and put all the files of the current directory in the compressed form.

ankur@ankur:~> cd test/
ankur@ankur:~/test> ll
total 0
-rw-r--r-- 1 ankur users 0 2010-10-20 10:03 1.txt
-rw-r--r-- 1 ankur users 0 2010-10-20 10:03 2.txt
-rw-r--r-- 1 ankur users 0 2010-10-20 10:03 3.txt
ankur@ankur:~/test> zip zipthis *
 adding: 1.txt (stored 0%)
 adding: 2.txt (stored 0%)
 adding: 3.txt (stored 0%)
ankur@ankur:~/test> ll
total 4
-rw-r--r-- 1 ankur users   0 2010-10-20 10:03 1.txt
-rw-r--r-- 1 ankur users   0 2010-10-20 10:03 2.txt
-rw-r--r-- 1 ankur users   0 2010-10-20 10:03 3.txt
-rw-r--r-- 1 ankur users 382 2010-10-20 10:05 zipthis.zip
ankur@ankur:~/test>

This command will automatically put the zip extension when the process will done.

2. Now try for zipping the subdirectory also..
Here I have created the subdirector as “subtest”.

ankur@ankur:~/test> ll
total 8
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 1.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 2.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 3.txt
drwxr-xr-x 2 ankur users 4096 2010-10-20 10:14 subtest
-rw-r--r-- 1 ankur users  382 2010-10-20 10:05 zipthis.zip
ankur@ankur:~/test> zip -r subzipthis *
 adding: 1.txt (stored 0%)
 adding: 2.txt (stored 0%)
 adding: 3.txt (stored 0%)
 adding: subtest/ (stored 0%)
 adding: subtest/sub1.txt (stored 0%)
 adding: subtest/sub2.txt (stored 0%)
 adding: zipthis.zip (stored 0%)
ankur@ankur:~/test> ll
total 12
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 1.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 2.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 3.txt
drwxr-xr-x 2 ankur users 4096 2010-10-20 10:14 subtest
-rw-r--r-- 1 ankur users 1306 2010-10-20 10:15 subzipthis.zip
-rw-r--r-- 1 ankur users  382 2010-10-20 10:05 zipthis.zip
ankur@ankur:~/test>

To use unzip to extract all files of the archive pics.zip into the current directory & subdirectories:

3. Listing of your files from a zip folder.

ankur@ankur:~/test> ll
total 8
-rw-r--r-- 1 ankur users 1306 2010-10-20 10:15 subzipthis.zip
-rw-r--r-- 1 ankur users  382 2010-10-20 10:05 zipthis.zip
ankur@ankur:~/test> unzip -l subzipthis.zip
Archive:  subzipthis.zip
 Length     Date   Time    Name
 --------    ----   ----    ----
 0  10-20-10 10:03   1.txt
 0  10-20-10 10:03   2.txt
 0  10-20-10 10:03   3.txt
 0  10-20-10 10:14   subtest/
 0  10-20-10 10:14   subtest/sub1.txt
 0  10-20-10 10:14   subtest/sub2.txt
 382  10-20-10 10:05   zipthis.zip
 --------                   -------
 382                   7 files
ankur@ankur:~/test>

4. To test about your zip archive that archive is OK or not:

ankur@ankur:~/test> unzip -tq subzipthis.zip
No errors detected in compressed data of subzipthis.zip.
ankur@ankur:~/test> unzip -tq zipthis.zip
No errors detected in compressed data of zipthis.zip.

5. Unzip your data

ankur@ankur:~/test> unzip zipthis.zip
Archive:  zipthis.zip
 extracting: 1.txt
 extracting: 2.txt
 extracting: 3.txt
ankur@ankur:~/test> ll
total 8
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 1.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 2.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 3.txt
-rw-r--r-- 1 ankur users 1306 2010-10-20 10:15 subzipthis.zip
-rw-r--r-- 1 ankur users  382 2010-10-20 10:05 zipthis.zip

6. Now you want to extract only the specific files from your zip folder. You can use like this…

ankur@ankur:~/test> unzip zipthis.zip 1.txt
Archive:  zipthis.zip
 extracting: 1.txt
ankur@ankur:~/test> ll
total 8
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 1.txt
-rw-r--r-- 1 ankur users 1306 2010-10-20 10:15 subzipthis.zip
-rw-r--r-- 1 ankur users  382 2010-10-20 10:05 zipthis.zip

7. To extract all files to some specified directory.

ankur@ankur:~/test> unzip zipthis.zip -d /home/ankur/test/
Archive:  zipthis.zip
 extracting: /home/ankur/test/1.txt
 extracting: /home/ankur/test/2.txt
 extracting: /home/ankur/test/3.txt
ankur@ankur:~/test> ll
total 8
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 1.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 2.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 3.txt
-rw-r--r-- 1 ankur users 1306 2010-10-20 10:15 subzipthis.zip
-rw-r--r-- 1 ankur users  382 2010-10-20 10:05 zipthis.zip

8. Unzip files one by one with confirmation.

ankur@ankur:~/test> unzip -q subzipthis.zip
replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
replace 2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
replace 3.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
replace zipthis.zip? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
ankur@ankur:~/test> ll
total 12
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 1.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 2.txt
-rw-r--r-- 1 ankur users    0 2010-10-20 10:03 3.txt
drwxr-xr-x 2 ankur users 4096 2010-10-20 10:14 subtest
-rw-r--r-- 1 ankur users 1306 2010-10-20 10:15 subzipthis.zip
-rw-r--r-- 1 ankur users  382 2010-10-20 10:05 zipthis.zip

9. Zip and Unzip version and liceance.

zip -v
zip -L
unzip -v

10. Help from zip and unzip

zip -h
unzip -h