Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, 2 July 2017

ShellScript-2

                                                              ShellScript

The below script uses variable to read the input from command prompt and display it.Here echo is print statement. Used to print the text. Comments will be written using #. Comments are not excutable .while reading a variable $ symbol is not required but when printing $ symbol is required.
[dhoni@server1 ~]$ vi read.sh

vi read.sh

#!/bin/bash
echo "Who are you give your name"
read person
echo Hai "$person"

[dhoni@server1 ~]$ chmod +x test2.sh

[dhoni@server1 ~]$ ./test2.sh
Who are you give your name
kiran(prompt asks input from  the keyboard)
Hai kiran
------------------------------------------------------------------------------------
-> Script to read the varible and display it. Here  first i give sachin  for name variable then i use sehwag  for the name variable. Sachin name is override by sehwag.

[dhoni@server1 ~]$ vi read1.sh
#!/bin/bash
echo "The name is"
Name="Sachin"

echo "$Name"
Name="Sehwag"
echo "$Name"

[dhoni@server1 ~]$ chmod +x read1.sh

[dhoni@server1 ~]$ ./read1.sh

The name is
Sachin
Sehwag
-----------------------------------------------------------------------------------------------
Readonly variables
--> script to read the variables.Here we use readonly variable. once value intialized the value can not be changed entire the script.First sachin is intialized to name then trying to intialize sehwag to the same variable. so it shows error becuase Name is readonly variable 

[dhoni@server1 ~]$ vi read2.sh
#!/bin/bash
echo "The name is"
Name="Sachin"
readonly Name
echo "$Name"
Name="Sehwag"
echo "$Name"

[dhoni@server1 ~]$ chmod +x read2.sh

[dhoni@server1 ~]$ ./read2.sh
The name is
Sachin
./read.sh: line 6: Name: readonly variable
Sachin
----------------------------------------------------------------------------------------
-->Script to  add the numbers using arithamatic operators.It will read two numbers from the command prompt and it will do following operations.To do arithamatic operations we use a program called expr in linux .

echo "Addition of  $a+$b is" `expr $a + $b`

in above line echo  for printing and

`expr $a +$b`

For every arithamatic operation we should write expr in linux. expr should be written inside ``(accent graves).and we should give space between each variable  and operator also.

[dhoni@server1 ~]$ vi add.sh

#!/bin/bash
echo "Enter The numbers to do Arithamatic Operations "
read a
read b
#c=`expr $a + $b`
echo "Addition of  $a+$b is" `expr $a + $b`
echo "Substraction is $a-$b is " `expr $a - $b`
echo "Multiplication is $a*$b is " `expr $a \* $b`
echo "Division  is $a/$b is " `expr $a / $b`
echo "Modular is $a%$b is " `expr $a %  $b`

[dhoni@server1 ~]$ chmod +x add.sh

[dhoni@server1 ~]$ ./add.sh

Enter The numbers to do Arithamatic Operations
6
3
Addition of  6+3 is 9
Substraction is 6-3 is  3
Multiplication is 6*3 is  18
Division  is 6/3 is  2
Modular is 6%3 is  0
--------------------------------------------------------------------------------
-->Script to demonstrate array.
Array is used to store large amount of data of same data type. Array values can accessed using index value.index value starts from ''0".To acces array we should use index number as follow.

This helps assign a value to one of its indices.
array_name[index]=value

Here array_name is the name of the array, index is the index of the item

Accessing Array Values

After you have set any array variable, you access it as follows −

${array_name[index]}


Below example having array called name.it contains 4 values.To display array contents we use 
echo ${name[3]}  --> Displays index 3 value

To display all index values we can use any one from below

echo ${name[*]}
echo ${name[@]}

[dhoni@server1 ~]$vi array.sh


#!/bin/bash
name[0]="a"
name[1]="b"
name[2]="c"
name[3]="d"
echo ${name[3]}
echo ${name[*]}
echo ${name[@]}


[dhoni@server1 ~]$ chmod +x array.sh

[dhoni@server1 ~]$ ./array.sh
d
a b c d
a b c d

If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team

Saturday, 1 July 2017

Linux-7(ShellScript-1)


                                                                  Vi Editor

