menu

Sunday, 18 March 2018

Tips and Tricks for Using Linux Command Line

Tips and Tricks for Using Linux Command Line


  • You can use the clear command to clear the terminal if your screen is full
  • TAB can be used to fill up in terminal. For example, You just need to type “cd Doc” and then TAB andthe terminal fills the rest up and makes it “cd Documents”.
  • Ctrl+C can be used to stop any command in terminal safely. If it doesn't stop with that, then Ctrl+Z can be used to force stop it.
  • Use the exit command for exit from the terminal by .
  • You can power off or reboot the computer by using the command sudo halt and sudo reboot.
Basic Commands
1. pwd — When you first open the terminal, you are in the home directory of your user. To know which directory you are in, you can use the “pwd” command. 
2. ls — Use the "Is" command to know what files are in the directory you are in. You can see all the hidden files by using the command “ls -a”.
3. cd — Use the "cd" command to go to a directory. For example, if you are in the home folder, and you want to go to the downloads folder, then you can type in “cd Downloads”. 

4. mkdir & rmdir — Use the mkdir command when you need to create a folder or a directory. For example, if you want to make a directory called “DIY”, then you can type “mkdir DIY”. Remember, as told before, if you want to create a directory named “DIY Hacking”, then you can type mkdir DIY\ Hacking”. Use rmdir to delete a directory. 

5. rm — Use the rm command to delete files and directories. But rm cannot simply delete a directory. Use “rm -r” to delete a directory. 

7. man & --help — To know more about a command and how to use it, use the man command. It shows the manual pages of the command. For example, “man cd” shows the manual pages of the cd command. 

8. cp — Use the cp command to copy files through the command line. It takes two arguments: The first is the location of the file to be copied, the second is where to copy.

9. mv — Use the mv command to move files through the command line. We can also use the mv command to rename a file. For example, if we want to rename the file “text” to “new”, we can use “mv text new”. It takes the two arguments, just like the cp command.

10. locate — The locate command is used to locate a file in a Linux system, just like the search command in Windows. 

Intermediate Commands


1. echo — The "echo" command helps us move some data, usually text into a file. For example, if you want to create a new text file or add to an already made text file, you just need to type in, “echo hello, my name is alok >> new.txt”. 

2. cat — Use the cat command to display the contents of a file. It is usually used to easily view programs.

3. nano, vi, jed — nano and vi are already installed text editors in the Linux command line. The nano command is a good text editor that denotes keywords with color and can recognize most languages. And vi is simpler than nano.You can create a new file or modify a file using this editor. For example, if you need to make a new file named "check.txt", you can create it by using the command “nano check.txt”.

4. sudo —  A widely used command in the Linux command line, sudo stands for "SuperUser Do". So, if you want any command to be done with administrative or root privileges, you can use the sudo command. For example, if you want to edit a file like viz. alsa-base.conf, which needs root permissions, you can use the command – sudo nano alsa-base.conf. You can enter the root command line using the command “sudo bash”, then type in your user password. 

5. df — Use the df command to see the available disk space in each of the partitions in your system. You can just type in df in the command line and you can see each mounted partition and their used/available space in % and in KBs. If you want it shown in megabytes, you can use the command “df -m”.

6. du — Use du to know the disk usage of a file in your system. If you want to know the disk usage for a particular folder or file in Linux, you can type in the command df and the name of the folder or file. For example, if you want to know the disk space used by the documents folder in Linux, you can use the command “du Documents”. You can also use the command “ls -lah” to view the file sizes of all the files in a folder.

