Saturday, 31 August 2013

How to prevent accidental delete rm -rf * in Linux

To prevent accidental delete rm -rf * in Linux by different ways

If you want to prevent any important directory deleted accidental

Create a file named -i in that directory. How can such a odd file be created? Using touch -- -i or touch ./-i

Now try rm -rf *:

[root@server]# touch {1..4}
[root@server]# touch -- -i
[root@server]# ls
1  2  3  4  -i file1 file2 directory1
[root@server]# rm -rf *
rm: remove regular empty file `1'? n
rm: remove regular empty file `2'?
Here the * will expand -i to the command line, so your command ultimately becomes rm -rf -i.
So command will prompt before removal. You can put these files in your /, /home/, /etc/, / etc.


Use --preserve-root as an option to rm. In the rm included in newer coreutils packages, this option is the default.
create alias to rm

alias rm=rm -i --preserve-root

--preserve-root means do not remove `/' (default)


Use safe-rm

Safe-rm is a safety tool intended to prevent the accidental deletion of important files by replacing /bin/rm with a wrapper, which checks the given arguments against a configurable blacklist of files and directories that should never be removed.

Users who attempt to delete one of these protected files or directories will not be able to do so and will be shown a warning message instead:

[root@server]# rm -rf /usr
Skipping /usr
Read More

Thursday, 29 August 2013

Solution : Check Variable in Linux Bash is Float or Interger


Here solution for checking a variable in Linux Bash is Float or Integer by using grep.

---- file :

function check_int(){
echo $1 | grep "^[0-9]*$" > /dev/null
if [ $? -ne 0 ]; then
echo $2 : $1 is not a number;
                echo $2 : $1 is a number

function check_float() {
echo $1 | grep "^[0-9]*\.[0-9]*$" > /dev/null
if [ $? -ne 0 ]; then
check_int $1 $2
                echo $2 : $1 is a float number

check_int 12 my_number
check_float  12.2 my_number

check_int 12a my_number
check_float  12a2 my_number


yadavmahi@localhost:~/MahiYadav/scripts> bash
my_number : 12 is a number
my_number : 12.2 is a float number
my_number : 12a is not a number
my_number : 12a2 is not a number

Read More

Wednesday, 28 August 2013

Create Fake Swap in OpenVZ VPS if you get swapon failed: Operation not permitted Error

if you get swapon failed: Operation not permitted Error even if you run as root it is because in your VPS swap creation is not allowed
follow below steps to Create Fake Swap in OpenVZ VPS

[root@server] free -m
              total       used       free
Mem:          4096        104       3991
-/+ buffers/cache:        104       3991
Swap:            0          0          0

create shell script file add lines like below

[root@server] vi


NEW="$[SWAP*1024]"; TEMP="${NEW//?/ }"; OLD="${TEMP:1}0"

umount /proc/meminfo 2> /dev/null

sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo
mount --bind /etc/fake_meminfo /proc/meminfo

free -m

[root@server] chmod +x
[root@server] sh
[root@server] free -m
 total       used       free
Mem:          4096        104       3991
-/+ buffers/cache:        104       3991
Swap:          512          0        512

to create 1024MB Swap run like below
[root@server] sh 1024
[root@server] free -m
 total       used       free
Mem:          4096        104       3991
-/+ buffers/cache:        104       3991
Swap:          1024          0        1024

Read More

How to Copy with overwrite in Linux

To copy content with default overwrite in linux use below command

 [root@server1] yes | cp -rf directory1/*  /home/directory2
Read More

How to restrict download speed in wget

To restrict download speed in wget use below command

wget --limit-rate=500k

where --limit-rate=500k speed

Read More

How to Enable .htaccess and Verify if .htaccess file is running

Step 1 : changes in the .htaccess should take effects if you change .conf  file of apache like below

<Directory ..>
    AllowOverride None

Should be changed to

<Directory ..>
    AllowOverride All

Step 2 : 
check for below line in  .conf  file of apache
LoadModule rewrite_module modules/

If it is commented(#), uncomment (remove # )

Now restart apache server

Step 2 :

Enter some junk value into your .htaccess restart apache server and visit your URL.
If .htaccess is working, you should get a
500 Internal Server Error
Read More

Solution: Install/Update Wordpress plugins without providing FTP access

Hi if you don't have FTP access to your wordpress server yow follow below steps to Install/Update Wordpress plugins from wordpress admin panel

step1 : Change "wp-content" folder permissions to 777

sudo chmod -R 777 wp-content

step2In "wp-config.php" file add define('FS_METHOD', 'direct');

example :
/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

define('FS_METHOD', 'direct');

Read More

Wednesday, 21 August 2013

Solution : Making of Bootable USB live from Open Suse 12.3 ISO


Here is the solution for the opensuse bootable usb live.

Download the Opensuse 12.3 from :

 Now  login as root in any linux machine

 $ cd < location of folder of iso>
 $ isohybrid openSUSE-12.3-GNOME-Live-i686.iso

# what this command do , ISOLINUX supports a "hybrid mode" which can be booted from either CD-ROM or from a device which BIOS considers a
hard disk or ZIP disk, e.g. a USB key or similar.

$ dd if=openSUSE-12.3-GNOME-Live-i686.iso of=/dev/sdb1  bs=4M

/dev/sdb1 : your usb drive.

By this we can make openSUSE on USB

Read More

Tuesday, 20 August 2013



sample   /etc/squid3/squid.conf :

auth_param basic program /usr/lib/squid3/ncsa_auth /etc/squid3/passwd
auth_param basic children 5
auth_param basic realm Squid proxy with NCSA
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off

acl usrs proxy_auth REQUIRED
http_access allow usrs
http_access deny all

http_port 3128

> Before starting the Squid server we need  to create a password file by using NCSA for that we need
apache2-utils  (ubuntu)

> for the first time creating the passwd we need to use -c option for htpasswd command , for next don't use -c

$ /usr/bin/htpasswd -c /etc/squid3/passwd  somexyz
New password:
Re-type new password:
Adding password for user somexyz

>Now start squid server :

$ service squid3 start

>  Squid proxy will  start but we not able log in, because the password file storing in the format md5, but Squid 3 uses Crypt format password.

> To uses Crypt format password user we need to use  "-d" for more details "/usr/bin/htpasswd --help"

$ /usr/bin/htpasswd -d /etc/squid3/passwd somexyz1
New password:
Re-type new password:
Adding password for user somexyz

> Now restart the Squid service

$ service squid3 stop
$ service squid3 start

> Now we can login with somexyz1 user account into squid proxy : - )

Read More

Wednesday, 14 August 2013

PUTTY command line ssh login with plink

First we need Putty in Linux ?

     Download the PUTTY source code file from :


After that we need build that package. we need gcc and gcc-devel packages, if you want gui we need gtk-2 packages

$  tar -zxvf putty-0.63.tar.gz
$  cd putty-0.63

$  ./configure --prefix=/apps/putty  # your installation location


$ ./configure               #if you don't want seperatly remove --prefix

$ make
$ make install

$ cd /app/putty/bin
$ ./plink -ssh  -l somexyz
$  # login into
$ exit

for enabling X11 in plink as :

$./plink -ssh -X -l somexyz

for command line passing password as :

$  ./plink -ssh -X -l somexyz -pw xyzabc

for running remote system commands as :

$  ./plink -ssh -X -l somexyz -pw xyzabc  "uname  -a"
Read More

Sunday, 4 August 2013

Solution : javac command not found in Linux

Hi if you get javac command not found in Linux even you have
java-open jdk installed means java-devel not there
Install java-devel
In Fedora
yum install java-devel
In Ubuntu
apt-get install java-devel
Read More

Steps to Sign a JAR file using self signed Certificate

To Sign a JAR file using self signed Certificate follow below steps
keytool come with Java, so install Java First

Step1 : Create .jar file from .class file

C:\javaapp> jar cvf VideoANTyd.jar VideoANTyd.class

Step2 : Create a Key by using key tool

C:\javaapp>keytool -genkey -alias selfsigned -keyalg RSA -keysize 2048 -validity
Enter keystore password:
keytool error: Keystore was tampered with, or password was

If you get above error goto C:/Users/yourname/ and delete .keystore file

Now again

C:\javaapp>keytool -genkey -alias selfsigned -keyalg RSA -keysize 2048 -validity
Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:  Name
What is the name of your organizational unit?
  [Unknown]:  VideoANT
What is the name of your organization?
  [Unknown]:  PMDOX
What is the name of your City or Locality?
  [Unknown]:  YourCity
What is the name of your State or Province?
  [Unknown]:  YourState
What is the two-letter country code for this unit?
  [Unknown]:  YourCountry
Is CN=Name, OU=VideoANT, O=PMDOX, L=YourCity, ST=YourState, C=YourCountry cor
  [no]:  yes

Enter key password for <selfsigned>
        (RETURN if same as keystore password):

Step3 : Create certificate from Above Key

C:\javaapp>keytool -export -alias selfsigned -file VideoANT.crt
Enter keystore password:
Certificate stored in file <VideoANT.crt>

Step4 :  Sign a JAR file

C:\javaapp>jarsigner VideoANTyd.jar selfsigned
Enter Passphrase for keystore:



Read More

Thursday, 1 August 2013

Simple and Best Linked List example in C

Below linked list example is taken from it is easy and working properly. I did small modifications to it

This example is single linked list


struct list {
   int val;
   struct list * next;

void main() {
   struct list * head = NULL;
   struct list * curr = NULL;

//Storing data into Linked list
      curr = (struct list *)malloc(sizeof(struct list));
      curr->val = 10;
      curr->next  = head;
      head = curr;

//Storing data into Linked list
      curr = (struct list *)malloc(sizeof(struct list));
      curr->val = 5;
      curr->next  = head;
      head = curr;

   curr = head;

//Reading data from Linked list (it print from tail)
   while(curr) {
      printf("%d\n", curr->val);
      curr = curr->next ;

Compilation Output

[root@system Desktop]# gcc linkedlist.c 
[root@system Desktop]# ./a.out
[root@system Desktop]# 

Read More

Solution : Implicit Declaration Of Function malloc error in Linux Kernel

Hi if you get Implicit Declaration Of Function malloc error in Linux Kernel then
solution is use vmalloc or kmalloc

kmalloc: Best used for fast allocations that are smaller than a page (PAGE_SIZE, 0x1000 on most architectures). It doesn't involve mapping memory, so you get the memory straight from the kernel's 1:1 physical memory mapping. You get physically contingent memory. Note that if you you want to allocate more than one page (i.e. order > 0), you risk bumping into external fragmentation issues - i.e. the call might fail even if there is enough free. Higher order - higher chance for allocation failure, and up-time plays a factor here too.

If you want to achieve maximal allocation efficiency then using your own kmem_cache for each type of struct is the way to go (the other benefits for this strategy are being able to monitor the state of your allocations from /proc and catching memory leaks more easily).

vmalloc: Allocations of more than one page. You get mapped-memory in kernel space. Behind the scenes it is similar to what userspace gets - the kernel allocates a bunch of pages and maps them in a virtual address space. This allocation is slower than kmalloc's, and memory accesses might incur a bit more overhead

Avoid vmalloc whenever possible and use kmalloc

kmalloc() should only be used allocating small amounts of memory (a few kb).  vmalloc() is better for larger amounts
Read More
Here We Write The Problems we face at different situations and Solutions to those problems.