Linux Command mostly used in Software development [SSH]

Software Engineer have remembered some command which are mostly used for software development to make quick and easy manner if server system is Lenux based.

You have various choices for getting Secure Socket Shell SSH.

What is SSH?

SSH is widely used by network administrators for managing systems and applications remotely, allowing them to log in to another computer over a network, execute commands and move files from one computer to another.

You also get understand for navigate and work with files and database in SHH or Linux terminal.

 

ls Show directory contents (list the names of files).

Example:

you should list directory and file in this location.

prakash@pkbhandari.com [~]# ls

public_html  etc  tmp  logs

 

1: List Specified path files:

Example: ls <path/inner_path>

prakash@pkbhandari.com [~/public_html/sites/pk]# ls test_p
./  ../
prakash@pkbhandari.com [~/public_html/sites/pk]# ls pkb_files
./  ../  in_1/  new/  pkb_files/  pkb_files.txt  pk_zip.zip
prakash@pkbhandari.com [~/public_html/sites/pk]#

 

2. List all with hidden files:

Example: ls -a

3. List all with .dot files and hidden files:

Example: ls -all

 

4. See file and List all folder and files permission

@pkbhandari.com [~/public_html/sites/pk]# ls -lt
total 0
drwxr-xr-x  4 prakash group 54 Feb 10 13:13 ./
-rw-rw-r–  1 prakash group 0 Feb 10 13:13 pkb_file.txt
drwxrwxr-x  2 prakash group 6 Feb 10 12:55 test_p/
drwxr-xr-x  5 prakash group 80 Feb 10 12:31 pkb_files/
drwxr-xr-x. 6 prakash group 77 Feb 10 12:31 ../

folders : test_p,pkb_files

Files : pkb_file.txt

The bits we are interested in are drwxr-xr-x prakash and group

The d tells us that test is a directory. if without d it is file (pkb_file.txt).

The first three characters after the d are the owner permissions for the directory specified by the owner’s name.

  • r stands for read
  • w stands for write
  • x stands for execute (which in this case means you can access the folder)

 

Change Permission

To change the permissions for a file or folder you can use the chmod command. The chmod command lets you specify 3 numbers which set the permissions.
read permissions = 4
write permissions = 2
execute permissions = 1

To get a mixture of permissions you add the numbers together. For example to get read and execute permissions the number you need is 5, to get read and write permissions the number is 6 and to get write and execute permissions the number is 3.

Remember you need to specify 3 numbers as part of the chmod command. The first number is for the owner permissions, the second number is for the group permissions and the last number is for everyone else.

For example to get full permissions on the owner, read and execute permissions on the group and no permissions for anyone else type the following:

     chmod 750 test_p

 

 

cd Change Directory.

Example:

you should navigate the direction with folder name.

prakash@pkbhandari.com [~]# cd public_html

It will enter you in public_html folder.

 

mkdir Create a new folder (directory).

Syntax: mkdir <foldername>

Example:

prakash@pkbhandari.com [~/public_html/sites/pk]#mkdir pkb_test

it will create directory pkb_test in inside pk folder.

 

touch Create a new file.

 

rm Remove a file.
cat Show contents of a file.
pwd Show current directory (full path to where you are right now).
cp Copy file/folder.
mv Move file/folder.
grep Search for a specific phrase in file/lines.
find Search files and directories.
vi/nano Text editors.
history Show last 50 used commands.
clear Clear the terminal screen.
tar Create & Unpack compressed archives.
wget Download files from the internet.
du Get file size.

Read RSS feed in Php

We need external item to incorporate in website.

Here i have shared the method for read RSS feed using php.

 

RSS (Rich Site Summary; originally RDF Site Summary; often called Really Simple Syndication) is a type of web feed[2] which allows users to access updates to online content in a standardized, computer-readable format. These feeds can, for example, allow a user to keep track of many different websites in a single news aggregator. The news aggregator will automatically check the RSS feed for new content, allowing the content to be automatically passed from website to website or from website to user. This passing of content is called web syndication. Websites usually use RSS feeds to publish frequently updated information, such as blog entries, news headlines, audio, video. An RSS document (called “feed”, “web feed”,[3] or “channel”) includes full or summarized text, and metadata, like publishing date and author’s name.

 

