Basic Linux Commands – Part 3

By | February 24, 2018

Linux Basic to Advance commands continues. You can also refer part 1 and part 2. In this Post, we will be looking into the below commands.

  • ifconfig
  • ssh
  • alias
  • sleep
  • ping
  • time
  • hostname
  • pwd
  • exit
  • bc

1.  ifconfig

ifconfig is similar to ipconfig of windows. If a user wanted to see the IP address of the machine, he can use ifconfig command.

Ifconfig is used to configure the kernel-resident network interfaces. It is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed.

Sample Output:

[root@devopsage ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.31.23.202  netmask 255.255.240.0  broadcast 172.31.31.255
        inet6 fe80::444:86ff:fe19:7328  prefixlen 64  scopeid 0x20
        ether 06:44:86:19:73:28  txqueuelen 1000  (Ethernet)
        RX packets 15850  bytes 3930962 (3.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13755  bytes 2706460 (2.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 8  bytes 556 (556.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 556 (556.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

2.  ssh

ssh (secured shell) allows the user to take the access to the remote server or another Linux server in the same network. ssh is freely available for all the Unix based system. It is also used to login and execute certain commands on the remote machine. It is intended to provide secure encrypted communications between two untrusted hosts over an insecure network. The user must provide his identity to the remote machine using one of several methods depending on the protocol version used.

root@devopsage1:~# ssh [email protected]
[email protected]'s password: 
Last login: Sat Feb 24 08:36:06 2018 from localhost

[sampleuser2@devopsage ~]$ whoami
sampleuser2
[sampleuser2@devopsage ~]$

3. alias

alias command is used when you wanted to use another name for any command. take an example of ifconfig, which displays all the ethernet and ip adress of your machine. we can create our own command say, “ip” which will perform exactly the same as ifconfig. So here instead of typing 6 characters, the work will get done only in 2 characters.

[root@devopsage ~]# alias ip='ifconfig'

[root@devopsage ~]# ip   
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.31.23.202  netmask 255.255.240.0  broadcast 172.31.31.255
        inet6 fe80::444:86ff:fe19:7328  prefixlen 64  scopeid 0x20
        ether 06:44:86:19:73:28  txqueuelen 1000  (Ethernet)
        RX packets 17641  bytes 4357198 (4.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15282  bytes 3092042 (2.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 8  bytes 556 (556.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 556 (556.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@devopsage ~]# unalias ip  // to remove the alias

4. sleep

This command created a delay for a specific amount of time. It suspends all the executions on a particular terminal for the specific period of time. In simple words, terminal remains inactive for those many seconds.

[root@devopsage ~]# sleep 5   // terminal inactive for 5 sec
[root@devopsage ~]# sleep 1m  // terminal inactive for 1 minute
[root@devopsage ~]# sleep 1h  // terminal inactive for 1 hour
[root@devopsage ~]# sleep 1d  // terminal inactive for 1 day

5. ping

ping uses the ICMP protocol’s mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. In simple words, it tries to send some data to the given IP address and receive it. If the data is not received back in some time which states that the IP you are trying to ping is not reachable

ping command keeps on sending and receiving the data continuously, though you can kill it manually, you can also restrict it to a specific number of times.

[root@devopsage ~]# ping 172.31.27.124 //will ping continuously, until it is canceled manually
[root@devopsage ~]# ping -c2 172.31.27.124 // ping only for 2 times

6. time

time command can be used to determine the total time elapsed in executing any script or any command

[root@devopsage ~]# time sleep 3

real	0m3.002s
user	0m0.000s
sys	0m0.001s

[root@devopsage ~]# time bash script.sh

7. hostname

hostname shows the fully qualified domain name of the Linux machine.

[root@devopsage ~]# hostname
devopsage.example.com

8. pwd

pwd stands for present working directory. It displays the full length of present/current working directory. It is useful because it quickly determines where the user is working on the entire Linux filesystem.

[root@devopsage ~]# pwd
/root
[root@devopsage ~]#

9. exit

logout. simply exits you out of the session. shortcut for exit command is ctrl+d. sample output is shown below.

[root@devopsage ~]# exit
logout
[testuser@devopsage ~]$

10.  bc

In Linux, bc is basically a command line calculator which performs simple mathematics calculations.

root@devopsage1:~# 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'. 
100*100
10000

Note: If this command is not installed on your Linux machine, then you can install it by using any package manager.

  • For Redhat/CentOs: # yum install bc
  • For Ubuntu/Debian: # apt-get install bc
  • To come out of the calculator use, ctrl+d

Leave a Reply

Your email address will not be published. Required fields are marked *