Wednesday 30 January 2019

enable and disable command in Linux

Linux Study Materials, LPI Guides, LPI Certification, LPI Tutorial and Materials

Enables and disables are the built-in shell commands. enable command is used to start the printers or classes whereas the disable command is used to stop the the printers or classes.

Syntax For enable Command:


enable [-a] [-dnps] [-f filename][name ...]

Syntax For disable Command:


disable [-c] [-W] [ -r [ reason ] ] printer


Options:


◈ -a : List all builtins with the message of whether it is enabled or not.
◈ -c : It will cancel the requests which are currently printing.
◈ -d : Delete a builtin loaded with `-f’.
◈ -W : Wait until the request currently being printed is finished before disabling printer. This option cannot be used with the -c option. If the printer is remote then the -W option will be silently ignored.
◈ -r reason : It assigns a reason for the disabling of the printer(s).
◈ printer : The name of the printer to be enabled or disabled.
◈ -n: Disable the names listed, otherwise names are enabled.

Saturday 19 January 2019

Some useful Linux Hacks

Linux is the best-known and most-used open source operating system. As an operating system, Linux is software that sits underneath all of the other software on a computer, receiving requests from those programs and relaying these requests to the computer’s hardware.

Linux Command, Linux Tutorial and Material, LPI Guides, LPI Certification

For the purposes of this page, we use the term “Linux” to refer to the Linux kernel, but also the set of programs, tools, and services that are typically bundled together with the Linux kernel to provide all of the necessary components of a fully functional operating system. Some people, particularly members of the Free Software Foundation, refer to this collection as GNU/Linux, because many of the tools included are GNU components. However, not all Linux installations use GNU components as a part of their operating system. Android, for example, uses a Linux kernel but relies very little on GNU tools.

Here are some of my favorites LINUX HACKS (in no particular order) :

1. Paste Code: Directly paste any code/text into terminal use Ctrl + Shift + v

2. Sharing Server:  You can make a quick HTTP server for sharing in Python 2 using following command:

python -m SimpleHTTPServer

3. Increase Speaker Volume: Increase the maximum volume of your speakers by a certain percentage (150 in this case) :

pactl set-sink-volume 0 150%

4. Fortune Messages: Make your terminal output you random fortune messages. On a ubuntu system do:

sudo apt-get install fortune

and add fortune to the last line of your .bashrc if you are using Bash (default in my linux distros ). If you love cows then you can install cowsay pipe the output of fortune to cowsay , add following line to the end of your .bashrc

fortune | cowsay

5. Starwars: Want to watch StarWars in terminal ? Just type:
telnet towel.blinkenlights.nl

6. Shorten Lengthy Command: Have a lengthy command and want to short it down ? Use aliases
Add all aliases to your .bashrc so that they remain permanent. Like we used sudo apt-get install to install packages we can slim it done by defining an alias in our bashrc like

alias install = 'sudo apt-get install'

After saving the file and restarting the terminal you can do things like

install cowsay fortune figlet

instead of typing

sudo apt-get install fortune figlet cowsay

You can do it for many commands with the syntax  alias short-name=’long command’.

# Notice there is no space between long command and equal sign ( = ) Plus some commands are pre-aliased like la is an alias for ls -a. You can this out by typing la in your terminal .

7. Ping and traceroute together: Want to ping and traceroute/tracert at the same time. Use mtr
Install it with

sudo apt-get install mtr

or if you aliased the command use install mtr .
Usage mtr

8. Download files: Want to download files with a specific pattern like:

File1 at http://example.com/files/file1.zip
File2 at http://example.com/files/file2.zip
Use wget ( comes pre-installed on most distros ) as following

wget Page on example.com

Wget can be used for crawling and other awesome automated stuff.

9. Download accelerator: Want a stable download accelerator use axel?
Install with sudo apt-get install axel
use as follows

axel -a

10. Enable Scroll lock: Scroll Lock is disabled by default in Linux Distros. Even though the Scroll Lock doesn’t serve much of a purpose in the modern day applications. But still we might need it for some purposes like toggling the back light on our illuminated keyboards. To enable scroll lock

xmodmap -e 'add mod3 = Scroll_Lock' link

11. Download files using the command line : This one is pretty common. wget is used to download files using the command line via HTP, HTTPS and FTP.

wget file.link
where file.link is the link from where the file has to be downloaded.

12. Download YouTube videos: You can also download YouTube videos straight from the command line using a package by the name of youtube-dl. First install the package using apt-get or pip

sudo apt-get install youtube-dl
OR
sudo pip install youtube-dl

Your package is ready to be used. You can now use it to download videos

youtube-dl Youtube-link

13. Change terminal look and feel: If you want to edit the way your terminal looks, or the font sizes and other features. You have two options. gsettings or dconf. In layman terms gsettings uses the command line whereas dconf uses a GUI called dconf-editor. First we need to install dconf.

sudo apt-get install dconf-tools
dconf-editor

14. Be a bond: You want to look like a badass hacker ? (Kind of)

Install hollywood, your terminal will split and look like you’re doing a lot of cool things

sudo apt-add-repository ppa:hollywood/ppa
sudo apt-get update
sudo apt-get install hollywood
sudo apt-get install byobu #Used to split your terminal, very useful

Launch byobu then hollywood (just type byobu and hollywood)

15. Current Weather: What about the knowing the current weather of any city around the world.

In your terminal, just type:

curl http://wttr.in/your_city_name

and voila, weather for next 3 days displayed elegantly in your terminal.

16. Same command at same time: Want to run a command you ran yesterday at a point of time?

Try Ctrl-R(recursive search) and then type a subset of characters in your command and boom you accessed a recent history without pressing key many times.

Thursday 17 January 2019

diff command in Linux with examples

diff stands for difference. This command is used to display the differences in the files by comparing the files line by line. Unlike its fellow members, cmp and comm, it tells us which lines in one file have is to be changed to make the two files identical.

diff Command, Linux Tutorial and Materials, LPI Study Materials, LPI Guides

The important thing to remember is that diff uses certain special symbols and instructions that are required to make two files identical. It tells you the instructions on how to change the first file to make it match the second file.

Special symbols are:

a : add
c : change
d : delete

Syntax :

diff [options] File1 File2

Lets say we have two files with names a.txt and b.txt containing 5 Indian states.

$ ls
a.txt  b.txt

$ cat a.txt
Gujarat
Uttar Pradesh
Kolkata
Bihar
Jammu and Kashmir

$ cat b.txt
Tamil Nadu
Gujarat
Andhra Pradesh
Bihar
Uttar pradesh

Now, applying diff command without any option we get the following output:

$ diff a.txt b.txt
0a1
> Tamil Nadu
2,3c3
< Uttar Pradesh
 Andhra Pradesh
5c5
 Uttar pradesh

Let’s take a look at what this output means. The first line of the diff output will contain:

◈ Line numbers corresponding to the first file,
◈ A special symbol and
◈ Line numbers corresponding to the second file.

Like in our case, 0a1 which means after lines 0(at the very beginning of file) you have to add Tamil Nadu to match the second file line number 1. It then tells us what those lines are in each file preceeded by the symbol:

◈ Lines preceded by a < are lines from the first file.
◈ Lines preceded by > are lines from the second file.
◈ Next line contains 2,3c3 which means from line 2 to line 3 in the first file needs to be changed to match line number 3 in the second file. It then tells us those lines with the above symbols.
◈ The three dashes (“—“) merely separate the lines of file 1 and file 2.

As a summary to make both the files identical, first add Tamil Nadu in the first file at very beginning to match line 1 of second file after that change line 2 and 3 of first file i.e. Uttar Pradesh and Kolkata with line 3 of second file i.e. Andhra Pradesh. After that change line 5 of first file i.e. Jammu and Kashmir with line 5 of second file i.e. Uttar pradesh.

Now let’s see what it looks like when diff tells us that we need to delete a line.

$ cat a.txt
Gujarat
Andhra Pradesh
Telangana
Bihar
Uttar pradesh

$ cat b.txt
Gujarat
Andhra Pradesh
Bihar
Uttar pradesh

$ diff a.txt b.txt
3d2
< Telangana

Here above output 3d2 means delete line 3rd of first file i.e. Telangana so that both the files sync up at line 2.

Options


diff Command, Linux Tutorial and Materials, LPI Study Materials, LPI Guides
Linux system offers two different ways to view the diff command output i.e. context mode and unified mode.

1. -c (context) : To view differences in context mode, use the -c option. Lets try to understand this with example, we have two files file1.txt and file2.txt:

$ cat file1.txt                                                                                                                           
cat                                                                                                                                             
mv                                                                                                                                             
comm                                                                                                                                           
cp

$ cat file2.txt
cat                                                                                                                                             
cp                                                                                                                                             
diff                                                                                                                                           
comm
                                                                                                 
$ diff -c file1.txt file2.txt                                                                                                             
*** file1.txt   Thu Jan 11 08:52:37 2018                                                                                                       
--- file2.txt   Thu Jan 11 08:53:01 2018                                                                                                       
***************                                                                                                                                 
*** 1,4 ****                                                                                                                                   
  cat                                                                                                                                           
- mv                                                                                                                                           
- comm                                                                                                                                         
  cp                                                                                                                                           
--- 1,4 ----                                                                                                                                   
  cat                                                                                                                                           
  cp                                                                                                                                           
+ diff                                                                                                                                         
+ comm

The first file is indicated by ***, and the second file is indicated by —.
The line with *************** is just a separator.

The first two lines of this output show us information about file 1 and file 2. It lists the file name, modification date, and modification time of each of our files, one per line.

The next line has three asterisks *** followed by a line range from the first file (in our case lines 1 through 4, separated by a comma). Then four asterisks ****. After that it shows the contents of the first file with the following indicators:

(i) If the line needs to be unchanged, it is prefixed by two spaces.
(ii) If the line needs to be changed, it is prefixed by an symbol and a space. The symbol means are as follows:

(a) + : It indicates a line in the second file that needs to be added to the first file to make them identical.
(b) – : It indicates a line in the first file that needs to be deleted to make them identical.

Like in our case, it is needed to delete mv and comm from first file and add diff and comm to the first file to make both of them identical.

After that there are three dashes — followed by a line range from the second file (in our case lines 1 through 4, separated by a comma). Then four dashes —-. Then it shows the contents of the second file.

2. -u (unified) : To view differences in unified mode, use the -u option. It is similar to context mode but it doesn’t display any redundant information or it shows the information in concise form.

$ cat file1.txt                                                                                                                           
cat                                                                                                                                             
mv                                                                                                                                             
comm                                                                                                                                           
cp

$ cat file2.txt                                                                                                                           
cat                                                                                                                                             
cp                                                                                                                                             
diff                                                                                                                                           
comm

$ diff -u file1.txt file2.txt                                                                                                           
--- file1.txt   2018-01-11 10:39:38.237464052 +0000                                                                                             
+++ file2.txt   2018-01-11 10:40:00.323423021 +0000                                                                                             
@@ -1,4 +1,4 @@                                                                                                                                 
 cat                                                                                                                                           
-mv                                                                                                                                             
-comm                                                                                                                                           
 cp                                                                                                                                             
+diff                                                                                                                                           
+comm

The first file is indicated by —, and the second file is indicated by +++.
The first two lines of this output show us information about file 1 and file 2. It lists the file name, modification date, and modification time of each of our files, one per line.

After that the next line has two at sign @ followed by a line range from the first file (in our case lines 1 through 4, separated by a comma) prefixed by – and then space and then again followed by a line range from the second file prefixed by + and at the end two at sign @. Followed by the file content in output tells us which line remain unchanged and which lines needs to added or deleted(indicated by symbols) in the file 1 to make it identical to file 2.

3. -i : By default this command is case sensitive. To make this command case in-sensitive use -i option with diff.

$ cat file1.txt
dog
mv
CP
comm

$ cat file2.txt
DOG
cp
diff
comm

Without using this option:
$ diff file1.txt file2.txt
1,3c1,3
< dog
< mv
 DOG
> cp
> diff

Using this option:
$ diff -i file1.txt file2.txt
2d1
 diff

4. –version : This option is used to display the version of diff which is currently running on your system.

$ diff --version
diff (GNU diffutils) 3.5
Packaged by Cygwin (3.5-2)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Friday 11 January 2019

dos2unix and unix2dos commands

Sometimes, you will need to move files between windows and unix systems. Window files use the same format as Dos, where the end of line is signified by two characters, Carriage Return or CR or \r followed by Line Feed or LF or \n.

dos2unix, unix2dos commands, LPI Gudies, LPI Learning, LPI Tutorial and Material

Unix files, on the other hand, use only Line Feed (\n).

unix2dos is a tool to convert line breaks in a text file from Unix format (Line feed) to DOS format (carriage return + Line feed) and vice versa.

◈ dos2unix command : converts a DOS text file to UNIX format.
◈ Unix2dos command : converts a Unix text file to DOS format

Example


Task : Create a file in DOS or in notepad with following contents
hello everybody
welcome to unix
unix is easy

now copy this file in unix /home/lpi directory

$od –bc myfile.txt
0000000 150 145 154 154 157 040 145 166 145 162 171 142 157 144 171 015
          h   e   l   l   o       e   v   e   r   y   b   o   d   y  \r
0000020 012 167 145 154 143 157 155 145 040 164 157 040 165 156 151 170
         \n   w   e   l   c   o   m   e       t   o       u   n   i   x
0000040 015 012 165 156 151 170 040 151 163 040 145 141 163 171 015 012
         \r  \n   u   n   i   x       i   s       e   a   s   y  \r  \n
0000060

The CR-LF combination is represented by the octal values 015-012 and the escape sequence \r\n.

Note: The above output shows that this is a DOS format file.
Now convert DOS file to UNIX format by using dos2unix command

$dos2unix myfile.txt
$od –bc myfile.txt

Conversion of this file to UNIX is just a simple matter of removing the \r.
We can also convert UNIX file to DOS format by using unixsdos command

$unix2dos myfile.txt
$od –bc myfile.txt

After Conversion of this file to DOS, \r is added in DOS file.

Wednesday 9 January 2019

Different Shells in Linux

Shells in Linux, Linux Certification, Linux Tutorial and Material, Linux Study Materials

SHELL is a program which provides the interface between the user and an operating system. When the user logs in OS starts a shell for user. Kernel controls all essential computer operations, and provides the restriction to hardware access, coordinates all executing utilities, and manages Resources between process. Using kernel only user can access utilities provided by operating system.

Types of Shell:


◈ The C Shell –

Denoted as csh

Bill Joy created it at the University of California at Berkeley. It incorporated features such as aliases and command history. It includes helpful programming features like built-in arithmetic and C-like expression syntax.

In C shell:

Command full-path name is /bin/csh,
Non-root user default prompt is hostname %,
Root user default prompt is hostname #.

◈ The Bourne Shell –

Denoted as sh

It was written by Steve Bourne at AT&T Bell Labs. It is the original UNIX shell. It is faster and more preferred. It lacks features for interactive use like the ability to recall previous commands. It also lacks built-in arithmetic and logical expression handling. It is default shell for Solaris OS.

For the Bourne shell the:

Command full-path name is /bin/sh and /sbin/sh,
Non-root user default prompt is $,
Root user default prompt is #.

◈ The Korn Shell

It is denoted as ksh

It Was written by David Korn at AT&T Bell LabsIt is a superset of the Bourne shell.So it supports everything in the Bourne shell.It has interactive features. It includes features like built-in arithmetic and C-like arrays, functions, and string-manipulation facilities.It is faster than C shell. It is compatible with script written for C shell.

For the Korn shell the:

Command full-path name is /bin/ksh,
Non-root user default prompt is $,
Root user default prompt is #.

◈ GNU Bourne-Again Shell –

Denoted as bash

It is compatible to the Bourne shell. It includes features from Korn and Bourbe shell.

For the GNU Bourne-Again shell the:

Command full-path name is /bin/bash,
Default prompt for a non-root user is bash-g.gg$
(g.ggindicates the shell version number like bash-3.50$),
Root user default prompt is bash-g.gg#. 

Sunday 6 January 2019

Daily life Linux Commands

1. Clear the Terminal : In our daily life, we use to work on Terminal if we are using LINUX. Continuous working on terminal make terminal screen full with commands and for removing them and making our screen totally free of character, we often use clear command. Key combination ‘Ctrl+l‘ has the same effect as ‘clear‘ command. So from next time use ctrl+l to clear your Linux Command Line Interface.


Daily life Linux Commands, Linux Tutorial and Material, Linux Certification, Linux Guides

Note: Since ctrl+l is a key combination, so we can not use it inside a script. If we need to clear screen inside a shell script, we must have to call command ‘clear’.

2. Run command and get back to directory, together: This is also an amazing hack not known to many people. We may run a command no matter what it is and then return back to the current directory. For this, all we need to do is to run the command in parentheses i.e., in between ( and ).
For Example :

Input :

cd /home/shivam/Downloads/ && ls -l

Output :

-rw-r----- 1 shivam shivam    54272 May 3 18:37 text1.txt
-rw-r----- 1 shivam shivam    54272 May 3 18:37 text2.txt
-rw-r----- 1 shivam shivam    54272 May 3 18:37 text3.txt

Explanation : In the above command it first changed the current directory to Downloads and then list the content of that directory before returning back to the current directory.

3. Shortcut to Directories: You can create a shortcut to frequently accessed directories by adding them to the CDPATH environment variable. So, say If you frequently access “/var/www/html/”.
Instead of typing “cd /var/www/html”, you can add /var/www/ to CDPATH and then you have to type “cd html” only.
shivam:~> export CDPATH=$CDPATH:/var/www/
shivam:~> cd html
shivam:~:html>

4. Replacing words or characters:

◈ If you are working with any text file then to replace every instance of any word say “version” with “story” in myfile.txt, you can use sed command as:

# sed 's/version/story/g' myfile.txt

◈ Additionally, if you want to ignore character case then you may use gi instead of g as:

# sed 's/version/story/gi' myfile.txt

5. Here are some useful shortcuts which you may use while working on terminal:
Cursor Movement Control:

◈ Ctrl-a: Move cursor to the start of a line
◈ Ctrl-e: Move cursor to the end of a line
◈ Ctrl-Left/Right: Navigate word by word (may not work in all terminals)Modify Text:
◈ Ctrl-w: Delete the whole word to the left of the cursor
◈ Ctrl-k: Erase to end of line
◈ Ctrl-u: Erase to beginning of line

6. Run top in batch mode: ‘top’ is a handy utility for monitoring the utilization of your system. It is invoked from the command line and it works by displaying lots of useful information, including CPU and memory usage, the number of running processes, load, the top resource hitters, and other useful bits. By default, top refreshes its report every 3 seconds.
Mostly we run ‘top’ inside the terminal, look on the statistics for a few seconds and then graciously quit and continue our work.
Better yet, if we wants to run such a utility only for a given period of time, without any user interaction:

There are many possible answers:

◈ You could schedule a job via cron.
◈ You could run a shell script that runs ps every X seconds

Instead of going wild about trying to patch a script, there’s a much, much simpler solution:

top -b -d 10 -n 3 >> top-file

We have top running in batch mode (-b). It’s going to refresh every 10 seconds, as specified by the delay (-d) flag, for a total count of 3 iterations (-n). The output will be sent to a file.Here is a screenshots of outut:

Daily life Linux Commands, Linux Tutorial and Material, Linux Certification, Linux Guides

7. Duplicate pipe content: ‘tee’ is a very useful utility that duplicates pipe content. Now, what makes tee really useful is that it can append data to existing files, making it ideal for writing periodic log information to multiple files at once.

ps | tee file1 file2 file3

We’re sending the output of the ps command to three different files! Or as many as we want. As you can see in the screenshots below, all three files were created at the same time and they all contain the same data.

8. export: The ‘export’ command is one of the bash shell BUILTINS commands.It has three available command options. In general, it marks an environment variable to be exported with any newly forked child processes and thus it allows a child process to inherit all marked variables.
Frequently Used Options with ‘export’

◈ -p : List of all names that are exported in the current shell
◈ -n: Remove names from export list
◈ -f : Names are exported as functions

Example :

◈ command without ‘export’:

$ a = lpicentral.blogspot.com
$ echo $a
lpicentral.blogspot.com
$ bash
$ echo $a

From the above we can see that any new child process forked from a parent process by default does not inherit parent’s variables. This is where the export command comes handy.

$ a = lpicentral.blogspot.com
$ echo $a
lpicentral.blogspot.com$ export a
$ bash
$ echo $a
lpicentral.blogspot.com$

On line 3, we now have used the export command to make the variable “a” to be exported when a new child process is created. As a result the variable “a” still contains the string “lpicentral.blogspot.com” even after a new bash shell was created.

9. basename – Strips directory and suffix from filenames. basename prints NAME with any leading directory components removed. If Suffix is specified, it will also remove a trailing SUFFIX. For example: To get the name of the file present in test folder

$ basename test/gfg.txt
gfg.txt

10. grep: grep searches files for a given character string or pattern and can replace the string with another. This is one method of searching for files within Linux.

grep [option(s)] pattern [file(s)]

◈ Search number of files: grep can search any number of files simultaneously. Thus, for example, the following would search the three files file1, file2 and file3 for any line that contains the string GfG

grep GfG file1 file2 file3

◈ Search text in all files: To search all text files in the current directory (i.e., the directory in which the user is currently working), if there is a phrase “Linux is”

grep 'Linux is' *

There are lot of more options which can be tried using grep command.

Friday 4 January 2019

List of useful Github Commands

Github is a distributed version control system which helps to manage the repositories.

Github Commands, LPI Guides, LPI Study Materials, LPI Tutorial and Materials

These are a list of few commands that you can use frequently on github(git bash)

1.git help

Take help from github help section for different commands and other errors

2.git config

To set the basic configurations on github like your name and email.

3.git config –global user.name “xyz”

Sets configuration values for your user name on git.

4.git config –global user.email xyz01@gmail.com

Sets configuration values for your user email on git.

5.git config –global color.ui true

To see different colours on command line for different outputs.

6.mkdir store

Create a directory if not created initially.

7.cd store

To go inside the directory and work upon its contents.

8.git init

To create a local git repository for us in our store folder.This will help to manage the git commands for that particular repository.

9.git status

To see whats changed since last commit.It shows all the files that have been added and modified and ready to be commmitted and files which are untracked

10.git add Readme.txt

To add a file Readme.txt to the staging area to track its changes.

11.git commit -m “Created a Readme.txt”

To commit our changes(taking a snapshot) and providing a message to remember for future reference.

12.git log

To check the history of commits for our reference.

Different ways to use add command:


13.git add

To add a specific list of files to staging area.

14.git add --all

To add all files of current directory to staging area.

15.git add *.txt

To add all text files of the current directory to staging area.

16.git add docs/*.txt

To add all text files of a particular directory(docs) to staging area.

17.git add docs/

To add all files in a particular directory(docs) to staging area.

18.git add “*.txt”

To add text files of entire project to staging area.


More Commands:


19.git diff

To figure out what changes you made since last commit.

20.git reset head license

To undo staging of the file that was added in the staging area.

21.git checkout –license

To Blow away all changes since the last commit of the file.

22.git commit -a -m “Readme.md”

To add any of our tracked files to staging area and commit them by providing a message to remember.

23.git reset –soft HEAD^

To undo last commit and bring file to staging area.

24.git reset –hard HEAD^

To undo last commit and remove file from the staging area as well(In case we went horribly wrong).

25.git reset –hard HEAD^^

To undo last 2 commits and all changes.

26.git remote add origin https://github.com/madaan123/MyAlgorithms.git

This commands make a bookmark which signifies that this particular remote refers to this URL.

This remote will be used to pull any content from the directory and push our local content to the global server.

27.git remote add <address>

To add new remotes to our local repository for a particular git address.

28.git remove rm

To remove a remote from our local repository.

29.git push -u origin master

To push all the contents of our local repository that belong to master branch to the server(Global repository).

30.git clone https://github.com/xyz123/MyAlgorithms.git

Github Commands, LPI Guides, LPI Study Materials, LPI Tutorial and Materials

To clone or make a local copy of the global repository in your system
(git clone command downloads the repository and creates a remote named as origin which can be checked by command – git remote -v).

31.git branch Testing

To create a new branch named as Testing.

32.git branch

To see all the branches present and current branch that we are working on.

33.git checkout Testing

To switch to branch Testing from master branch.

34.ls

To see directories and files in the current directory.

35.git merge Testing

To merge Testing branch with master branch.

36.git branch -d Testing

To delete Testing branch.

37.git checkout -b admin

To create a new branch admin and set it as current branch.

38.git branch -r

To look at all the remote branches.

39.git branch -D Testing

To forcefully delete a branch without making commmits.

40.git tag

To see the list of available tags.

41.git checkout v0.0.1

To set the current tag to v0.0.1.

42.git tag -a v0.0.3 -m “version 0.0.3”

To create a new tag.

43.git push –tags

To push the tags to remote repository.

44.git fetch

To fetch down any changes from global repository to current repository

45.git rebase

Three tasks are performed by git rebase

1. Move all changes to master which are not in origin/master to a temporary area.

2. Run all origin master commits.

3. Run all commits in the temporary area on top of our master one at a time, so it avoids merge commits.

Wednesday 2 January 2019

Useful CMD commands for daily use in Windows OS

List of uncommon useful cmd commands are as follows:

1. Cipher:


Cipher.exe is a built-in command line tool in the Windows operating system that can be used to encrypt or decrypt data on NTFS drives. This tool also lets to securely delete data by overwriting it.
Cipher Switches:

◈ /? : Displays help at the command prompt.
◈ /e : Encrypts the specified folders. Folders are marked so that files that are added to the folder later are encrypted too.
◈ /d : Decrypts the specified folders. Folders are marked so that files that are added to the folder later are encrypted too.
◈ /w : PathName – Removes data on unused portions of a volume. PathName can indicate any directory on the desired volume.

Syntax:

cipher /w:c

This will wipe free space on the drive. The command does not overwrite undeleted data, so you will not wipe out files you need by running this command.

2. File compare:


File compare (or fc) is a great command line tool that can be used to compare files to see if there are any content or binary code differences that you can access if you are using a PC. It is a simple program that will compare the contents of text or binary files and is capable of comparing both ASCII and Unicode text. You can use this tool to display any lines from two files or two sets of files that do not match up with the others.

Switches:

◈ /b – This switch will perform a binary comparison.
◈ /c – If you need to do a case insensitive comparison, use this switch.
◈ /a – This switch will make FC show only the first and last lines for each group of differences.
◈ /u – Use this switch to compare files as Unicode text files.
◈ /l – This will compare your files as ASCII text.
◈ /n – This switch can only be used with ASCII but it will show all the corresponding line numbers.

Syntax:

Simply type “fc” and then the directory path and file name of the two files you want to compare.

fc [switches] [pathname1] [pathname2]


3. Tasklist:


In Windows, we can get the list of processes running on the system from command prompt also. We can use ‘tasklist‘ command for this purpose.
Using this command we can selectively list the processes based on criteria like the memory space used, running time, image file name, services running in the process etc.

Parameters:

◈ /s Computer : Specifies the name or IP address of a remote computer (do not use backslashes). The default is the local computer.
◈ /u Domain \ User : Runs the command with the account permissions of the user specified by User or Domain\User. The default is the permissions of the current logged on user on the computer issuing the command.
◈ /p Password : Specifies the password of the user account that is specified in the /u parameter.
◈ /fo { TABLE | LIST | CSV } : Specifies the format to use for the output. Valid values are TABLE, LIST, and CSV. The default format for output is TABLE.
◈ /nh : Suppresses column headers in the output. Valid when the /fo parameter is set to TABLE or CSV.
◈ /fi FilterName : Specifies the types of process(es) to include in or exclude from the query. The following table lists valid filter names, operators, and values.
◈ /svc : Lists all the service information for each process without truncation. Valid when the /fo parameter is set to TABLE. Cannot be used with the /m or the /v parameter.
◈ /v : Specifies that verbose task information be displayed in the output. Cannot be used with the /svc or the /m parameter.
◈ /m [ ModuleName ] : Specifies to show module information for each process. When a module is specified, all the processes using that module are shown. When a module is not specified, all the processes for all the modules are shown. Cannot be used with the /svc or the /v parameter.

Filters:

LPI Tutorial and Material, LPI Guides, LPI Study Material, LPI Certifications

Syntax:

 tasklist[.exe] [/s computer] [/u domain\user [/p password]] 
    [/fo {TABLE|LIST|CSV}] [/nh] [/fi FilterName [/fi FilterName2 
    [ ... ]]] [/m [ModuleName] | /svc | /v]   

Example:

tasklist /v /fi “PID gt 1000” /fo csv
tasklist /fi “USERNAME ne NT AUTHORITY\SYSTEM” /fi “STATUS eq running”
tasklist /v /fi “STATUS eq running”
tasklist /s srvmain /nh
tasklist /s srvmain /s srvny
tasklist /s srvmain /u maindom\hiropln /p p@ssW23 /nh

4. Taskkill:


Its sure that you are familiar with the traditional way to kill or end a process in Windows using Task Manager. This method is effective but not nearly as fun as killing a process in Command Prompt. Additionally, killing processes in Command Prompt provides much more control and the ability to end multiple processes at once.

Parameters:

◈ /s Computer : Specifies the name or IP address of a remote computer (do not use backslashes). The default is the local computer.
◈ /u Domain \ User : Runs the command with the account permissions of the user specified by User or Domain\User. The default is the permissions of the current logged on user on the computer issuing the command.
◈ /p Password : Specifies the password of the user account that is specified in the /u parameter.
◈ /fi FilterName : Specifies the types of process(es) to include in or exclude from termination. The following are valid filter names, operators, and values.
◈ /pid ProcessID : Specifies the process ID of the process to be terminated.
◈ /im ImageName : Specifies the image name of the process to be terminated. Use the wildcard (*) to specify all image names.
◈ /f : Specifies that process(es) be forcefully terminated. This parameter is ignored for remote processes; all remote processes are forcefully terminated.
◈ /t : Specifies to terminate all child processes along with the parent process, commonly known as a tree kill.

Filters:

LPI Tutorial and Material, LPI Guides, LPI Study Material, LPI Certifications

Syntax:

 taskkill [/s Computer] [/u Domain\User [/p Password]]] [/fi FilterName] 
  [/pid ProcessID]|[/im ImageName] [/f][/t] 

Examples:
C:\>taskkill /pid 26356 /f
C:\>taskkill /fi “USERNAME eq Pratik” /f
C:\>taskkill /s VictimsDesktop /u RemoteAccountName /p RemoteAccountPassword /im notepad.exe /f

5. System File Checker:


System File Checker is an automatic scan and repair tool that focuses on Windows system files. You will need to run the command prompt with administrator privileges and enter the command “sfc /scannow”. If any corrupt or missing files are found, they’ll be automatically replaced using cached copies kept by Windows for just that purpose. The command can require a half-hour to run on older notebooks.

Syntax:

sfc /scannow  

6. Driverquery:


Drivers remain among the most important software installed on a PC. Improperly configured or missing drivers can cause all sorts of trouble, so its good to have access to a list of what’s on your PC. That’s exactly what the “driverquery” command does. You can extend it to “driverquery -v” to obtain more information including the directory in which the driver is installed.

Parameters:

◈ /s Computer : Specifies the name or IP address of a remote computer (do not use backslashes). The default is the local computer.
◈ /u Domain \ User : Runs the command with the account permissions of the user specified by User or Domain\User. The default is the permissions of the current logged on user on the computer issuing the command.
◈ /p Password : Specifies the password of the user account that is specified in the /u parameter.
◈ /fo { TABLE | LIST | CSV } : Specifies the format to display the driver information. Valid values are TABLE, LIST, and CSV. The default format for output is TABLE.
◈ /nh : Omits the header row from the displayed driver information. Valid when the /fo parameter is set to TABLE or CSV.
◈ /v : Specifies that detailed driver information be displayed.
◈ /si : Displays digital signature information for both signed and unsigned device drivers.

Syntax:

 driverquery  [/s Computer] [/u Domain\User /p Password] 
   [/fo {TABLE|LIST|CSV}] [/nh] [/v] [/si]  

Examples:
driverquery
driverquery /fo csv
driverquery /nh
driverquery /s ipaddress