There are many ways to edit files in Unix. Editing files using the screen-oriented text editor vi is one of the best ways. This editor enables you to edit lines in context with other lines in the file.
An improved version of the vi editor which is called the VIM.we can use the vi editor to edit an existing file or to create a new file from scratch.we can also use this editor to just read a text file.

vi filename  --> Creates a new file if it already does not exist, otherwise opens an
existing file.
vi -R filename--> Opens an existing file in the read-only mode.
view filename-->  Opens an existing file in the read-only mode.

Vi editor available in two modes −
 Command mode − to perform administrative tasks such as saving the files, executing the commands, moving the cursor, cutting (yanking) and pasting the lines or words, as well as finding and replacing. In this mode, whatever you type is interpreted as a command.

 Insert mode − to insert text into the file. Everything that's typed in this mode is interpreted as input and placed in the file. 
vi always starts in the command mode. To enter text, you must be in the insert mode for which simply type i. To come out of the insert mode, press the Esc key, which will take you back to the command mode.
Shortcuts to the Editor

Esc+i  =To insert the text into the file

Esc+yy =To copy the single line

Esc+2yy = To copy the two lines, place the cursor at starting position

Esc+p =To Paste the copied text

Esc+dd = To delete the line

Esc+2dd = To delete the 2 lines.place the cursor at starting position.

Alt+u = Undo the changes.

Esc+Shift+wq: -To Save and quit

The command to quit out of vi is :q


[dhoni@server1 ~]$vi example

Hai this is example file.In this i am typing some info.

To view contents of any file

[dhoni@server1 ~]$more example

Shell Script:

The prompt, $, which is called the command prompt, is issued by the shell. While the prompt is displayed, you can type a command.Shell reads your input after you press Enter. It determines the command you want executed by looking at the first word of your input. A word is an unbroken set of characters.Spaces and tabs separate words.Following is a simple example of the date command, which displays the current date and time:
$date
Thu Jun 25 08:30:19 MST 2009


In Unix, there are two major types of shells:

 Bourne shell — If you are using a Bourne-type shell, the $ character is the default
prompt.

 C shell — If you are using a C-type shell, the % character is the default prompt.

Shell Scripts

The basic concept of a shell script is a list of commands, which are listed in the order of
execution. A good shell script will have comments, preceded by # sign, describing the
steps. we create a test.sh script. Note all the scripts would have the .sh extension.
Before you add anything else to your script, you need to alert the system that a shell script
is being started. This is done using the shebang construct. For example

#!/bin/sh
This tells the system that the commands that follow are to be executed by the Bourne
shell. It's called a shebang because the # symbol is called a hash, and the ! symbol is
called a bang. To create a script containing these commands, you put the shebang line first and then add the commands −

#!/bin/bash
pwd
ls

[dhoni@server1 ~]$ vi test.sh
#!/bin/bash
pwd
ls

Then give +x permission to the script. To make script excutable.

[dhoni@server1 ~]$ chmod +x test.sh


[dhoni@server1 ~]$ ./test.sh
/home/dhoni
add.sh  array.sh  read.sh  test2.sh  test.sh

If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team


Linux-6

                                             Commands to know Linux System Information  

à To display System information
uname (short for unix name) is a computer program in Unix and Unix-like computer operating systems that prints the name, version and other details about the current machine and the operating system running on it.
The -a (i.e., all) option tells uname to provide the following information: the name of the kernel, network node host name (e.g., localhost.localdomain), kernel version number and release level (e.g., 2.4.20-6), kernel release date, machine hardware name, CPU (central processing unit) type, hardware platform and operating system name (e.g., GNU/Linux).

[root@server1 ~]# uname -a
Linux server1.abc.com 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Options are available to allow each of these pieces of information to be reported individually: -s for kernel name (i.e., the default action), -n for network node host name, -r for kernel version number and release level, -v for date of release of the kernel version, -m for machine hardware name, -p for CPU type (not available on some systems), -i for general hardware platform and -o for operating system.
àTo Display Kernal information
[root@server1 ~]# uname -r
2.6.32-573.el6.x86_64

àTo Display which version of redhat is installed
[root@server1 ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)