<?php
//get the q parameter from URL
$xml=(“http://www.pkbhandari.com/feed/”);
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);//get elements from “<channel>”
$channel=$xmlDoc->getElementsByTagName(‘channel’)->item(0);
$channel_title = $channel->getElementsByTagName(‘title’)
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName(‘link’)
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName(‘description’)
->item(0)->childNodes->item(0)->nodeValue;

//output elements from “<channel>”
echo(“<p><a href='” . $channel_link
. “‘>” . $channel_title . “</a>”);
echo(“<br>”);
echo($channel_desc . “</p>”);

//get and output “<item>” elements
$x=$xmlDoc->getElementsByTagName(‘item’);
for ($i=0; $i<=2; $i++) {
$item_title=$x->item($i)->getElementsByTagName(‘title’)
->item(0)->childNodes->item(0)->nodeValue;
$item_link=$x->item($i)->getElementsByTagName(‘link’)
->item(0)->childNodes->item(0)->nodeValue;
$item_desc=$x->item($i)->getElementsByTagName(‘description’)
->item(0)->childNodes->item(0)->nodeValue;
echo (“<p><a href='” . $item_link
. “‘>” . $item_title . “</a>”);
echo (“<br>”);
echo ($item_desc . “</p>”);
}
?>

 

 

<script>
function showRSS(str) {
if (str.length==0) {
document.getElementById(“rssOutput”).innerHTML=””;
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {  // code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById(“rssOutput”).innerHTML=this.responseText;
}
}
xmlhttp.open(“GET”,”getrss.php?q=”+str,true);
xmlhttp.send();
}
</script>

Git Commands

Git Initialize

——————————

To initialize a git repository in the root of the folder, run the git init command: $ git init Commiting Specific file : what is commit command  $git add -A – $ git add <filename> [add specified file] – $git add -A [add all files in to repository] Show the changes status of file

 

————————————–

D:\ > $ git status  

D:\ > $ git status  :: Create a new branch::

——————————-

 

$ git checkout <my branch name>

$ git checkout -b <my branch name> [create new branch as name specified] ‘$ git checkout <my branch name>  [go to specified branch ] go back to master repository

 

—————————————

$ git checkout master 

$ git checkout master See whethere branch is created or not you can use the git branch command to confirm that your branch was created:

——————————————

$ git branch  

$ git branch

Create a new repository on GitHub

———————————-

create online repository in github site copy this repository link https://github.com/PrakashKumarBhandari/testproject.git See log

————————-

$git log $git log — graph [show log in graph]

$git log  push an existing repository from the command line’ section: into github site

————————————————————–

$ git remote add origin https://github.com/PrakashKumarBhandari/testproject.git push local repository master content in to online repository location :

 

——————————————-

Git Pull Fetch from and Integrate with another repository or a local branch.

$git pull [options] [<repository> [<refspec>…​]]

$git pull origin master

 

———————————————

Git Add changes (modified) local file

+++++++++++++++++++++++++++

Stage your changes

Git has a staging area, for files that you want to commit. On GitHub when you edit a file, you commit it as soon as you save it. On your machine, you can edit a number of files and commit them altogether.

Staging a file in Git’s terminology means adding it to the staging area, in preparation for a commit.

Add your amended file to the staging area:

$git add <filename>
Ex: $git add attendees_and_learners.rst


-----------------------------

Commit your changes

+++++++++++++++++++++++++++++
git commit -m "added my github name"

When you’re happy with your files, and have added the changes you want to commit to the staging area:

 

-----------------------------

Merge from branch

+++++++++++++++++++++++++++++

example branch is ratcv2 which is need to merge in to master branch.

1. Admin@Admin-PC MINGW64 /f/new (master)
$ git merge ratcv2

 

2. Admin@Admin-PC MINGW64 /f/new (master|MERGING)
$ git add -A

 

3. Admin@Admin-PC MINGW64 /f/new (master|MERGING)
$ git commit -m “download files – from branch”

this command will merge ratcv2 updates in to master if any conflict arises it has to be fixed before

……………………………………………..

Aborting Merge for branch:

—————————————

git merge –abort

 

 

—————————————–

 Push your changes to GitHub

++++++++++++++++++++++++

When you made a change on GitHub, it not only saved the change and committed the file at the same time, it also showed up right away in your GitHub repository. Here there is an extra step: we need to push the files to GitHub.

If you were pushing changes from master locally to master on GitHub, you could just issue the command git push and let Git work out what needs to go where.

