Tuesday, 21 April 2015

Unix Commands Interview Questions and Answers for beginner

Unix Commands Interview Questions and Answers for beginner


Question: How to create shell script file?
Follow the simple steps to create first shell script file.
1. Login to putty console with your username/password.
2. Now go inside directory where you want to create the shell script files.
3. type following command to create text file.
vi test1
Now, you are in vi editor mode.
4. Type following script inside editor.
echo "Hello World"

5. Now get out of this vi editor using :wq
6. Now execute your file.
sh test1
7.It should print "Hello World" in output


Question: How can I concatenate two string variables in shell script file?
a="Hello World,"
b=" How r u?"
c=$a$b;
echo $c;#Hello World, How r u?



Question: Give me few examples of Grep command?
Example 1: Search text in file.
grep  "Hello" test.txt

"Hello" -is text, which you want to search.
test.text -It is file where u r searching.

Example 2:Search text in multiple files.
grep "Hello" test_*

"Hello" -is text, which you want to search.
test_* -It means search in all the files which start with test_

Example 3:Search text in file with insensitive.
grep -i "Hello" test.txt
"Hello" -is text, which you want to search.
test_* -It means search in all the files which start with test_

Example 4: Search text recursively in all files.
grep -r "Hello" *
-r: It is option used to search recursively in all sub folder.
"Hello" -is text, which you want to search.
* -Search in all current directory



Question: How to get all cron job for all users?
create empty text file and add following code in that file.
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done
Now, just execute the file
sh filename
It will list all the cron job for all user.


Question: What is difference between sh and bash?
Sh: Shell Command is a programming language described by the POSIX standard.
blash: In Starting, bash was also sh compatible but Now it is NOT due to in-valid POSIX shell.


Question: How can I "Reverse the order of lines" in a file?
tail -r text.txt



Question: How to download a file from SSH?
You can copy the file from server to another public directory, from there you can download with FTP/SFTP.
scp username@domain.edu:file.txt /path/to/dir

This command, put the file.txt to "path/to/dir", From this directory you can download.


Question: What is difference between Soft link and Hard link?
Soft Link: soft or symbolic is just a short cut to the original file. If we delete one or more soft link, nothing happens.
Hard link: It is multiple paths to the same file.


Question: How to set screen names with GNU screen?
screen -S foo



Question: How to get full path of a file?
readlink -f test.txt



Question: How to permanently set $PATH on Linux?
You need to add it to your ~/.profile file.
export PATH=$PATH:/path/to/directory



Question: How to list all the files/directory with permission?
 ls -l



Question: How to get the current folder path?
pwd



Question: How can I copy the output of a command directly into my clipboard?
cat file | xclip





Monday, 20 April 2015

Wordpress Interview Questions and Answers for experienced

Wordpress interview questions and answers experienced

Question: How to create a folder if it doesn't already exist in Wordpress?
$pathname='path/to/directory';
if (!file_exists($pathname)) {
    mkdir($pathname, 0777, true);
}

In mkdir have following 3 parameters.
Pathname: path where you want to create the folder
Folder Permission: Permission of folder.
Recursive: true for all sub directory, false for current directory only.


Question: What is difference between mode value 0777 and 777 in mkdir/chmod function?
In PHP, 0777 and 777 have same meaning and no difference.
When you are providing 4 digit in for permission, it means 1 digit will be used for sticky bit.
sticky bit is access right flag that can be assigned to files and directories on Unix-like systems.


Question: Where to place to insert the google analytics Code?
You should add "Google analytics code" in Every page, so that you can get all pages tracking report.
As per google, you should add "Google Analytics code" just before the closing of "head" for better results.
https://support.google.com/analytics/answer/1008080?hl=en

In wordpress, when we are using some theme for displaying your website. there might be textbox in admin section, to add the "Google Analytics" code for tracking purpose.(May OR may not available in your current theme)


Question: How to get the current page name in WordPress?
You can get the page name from below of two?
$slug = basename(get_permalink());
OR
$pagename = get_query_var('pagename');  



Question: How do I ge the version of wordpress?
echo bloginfo('version');
Above is get from below file.
You can check in wp-includes/version.php
$wp_version = '4.1.2';



Question: How to turn off the Notice/Warning from my wordpress website?
Open the wp-config.php file and WP_DEBUG set the false.
define('WP_DEBUG', false );


Question: What is use of __() and _e() functions in wordpress?
These are function used when you website multilingual.
each of this function have two parameter.
1st parameter: String which you want to convert from one language to another.
2nd parameter: domain name.
 $translatedText = __( 'TEXT_FOR_TRANSLATION', 'textdomain' ); //This will return the translated text
 _e( 'TEXT_FOR_TRANSLATION', 'textdomain' ); //This will print the translated text



Question: How to get wordpress post featured image URL?
if (has_post_thumbnail( $post->ID ) ){ 
  $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
  echo $image[0];//image url 
}



Question: How to get last inserted row id from wordpress database?
global $wpdb;
/** insert query here with $wpdb**/
/** insert query here with $wpdb**/
 $lastId = $wpdb->insert_id; //This is last insert id



Question: How to Remove P and Br tags in WordPress posts?
Open functions.php in your current active theme.
Add following lines

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

http://codex.wordpress.org/Function_Reference/wpautop




Question: How do I get current taxonomy "term id" on wordpress?
$obj = get_queried_object();
echo $obj->term_id;



Question: How do I add Syntax Highlighting on wordpress.com?
As you can't install plugin for syntax high lighting in wordpress.com, you can use existing syntax highligher.
[sourcecode language='python']

[/sourcecode]



Question: How to check admin login or Not?
if(is_admin()) { 
/** Write your code here */

/** Write your code here */
}



How to protect your website from DDos Attack?
Add following code in your .htaccess file.
<files xmlrpc.php>
      order allow,deny
      deny from all
    </files>