àShows how long system is running+load
[root@server1 ~]# uptime
 08:38:53 up 1 day, 13:06,  1 user,  load average: 0.08, 0.02, 0.01

 A FQDN consists of a short host name and the DNS domain name.You can change the FQDN and the DNS domain name (which is part of the FQDN) in the /etc/hosts file.The FQDN (Fully Qualified Domain Name) of the system is the name that the resolver returns for the host name, such as mysubdomain.example.com. It is usually the hostname followed by the DNS domain name (the part after the first dot). You can check the FQDN using hostname --fqdn or the domain name using dnsdomainname.

You cannot change the FQDN with hostname or dnsdomainname.
àTo display the hostname
[root@server1 ~]# hostname
server1.abc.com

àto display the ip address
[root@server1 ~]# hostname -i
192.168.33.10

àUse the ‘last reboot’ command, which will display all the previous reboot date and time for the system. This picks the information from the /var/log/wtmp file.To display the reboot history
[root@server1 ~]# last reboot
reboot   system boot  2.6.32-573.el6.x Mon Jun 26 15:49 - 08:39 (4+16:49)
reboot   system boot  2.6.32-573.el6.x Mon Jun 26 15:31 - 15:44  (00:12)

àDate command is helpful to display date in several formats. It also allows you to set systems date and time.to display the date
 [root@server1 ~]# date

Sat Jul  1 08:39:23 UTC 2017

Friday, 30 June 2017

Linux-5

                                                          Linux Commands

When dealing with the Linux operating system, commands are required as inputs to inform or direct a computer program to perform a specific operation. Understanding the most basic Linux commands will allow you to successfully navigate directories, manipulate files, change permissions, display information such as disk space, and more. Obtaining basic knowledge of the most common commands will help you easily execute tasks via the command line.


[root@server1 dhoni]# ls –ll file1

-rwxrwxrwx. 1 dhoni dhoni   18 Jun 30 05:11 file1

àThe chown command is used to change the owner and group of files, directories and links. ... new_owner is the user name or the numeric user ID (UID) of the new owner, and object is the name of the target file, directory or link. The ownership of any number of objects can be changed simultaneously.

Chown user:group filename

 [root@server1 dhoni]# chown root:root file1
[root@server1 dhoni]# ls –ll file1
-rwxrwxrwx. 1 root  root    18 Jun 30 05:11 file1



àtouch is a standard Unix command-line interface program which is used to update the access date and / or modification date of a file or directory. In its default usage, it is the equivalent of creating or opening a file and saving it without any change to the file contents

[root@server1 ~]# touch file22

àThe cat (short for “concatenate“) command is one of the most frequently used command in Linux/Unix like operating systems. cat command allows us to create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files.Then press ctrl+d to stop

[root@server1 ~]# cat> file22

Hai this is information for you

àto show the file contents.

[root@server1 ~]# cat file22

Hai this is information for you

àto store data into variable like var1 stores  text as hai 

[dhoni@server1 ~]$ var1="hai"


à to display the var content use $ symbol and echo to print the content

[dhoni@server1 ~]$ echo $var1

Hai

àBy default most Linux distro displays hostname and current working directory. You can easily customize your prompt to display information . 
Prompt is control via a special shell variable. You need to set PS1, PS2, PS3 and PS4 variable. If set, the value is executed as a command prior to issuing each primary prompt.
PS1 – The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is \s-\v\$ .
PS2 – The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is >
PS3 – The value of this parameter is used as the prompt for the select command
PS4 – The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +

# now the $ changed to =>

[dhoni@server1 ~]$ PS1='=>'

=>

=>

àto change prompt test as follows

Here

u for username

h for host name

t  for time

[dhoni@server1]=>PS1='[\u@\h \t]$'


àto display the date use the below command

[dhoni@server1 09:02:13 Fri Jun 30]$date

Fri Jun 30 09:02:19 UTC 2017

àto display the calendar for the month use the following command

[dhoni@server1 09:02:19 Fri Jun 30]$cal

      June 2017
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30


àlook here incomplete echo statement will display > symbol in second line after we press enter until 

it closes properly.

 [dhoni@server1]$echo "hai

> kdk

> ldldl"

hai

kdk

ldldl


à to change the symbol ‘>’ to ‘–‘ use the following command with PS2

[dhoni@server1]$PS2='-'

[dhoni@server1]$echo hai

-how

- are you“

Hai

How

are you.


à to change to ‘>’ follow below

[dhoni@server1]$PS2='>’

[dhoni@server1]$echo "ggg
>g
>hgg"
ggg
g
hgg


