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


No comments:

Post a Comment