7. tar — Use tar to work with tarballs (or files compressed in a tarball archive) in the Linux command line. It has a long list of uses. It can be used to compress and uncompress different types of tar archives like .tar, .tar.gz, .tar.bz2,etc. It works on the basis of the arguments given to it. For example, "tar -cvf" for creating a .tar archive, -xvf to untar a tar archive, -tvf to list the contents of the archive, etc. Since it is a wide topic, here are some examples of tar commands.
8. zip, unzip — Use zip to compress files into a zip archive, and unzip to extract files from a zip archive.
9. uname — Use uname to show the information about the system your Linux distro is running. Using the command “uname -a” prints most of the information about the system. This prints the kernel release date, version, processor type, etc.
10. apt-get — Use apt to work with packages in the Linux command line. Use apt-get to install packages. This requires root privileges, so use the sudocommand with it. For example, if you want to install the text editor jed (as I mentioned earlier), we can type in the command “sudo apt-get install jed”. Similarly, any packages can be installed like this. It is good to update your repository each time you try to install a new package. You can do that by typing “sudo apt-get update”. You can upgrade the system by typing “sudo apt-get upgrade”. We can also upgrade the distro by typing “sudo apt-get dist-upgrade”. The command “apt-cache search” is used to search for a package. If you want to search for one, you can type in “apt-cache search jed”(this doesn't require root).

11. chmod — Use chmod to make a file executable and to change the permissions granted to it in Linux. Imagine you have a python code named numbers.py in your computer. You'll need to run “python numbers.py” every time you need to run it. Instead of that, when you make it executable, you'll just need to run “numbers.py” in the terminal to run the file. To make a file executable, you can use the command “chmod +x numbers.py” in this case. You can use “chmod 755 numbers.py” to give it root permissions or “sudo chmod +x numbers.py” for root executable. Here is some more information about the chmod command.
12. hostname — It displays your hostname and IP address. Just typing “hostname”gives the output. Type “hostname -I” gives you your IP address in your network.

13. ping — Use ping to check your connection to a server.  Simply, when you type for example, “ping google.com”, it checks if it can connect to the server and come back.

Sunday, 18 February 2018

How to create plugin in wordpress

How to create plugin in wordpress this very easy if you have some knowledge og php language. Now in this tutorial, you’ll learn how to create a complete WordPress plugin. The main reason to create a plugin is that it allows you to separate your code from the core code of WordPress. If anything will be wrong in your plugin, the rest of the site will run continue with same functionalty.

Step1. First of all create a folder and then create a single file with one line of content.
Folder Location  /wp-content/plugins/awtplugin
Create a file named awtplugin.php. Open the file in a text editor, and paste the following information.
<?php
   /*
   Plugin Name: Advanced Web Tutorial
   Plugin URI: http://advancedwebtutorial.com
   description: Create AWT and spread joy
   Version: 1.1
   Author: Mr. Atul Sharma
   Author URI: https://plus.google.com/u/0/112051757095691606029
   License: GPL2
   */
?>
Only the plugin’s name is required. But if you intend to distribute your plugin, 
you should add as much data as possible. 
 
WordPress offers three great hooks to help you take care of this:
  • register_activation_hook() This hook allows you to create a function that runs when your plugin is activated. It takes the path to your main plugin file as the first argument, and the function that you want to run as the second argument. You can use this to check the version of your plugin, do some upgrades between versions, check for the correct PHP version and so on.
  • register_deactivation_hook() The name says it all. This function works like its counterpart above, but it runs whenever your plugin is deactivated. I suggest using the next function when deleting data; use this one just for general housekeeping.
  • register_uninstall_hook() This function runs when the website administrator deletes your plugin in WordPress’ back end. This is a great way to remove data that has been lying around, such as
Step 2 :

/**
 * Adds a view to the post being viewed
 *
 * Finds the current views of a post and adds one to it by updating
 * the postmeta. The meta key used is "awtpop_views".
 *
 * @global object $post The post object
 * @return integer $new_views The number of views the post has
 *
 */
function awtpop_add_view() {
   if(is_single()) {
      global $post;
      $current_views = get_post_meta($post->ID, "awtpop_views", true);
      if(!isset($current_views) OR empty($current_views) OR !is_numeric($current_views) ) {
         $current_views = 0;
      }
      $new_views = $current_views + 1;
      update_post_meta($post->ID, "awtpop_views", $new_views);
      return $new_views;
   }
}

add_action("wp_head", "awtpop_add_view");

 /**
 * Retrieve the number of views for a post
 *
 * Finds the current views for a post, returning 0 if there are none
 *
 * @global object $post The post object
 * @return integer $current_views The number of views the post has
 *
 */
function awtpop_get_view_count() {
   global $post;
   $current_views = get_post_meta($post->ID, "awtpop_views", true);
   if(!isset($current_views) OR empty($current_views) OR !is_numeric($current_views) ) {
      $current_views = 0;
   }

   return $current_views;
}

/**
 * Displays a list of posts ordered by popularity
 *
 * Shows a simple list of post titles ordered by their view count
 *
 * @param integer $post_count The number of posts to show
 *
 */
 function awtpop_popularity_list($post_count = 10) {
  $args = array(
    "posts_per_page" => 10,
    "post_type" => "post",
    "post_status" => "publish",
    "meta_key" => "awtpop_views",
    "orderby" => "meta_value_num",
    "order" => "DESC"
  );

  $awtpop_list = new WP_Query($args);

  if($awtpop_list->have_posts()) { echo "<ul>"; }

  while ( $awtpop_list->have_posts() ) : $awtpop_list->the_post();
    echo '<li><a href="'.get_permalink($post->ID).'">'.the_title('', '', false).'</a></li>';
  endwhile;

  if($awtpop_list->have_posts()) { echo "</ul>";}
 }


 

Saturday, 10 February 2018

how to get all share link of dropbox folder

Dropbox

Request and response formats

In general, the Dropbox API uses HTTP POST requests with JSON arguments and JSON responses. Request authentication is via OAuth 2.0 using the Authorization request header or authorization URL parameter.


/*// Step 1. For Call HTTP Autherization .
https://www.dropbox.com/oauth2/authorize?client_id=XXXXXXXXX&response_type=token&state=ahometech&require_role=personal&disable_signup=false&force_reauthentication=false&redirect_uri=http://localhost/mydropbox/xyz.php

After that you will get this responce
http://localhost/mydropbox/list.php#access_token=wGRn6y-Q5kAAAAAAAAAAKB3okg7UNewre-UAjwPOu2opZNv1NXQp-N9dZK_032B_&token_type=bearer&state=ahometech&uid=729287204&account_id=dbid%3AAAAQnPFMxiNicQYa-1fVYKYp9HgwKa-JZOY

// Step 2. This local Path is set in my API http://localhost/mydropbox/xyz.php
// Step 3.  You can use according to your need */




// List contents of home directory

    if(isset($_GET["access_token"])&& !empty($_GET["access_token"])){

    $auth_token = $_GET["access_token"];
    $root_path = '/math/';
    // create curl resource
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/files/list_folder");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $auth_token, 'Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('path'=> $root_path,'recursive'=> true,'include_media_info'=> false,'include_deleted'=> false,'include_has_explicit_shared_members'=> false,'include_mounted_folders'=> true)));
    $result = curl_exec($ch);
    //print_r($result);
    $array = json_decode(trim($result), TRUE);
    //echo "<pre>";print_r($array);exit;
    curl_close($ch);
    }

Sunday, 12 November 2017

Validating field with tooltip validation

When using FormValidation with some server-side frameworks such as CakePHPSymfonyRailsSpring, etc, there is a relationship between the model name and the attributename of input.
For example, assuming that a user is modeled by classUser withfirstNamelastName usernameemails[] properties.


git set up command

=========== Use GIT command ==========

>> sudo mkdir foldername
>> cd foldername/
>> git init
>> git remote add origin https://github.com/abc/project.git 


>> git fetch   
[ User : git-user-name , Pwd : git-pwd ]
>> git pull origin HEAD:Branch      [ User , Pwd ]
>> git add file_name.php
>> git commit -m "comment for add file"
>> git push origin HEAD:Branch     [ User , Pwd ]


>> git remote set-url origin https://git-user-name@github.com/abc/project.git    (For Setting Github User)

=============Add sql file in Xamp in ubuntu ===========

/opt/lampp/bin/php start
/opt/lampp/bin/mysql start

/opt/lampp/bin/mysql -h localhost -u root -p

use DatabseName; 
source /home/atul/Downloads/xyz.sql
==============Edit for file permission in wordpress ===============
find /path/to/your/wordpress/install/ a
find /path/to/your/wordpress/install/ -type f -exec chmod 644 {} \;
================== Add IP on host =================

sudo gedit /etc/hostname /etc/hosts
cd /etc
sudo gedit host

====================

Wednesday, 16 November 2016

basic commad of svn

find . -type d -name .svn -print0 | xargs -0 rm -rf          /* remove the svn folder from project */

svn co http://192.168.4.10/project_path     /* svn checkout */

svn ci -m 'commit'            /* commit the project */

svn up            /* update fron svn  */

svn st            /* check file in the project project which are not committed */

svn add *       /* add new file */

svn ci -m 'commit'            /* commit the project */

svn ci -m 'ciommit' folder_name/filename.php /* commit folder and file */

vim filename.php               /* for open file in online server */

i                        /* inset for online */

:wq!                   /* save and exit from file */
:q!          /* without save exit */

svn mkdir folder_name    /* Create folder name */

chmod -R 777 folder_name/       /* change folder permision */

mysql -u username -p database_name < file_name.sql    /* import database in mysql */

Tuesday, 11 August 2015

how to remove index.php from url in magento

1) Log-in to your Magento administration area then go to 'System > Configuration > Web'.
2) Navigate to the 'Unsecure' and 'Secure' tabs. Make sure the 'Unsecured' and 'Secure' - 'Base Url' options have your domain name within it, and do not leave the forward slash off at the end of the URL. Example: http://www.yourdomain.co.uk/
3) While still on the 'Web' page, navigate to 'Search Engine Optimisation' tab and select 'YES' underneath the 'Use Web Server Rewrites' option.
4) Navigate to the 'Secure' tab again (if not already on it) and select 'Yes' on the 'Use Secure URLs in Frontend' option.
5) NoW go to the root of your Magento website folder and use this code for your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Save the .htaccess and replace the original file. (PLEASE MAKE SURE TO BACKUP YOUR ORIGINAL .htaccess FILE BEFORE MESSING WITH IT!!!)
6) Now go to 'System > Cache Management'     refresh


logout  and enjoy.

Sunday, 9 August 2015

how to save div content as image using jquery

html2canvas

This script allows you to take "screenshots" of webpages or parts of it, directly on the users browser. The screenshot is based on the DOM and as such may not be 100% accurate to the real representation as it does not make an actual screenshot, but builds the screenshot based on the information available on the page.
Learn more »