à Grep command is used to search for a file using pattern maching as below

Here iam searching for file having Jun characters in it

[dhoni@server1]$ls -l | grep "Jun"

drwx------. 4 dhoni   dhoni   4096 Jun 30 07:15 dhoni

drwx------. 5 test    test    4096 Jun 18 16:31 test

drwx------. 2 test2   test2   4096 Jun 30 07:23 test2



If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team

Thursday, 29 June 2017

Linux-4

                                                             The Unix File System
A filesystem is the methods and data structures that an operating system uses to keep track of files on a disk or partition; that is, the way the files are organized on the disk. The word is also used to refer to a partition or disk that is used to store thefiles or the type of the filesystem.

A file system is a group of files and relevant information regarding them.The disk space alloted to a unix file system is madeup of 'blocks'.
The Boot Block:
This represents the beginning of the file system. It contains a program called 'bootstrap loader'. This program is executed when we 'boot the host machine.only one block is needed to start up the system, all file systems contain one boot block.
The Super Block:
The super block describes the state of the file system-how large it is how many maximum files can it accomodate, how many more files can be created.
The Inode Table:
All the entities in unix system are treated as files. The information related to all these files is stored in an Inode Table on the disk.The Detailes will be
·         Owner of the file
·         Group to which the owner belongs
·         Type of the file
·         File access permissions
·         Date and time  of the last acces
·         Number of links to the file
·         Size of the file
·         Address of the block Where the file actually present.
Data Blocks:
These contains the actual  file contents. An allocated block belong to one file in the file system. This block cannot be used  for storing any other  files contents.
How Does unix acces a file:
Internally a file is identified by the inode number.we can obtain inode number as follows.
[dhoni@server1 ~]$ ls -i ckt.txt
915756 ckt.txt

# To  check disk Free space
[dhoni@server1 ~]$ df
Filesystem           1K-blocks     Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      39645804   866232  36759016   3% /
tmpfs                   251020        0    251020   0% /dev/shm
/dev/sda1               487652    29789    432263   7% /boot
vagrant              218488828 69148548 149340280  32% /vagrant
# To check disk usage
[dhoni@server1 ~]$ du
4       ./dir1
4       ./best
32      .

To set the user limit when creating a file
[dhoni@server1 ~]$ ulimit

unlimited

Key directories in the file system:
  • */: Root directory (base of file system)
  • /bin: Executable programs
  • /boot: Linux kernel and boot loader
  • /dev: Special device files
  • /etc: System configuration files
  • /home: Home directories of all users
  • /lib: Library files for programs
  • /media: Mount points for CD-ROM and other media
  • /root: Home directory of the root user
  • */sbin: System administration commands
  • /srv: Data for services such as Web and FTP
  • */tmp: Temporary directory
  • /usr: Many of the important administration programs
  • /var: Various system files, such as logs


Wednesday, 28 June 2017

Linux-3(bc)


Let we go a littile deeper into the Linux