It’s always better to be explicit though. What’s more, you have multiple branches here, so you need to tell git where to push (i.e. back to the remote repository you cloned from, on GitHub) and what exactly to push (your new branch).

The repository you cloned from – yours – can be referred to as origin. The new branch is called amend-my-name. So:

$ git push origin amend-my-name

 

$ git push -u origin master

$ git push -u origin master Push a branch to GitHub

———————————————

$ git push origin <yourbranchname>

$ git push origin master [ push in to master repo or we can push into created branch ]

Copy and Rename file


 

Installing and set up process of Laravel projects

+++++++++++++++++++++++++++++++++++++++++++++++

change .env.example file to .env file $ cp .env.example .env now set up you database connection configuration — of .env file DB_HOST=localhost DB_DATABASE=ribbon DB_USERNAME=root DB_PASSWORD= +++++++++++++++++++++++++++++++++++++

Run composer

 

———————————–

$ composer install

+++++++++++++++++++++++++++++++++++++++

Migrate Database

————————————-

$ php artisan migrate

++++++++++++++++++++++

Seed database : $php artisan db:seed

Create and Edit file using Vim editor

‘vim’ includes many features to edit files, Here i have share simplest way to create and edit file in vim editor in linux shell environment.
Using ‘vim’ to create and edit a file

#1  Log into your server via SSH.
#2 Navigate to the directory location you wish to create the file, or edit an existing file.

#3 Type in vim followed by the name of the file. For example, if you wish to create (or edit) a new file named test.html, run the following:

[server]$ vim test.txt

The 'vim' editor will appear but we must change file mode to insert text. 
[ confusing at first because you cannot type into the file yet:]


Click the letter 'i' on your keyboard to enter INSERT mode in 'vim'.
It now shows -- INSERT -- on the bottom left:

 

Now we  can add edit into file.

 

#4 When finished editing the file, click the ESC key.

This takes you out of INSERT mode and — INSERT — disappears from the bottom left of your terminal.

 

 

#5 To save the file, type in a colon followed by wq. For example:

:wq

 

#6 Click ‘Enter’ to save.

Mysql database connection and back up from ssh client


Log in to your Hosting account using SSH.

step 1: At the command line, type the following command, replacing USERNAME with your username:
mysql -u USERNAME -p

 

At the Enter Password prompt, type your password. When you type the correct password, the mysql> prompt appears.

 

To display a list of databases, type the following command at the mysql> prompt:

 

To access a specific database, type the following command at the mysql> prompt, replacing DBNAME with the database that you want to access:

 

mysql> Use holycros_drupal;

 

After you access a database, you can run SQL queries, list tables, and so on. Additionally:

  • To view a list of MySQL commands, type help at the mysql> prompt.
  • To exit the mysql program, type \q at the mysql> prompt.

 

 

 

Lets look at some of the other functions you can execute via SSH. If you want, for example, to move and copy a file to a different folder you need to type the following:

mv index.html /path/to/directory/index.html ( this command will move it)

cp index.html /path/to/directory/index.html  (this command will copy it)

Copying a whole folder is done using the -r option of the cp command. This will copy the whole folder recursively for example:

 

cp -r /path/to/folder /destination/path

The mv command can also be used to rename a file. For example:

mv index.html newindex.html

Note that unlike windows, Linux files are key sensitive, so if you are going to move or edit a file you must type the exact name.

 

 

Set up and installing laravel project

+++++++++++++++++++++++++++++++++++++++++++++++

Installing and set up process of Laravel projects

+++++++++++++++++++++++++++++++++++++++++++++++   ++++++++++++++++++++++++

Git Clone —————————————–

$git clone https://github.com/prakashkumarbhandari.git  

 

++++++++++++++++++++++++ Copy file with rename

—————————————–

change .env.example file to .env file $ cp .env.example .env now set up you database connection configuration — of .env file DB_HOST=localhost DB_DATABASE=ribbon DB_USERNAME=root DB_PASSWORD=

+++++++++++++++++++++++++++++++++++++

Run composer

—————————————————————

$ composer install    

 

+++++++++++++++++++++++++++++++++++++++

Migrate Database

——————————————————————-

$ php artisan migrate    

++++++++++++++++++++++

Seed database :

————————————-

$php artisan db:seed

Drupal Quick tab use

We can use quick tab inteface for durpal tabbed display content.

We may use node(contents or view or block content) on tabbed display.

https://www.drupal.org/node/679116