We have a option like bc (best calucaltor) which provides good way of caluculations
using linux .Below i did some mathematical calculations.The Linux program bc can be used as a convenient desktop calculator. For interactive use you simply type "bc" at the command prompt in a terminal window and start typing arithmetic expressions.
When performing a series of calculations repeatedly it makes sense to use the bc calculator as part of a script.To open the calculator type bc. Exit from calculator type exit.
à
[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
10/2
5
11*32
352
quit

à
[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
45544*96556
4397546464
32+35+356+

3323
3323
quit

à
[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
10.23+1
11.23
scale=1(Here Scale option is used to restrict the precision points for float values)
10.23+2
12.23
quit

àto find the square root

[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
sqrt(25)
5
quit

à
To execute the logic
[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
for(i=0;i<10;i++)i
0
1
2
3
4
5
6
7
8
9
quit
Shows the login name

à
[dhoni@server1 ~]$ logname
vagrant

Shows the id of the user

à
[dhoni@server1 ~]$ id
uid=502(dhoni) gid=502(dhoni) groups=502(dhoni) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

à
[dhoni@server1 ~]$ uname
Linux

à
[dhoni@server1 ~]$ uname --help
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type or "unknown"
  -i, --hardware-platform  print the hardware platform or "unknown"
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit

Report uname bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'uname invocation'

[dhoni@server1 ~]$ uname -i
x86_64
[dhoni@server1 ~]$ uname -m
x86_64
[dhoni@server1 ~]$ uname -p
x86_64
[dhoni@server1 ~]$ uname -o
GNU/Linux
[dhoni@server1 ~]$ uname -n
server1.abc.com
[dhoni@server1 ~]$ uname -v
#1 SMP Thu Jul 23 15:44:03 UTC 2015

àThe tty command will display the file name of the terminal connected to
standard input i.e. the name of the current terminal. It displays not a
tty message if standard input is not a terminal.

[dhoni@server1 ~]$ tty
/dev/pts/0
#Tells the date

[dhoni@server1 ~]$ date
Wed Jun 28 16:36:10 UTC 2017

àWe can cusomize it as follow
[dhoni@server1 ~]$ date '+DATE: %d-%m-%y %n TIME: %H:%M:%S'
DATE: 28-06-17
 TIME: 16:39:13

[dhoni@server1 ~]$ date '+D: %d-%m-%y'
D: 28-06-17



If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team


Linux-2(File Permissions)

                                                           File permissions



Permission Groups

Each file and directory has three user based permission groups:
owner - The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
group - The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
all users - The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.

Permission Types
Each file or directory has three basic permission types:
read - The Read permission refers to a user's capability to read the contents of the file.
write - The Write permissions refer to a user's capability to write or modify a file or directory.
execute - The Execute permission affects a user's capability to execute a file or view the contents of a directory.

Viewing the Permissions
You can view the permissions by checking the file or directory permissions in your favorite GUI File Manager (which I will not cover here) or by reviewing the output of the \"ls -l\" command while in the terminal and while working in the directory which contains the file or folder.

The permission in the command line is displayed as: _rwxrwxrwx 1 owner:group

User rights/Permissions
The first character that I marked with an underscore is the special permission flag that can vary.
The following set of three characters (rwx) is for the owner permissions.
The second set of three characters (rwx) is for the Group permissions.
The third set of three characters (rwx) is for the All Users permissions.
Following that grouping since the integer/number displays the number of hardlinks to the file.
The last piece is the Owner and Group assignment formatted as Owner:Group.

Modifying the Permissions
When in the command line, the permissions are edited by using the command chmod. You can assign the permissions explicitly or by using a binary reference as described below.
Explicitly Defining Permissions

To explicity define permissions you will need to reference the Permission Group and Permission Types.

The Permission Groups used are:
u - Owner
g - Group
o - Others
a - All users

The potential Assignment Operators are + (plus) and - (minus); these are used to tell the system whether to add or remove the specific permissions.

The Permission Types that are used are:
r - Read
w - Write
x - Execute

So for an example, lets say I have a file named file1 that currently has the permissions set to _rw_rw_rw, which means that the owner, group and all users have read and write permission. Now we want to remove the read and write permissions from the all users group.

To make this modification you would invoke the command: chmod a-rw file1
To add the permissions above you would invoke the command: chmod a+rw file1

Every Permission has a value
read --4
write --2
execute --1

Default permission for file is 666
Default permission for directory is 777
When you create a file it will contains 3 types of users to access it they are

-rw-rw-r--. 1 dhoni dhoni 281 Jun 27 10:31 ckt.txt
 ---|---|---
owner|group|allusers

Each one have rwx permissions

when we create  a file using root then the file permissions will be 644.
Because here we having umask value 022 for root account.when you create file using
root this umask value will be deducted from the default file permissiosn that is(666-022=644)
644 stands(rw-r--r--).

when we create a file using normal user then the file permissions will be 664.
Because here we having umask value 002 for normal user account.when you create file using
normal user this umask value will be deducted from the default file permissiosn that is(666-002=664)
664 stands(rw-rw-r--).

à the below command will remove read permission for group,other users of dir1

[dhoni@server1 ~]$ chmod go-r dir1
[dhoni@server1 ~]$ ls
ckt.txt  dir1
[dhoni@server1 ~]$ ls -la ckt.txt

drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

àThe below command add write permissions whereever it require
[dhoni@server1 ~]$ chmod +w ckt.txt
[dhoni@server1 ~]$ ls -la

-rw-rw-r--. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

[dhoni@server1 ~]$ chmod +x ckt.txt
[dhoni@server1 ~]$ ls -la

-rwxrwxr-x. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

àThis will give write permission to the others
and removes execute permissions for group and others

[dhoni@server1 ~]$ chmod go-x,o+w ckt.txt

[dhoni@server1 ~]$ ls -la

-rwxrw-rw-. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

[dhoni@server1 ~]$ chmod g+x,o+w ckt.txt

[dhoni@server1 ~]$ ls -la

-rwxrwxrw-. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

[dhoni@server1 ~]$ ls -la ckt.txt
-rwxrwxrw-. 1 dhoni dhoni 281 Jun 27 10:31 ckt.txt

[dhoni@server1 ~]$ chmod g-x,o+x ckt.txt

[dhoni@server1 ~]$ ls -la ckt.txt
-rwxrw-rwx. 1 dhoni dhoni 281 Jun 27 10:31 ckt.txt

[dhoni@server1 ~]$ chmod u-r,g-x,o+x ckt.txt

[dhoni@server1 ~]$ ls -la

--wxrw-rwx. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

# Here another way to give permissions
 below command we gave permissions as 762(4+2+1,4+2,2)
stands for (user(rwx),group(rw),other(w))

[dhoni@server1 ~]$ chmod 762 ckt.txt

[dhoni@server1 ~]$ ls -la
-rwxrw--w-. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

[dhoni@server1 ~]$ touch sample

[dhoni@server1 ~]$ ls -la sample
-rw-rw-r--. 1 dhoni dhoni 0 Jun 27 12:20 sample

àShows the present working directory

[dhoni@server1 ~]$ pwd
/home/dhoni

àTo Exit from the present user account
[dhoni@server1 ~]$ exit
exit
[root@server1 ~]# su dhoni
[dhoni@server1 root]$ cd
[dhoni@server1 ~]$ ls
ckt.txt  dir1  sample

To check the umask value normal user

[dhoni@server1 ~]$ umask
0002
[dhoni@server1 ~]$ exit
exit
àThe umask value of root user

[root@server1 ~]# umask
0022
[root@server1 ~]# su dhoni

[dhoni@server1 ~]$ umask
0002
àTo change the umask value

[dhoni@server1 ~]$ umask 242

[dhoni@server1 ~]$ umask
0242
à now create a file it will be created with changed permissions like(666-242=424)
i.e -r---w-r--
[dhoni@server1 ~]$ touch sample2

[dhoni@server1 ~]$ ls -la sample2
-r---w-r--. 1 dhoni dhoni 0 Jun 27 12:26 sample2

àif you remove execute permission to the directory you can not list its contents

[dhoni@server1 ~]$ chmod u-x dir1

[dhoni@server1 ~]$ ls -la dir1
ls: cannot access dir1/..: Permission denied
ls: cannot access dir1/.: Permission denied
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..

[dhoni@server1 ~]$ chmod u+x dir1
[dhoni@server1 ~]$ ls -la dir1
total 8
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 .
drwx------. 3 dhoni dhoni 4096 Jun 27 12:26 ..
[dhoni@server1 ~]$ ls -la

àTo remove the file or directory use rm command

Here -rf option because to remove the file recursive and forcefully.

[dhoni@server1 ~]$ rm -rf sample2
[dhoni@server1 ~]$ ls -la

-rwxrw--w-. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1
-rw-rw-r--. 1 dhoni dhoni    0 Jun 27 12:20 sample

àls command having different options try it

[dhoni@server1 ~]$ ls -i
915756 ckt.txt  915755 dir1  915757 sample

[dhoni@server1 ~]$ ls -s
total 8
4 ckt.txt  4 dir1  0 sample
[dhoni@server1 ~]$ ls -r
sample  dir1  ckt.txt

If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team

Linux-1

Linux is Mulituser Operating system.
It is open-source, free, has a variety of options regarding distributions, and you can be in full control of how you use your computer’s memory; as well as your entire graphic interface, also known as X.
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.

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.
Moreover, it is less vulnerable to viruses and cyber-attacks.
In many ways, Linux is similar to other operating systems you may have used before, such as Windows, OS X, or iOS. Like other operating systems, Linux has a graphical interface, and types of software you are accustomed to using on other operating systems, such as word processing applications, have Linux equivalents. In many cases, the software’s creator may have made a Linux version of the same program you use on other systems. If you can use a computer or other electronic device, you can use Linux.

But Linux also is different from other operating systems in many important ways. First, and perhaps most importantly, Linux is open source software. The code used to create Linux is free and available to the public to view, edit, and—for users with the appropriate skills—to contribute to.

Linux is also different in that, although the core pieces of the Linux operating system are generally common, there are many distributions of Linux, which include different software options. This means that Linux is incredibly customizable, because not just applications, such as word processors and web browsers, can be swapped out. Linux users also can choose core components, such as which system displays graphics, and other user-interface components.
Here you will found basic commands.Slowly we will move to advance  level to shell script  also.

Login using Vagrant Vm
login as: vagrant
vagrant@127.0.0.1's password:
Last login: Mon Jun 26 11:55:23 2017 from 10.0.2.2

[vagrant@server1 ~]$ sudo su

[root@server1 vagrant]# cd

àadding user with useradd command.Linux has a super user account by default it is root user with this account we can create users and install the packages and do all the things which an admin can do in normal windows system.
[root@server1 ~]# useradd dhoni
[root@server1 ~]# passwd dhoni
Changing password for user dhoni.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

àGiving Sudo permission using visudo file.Above i had created a user name dhoni i am giving sudo permissions so he can do some admin level work when require.

[root@server1 ~]# visudo

àNow i would like to change the user account as dhoni so i can do using su command.It is nothing but switch user account.

[root@server1 ~]# su dhoni

àchange directory command.This command is used to change the present directory to another directory or file
[dhoni@server1 root]$ cd

àDisplays a list of files.This command displays the all the files which were in that directory.
[dhoni@server1 ~]$ ls

àTo open a create a file with vi editor.Write some text.This is like notepad in our windows operating system.
[dhoni@server1 ~]$ vi cricket

[dhoni@server1 ~]$ ls
cricket

à To Rename file cricket to ckt.txt we use  mv command.

[dhoni@server1 ~]$ mv cricket ckt.txt

àNow check using ls command to know wheater the file changes or not.
[dhoni@server1 ~]$ ls
ckt.txt

#ls -la Shows hidden files
# The file starts with . Known as hidden file
# file starts with d known as directory
# file starts with - known as file

[dhoni@server1 ~]$ ls -la
total 24
drwx------. 2 dhoni dhoni 4096 Jun 27 10:35 .
drwxr-xr-x. 7 root  root  4096 Jun 27 10:11 ..
-rw-r--r--. 1 dhoni dhoni   18 Jul 23  2015 .bash_logout
-rw-r--r--. 1 dhoni dhoni  176 Jul 23  2015 .bash_profile
-rw-r--r--. 1 dhoni dhoni  124 Jul 23  2015 .bashrc
-rw-rw-r--. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt

àWho am i Tells the present user detailes logged in.
[dhoni@server1 ~]$ who am i
vagrant  pts/0        2017-06-27 08:25 (10.0.2.2)

àWho command tells the same as above.
[dhoni@server1 ~]$ who
vagrant  pts/0        2017-06-27 08:25 (10.0.2.2)

àmkdir used to make directory Here i am creating dir1.

[dhoni@server1 ~]$ mkdir dir1

[dhoni@server1 ~]$ ls
ckt.txt  dir1

[dhoni@server1 ~]$ cd dir1

[dhoni@server1 dir1]$ ls

[dhoni@server1 dir1]$ ls -la
total 8
drwxrwxr-x. 2 dhoni dhoni 4096 Jun 27 12:05 .
drwx------. 3 dhoni dhoni 4096 Jun 27 12:05 ..

[dhoni@server1 dir1]$ cd

[dhoni@server1 ~]$ ls -la
total 28
drwx------. 3 dhoni dhoni 4096 Jun 27 12:05 .
drwxr-xr-x. 7 root  root  4096 Jun 27 10:11 ..
-rw-r--r--. 1 dhoni dhoni   18 Jul 23  2015 .bash_logout
-rw-r--r--. 1 dhoni dhoni  176 Jul 23  2015 .bash_profile
-rw-r--r--. 1 dhoni dhoni  124 Jul 23  2015 .bashrc
-rw-rw-r--. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwxrwxr-x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

àTo find out specific file detailes use following command.

[dhoni@server1 ~]$ ls -la ckt.txt
-rw-rw-r--. 1 dhoni dhoni 281 Jun 27 10:31 ckt.txt



If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team