Skip to main content

Command Palette

Search for a command to run...

Linux Basic Chet Sheet 02

πŸ§πŸ’»πŸ“πŸŒˆπŸ“πŸš€πŸšπŸ§πŸŽ‚πŸ©πŸŒπŸ”πŸŒŸπŸŒπŸ’»πŸ§πŸ’»πŸ“πŸŒˆπŸ“πŸš€πŸšπŸ§πŸŽ‚πŸ©πŸŒ

Published
β€’8 min read
Linux Basic Chet Sheet 02

A Beginner's Guide to Use Basic Command in Ubuntu Linux.

Hey there! Welcome to this blog on Basic Command in Ubuntu 02 updated commands In this post, we'll explore some essential commands that can help you efficiently handle files and directories while playing with Ubuntu Linux. πŸ§πŸ’»πŸ“πŸŒˆ

ls -a

  • To View Hidden Files will use "ls -a" Check the below example which shows the difference between "ls" and "ls -a".
ubuntu@ip-172-31-167-241:~$ ls ----> Hidden Files not showing
devops.txt  file1.txt  file2.txt  file3.txt  file4.txt 
ubuntu@ip-172-31-167-241:~$ ls -a  ---> To View Hidden Files
.  ..  .bash_history  .bash_logout  .bashrc  .cache  .local  .profile  .ssh  .sudo_as_admin_successful  .viminfo  devops.txt  file1.txt  file2.txt  file3.txt  file4.txt

πŸ“ Text Editing: Commands

  • To create a fruits.txt file and content.
ubuntu@ip-172-31-117-6:~$ touch fruits.txt
  • To create an empty "fruits.txt" file using the touch command

  • To add some content to the "fruits.txt" file using the echo command. (Also added a command prompt snapshot below)

This command does a simple task. It writes the names of fruits to a file, with each fruit name on a new line.

The special -e option is used to make sure that when writing to the file, escape sequences like \n are interpreted as new lines.

ubuntu@ip-172-31-117-6:~$ echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > fruits.txt

To check what's inside the "fruits.txt" file, you can use the cat command. It will show you all the fruit names written in the file, one after the other.

This command will display the contents of the file in the terminal. The fruit names should be listed on separate lines as shown in the below snapshot.

  • Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
echo "Apple" > devops.txt 
echo "Mango" >> devops.txt 
echo "Banana" >> devops.txt 
echo "Cherry" >> devops.txt 
echo "Kiwi" >> devops.txt 
echo "Orange" >> devops.txt 
echo "Guava" >> devops.txt

The first command creates a new file called devops.txt and writes the string "Apple" to it. The \> symbol is used to redirect the output of the echo command to the file devops.txt.

The second to seventh commands append the strings "Mango", "Banana", "Cherry", "Kiwi", "Orange", and "Guava" to the end of the file devops.txt, respectively.

The \>> symbol is used to append the output of the echo command to the end of the file.

Now, if you run the cat command to display the contents of the devops.txt file, you will see: As shown in the below snapshot.

  • Show only the top three fruits from the file.

show only the top three fruits from the devops.txt file, you can use the head command with the -n option.

ubuntu@ip-172-31-117-6:~$ head -n 3 devops.txt
Apple
Mango
Banana

  • To Show only the bottom three fruits from the file.

To show only the bottom three fruits from the devops.txt file, you can use the tail command with the -n option.

ubuntu@ip-172-31-117-6:~$ tail -n 3 devops.txt
Kiwi
Orange
Guava


  • To create another file Colors.txt and to view the content.

  • Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.

I used here vom editor and manually added all the colors on the text file each line

ubuntu@ip-172-31-117-6:~$ touch colors.txt
ubuntu@ip-172-31-117-6:~$ ls
colors.txt  devops.txt  fruits.txt
ubuntu@ip-172-31-117-6:~$ vim colors.txt

  • If you run the cat command again to display the contents of the Colors.txt file, you will see in below snapshot.


  • To find the difference between fruits.txt and Colors.txt files.

To find the difference between the fruits.txt and Colors.txt files, you can use the diff command.

ubuntu@ip-172-31-117-6:~$ diff fruits.txt colors.txt
1,5c1,5
< Apple
< Mango
< Banana
< Cherry
< Kiwi
---
> Red
> Pink
> White
> Black
> Blue
7c7,8
< Guava
---
> Purple
> Greay

If there are differences between the two files, the output will show the lines that are different between the two files. The output will look something like this:


What is Shell Scripting πŸ’»for DevOps πŸš€

As per my understanding 🧠 Shell Scripting for DevOps is a way to automate and streamline various tasks and processes in the field of DevOps using scripts written 🧠 in a shell language, such as Bash πŸ’».

  • #!/bin/bash?

🐚 #!/bin/bash: The Bash Shell 🌟

  • One of the languages your computer πŸ’» knows is called "Bash," which is like a special cooking language with many unique ingredients and techniques. πŸ§πŸŽ‚πŸ©

#!/bin/sh?

🐚#!/bin/sh? : The SH Shell

Whenever you see #!/bin/bash at the beginning of a script, it means the computer will use the Bash language to understand and execute the commands written in the script. πŸ‹οΈβ€β™‚οΈπŸŽ―


  • Write a Shell Script that prints I will complete the #90DaysOfDevOps challenge
ubuntu@ip-172-31-117-6:~$ vim 90daysofchallenge.sh
ubuntu@ip-172-31-117-6:~$ bash 90daysofchallenge.sh
I wil complete #90DaysOfDevOps Challenge

I need to learn more about shell script in order add further details, information and scenarios.


πŸŒπŸ”Network Commands in Ubuntu πŸš€πŸ’»

Ubuntu, being a powerful and versatile operating system, provides a plethora of network commands that allow you to troubleshoot, configure, and manage various networking aspects. Whether you're a beginner or an experienced user, understanding these commands can work wonders in keeping your network running smoothly. Let's dive into the world of network commands in Ubuntu! πŸŒπŸ”

  • ifconfig: This classic command displays the configuration of all network interfaces on your system, including IP addresses, MAC addresses, and more.

if this command not worked that means ifconfig is not installed on your Ubuntu system. check below code and snapshot.

ubuntu@ip-172-31-117-6:~$ ifconfig
Command 'ifconfig' not found, but can be installed with:
sudo apt install net-tools
ubuntu@ip-172-31-117-6:~$ sudo apt install net-tools
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 204 kB of archives.
After this operation, 819 kB of additional disk space will be used.
Get:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy/main amd64 net-tools amd64 1.60+git20181103.0eebece-1ubuntu5 [204 kB]
Fetched 204 kB in 0s (10.2 MB/s)
Selecting previously unselected package net-tools.
(Reading database ... 64295 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20181103.0eebece-1ubuntu5_amd64.deb ...
Unpacking net-tools (1.60+git20181103.0eebece-1ubuntu5) ...
Setting up net-tools (1.60+git20181103.0eebece-1ubuntu5) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu@ip-172-31-117-6:~$

  • Once net-tools are installed try to run the ifconfig command now.
ubuntu@ip-172-31-117-6:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.31.117.6  netmask 255.255.0.0  broadcast 172.31.255.255
        inet6 fe80::14ea:f3ff:fef8:f9f3  prefixlen 64  scopeid 0x20<link>
        ether 16:ea:f3:f8:f9:f3  txqueuelen 1000  (Ethernet)
        RX packets 6985  bytes 1014625 (1.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5732  bytes 687738 (687.7 KB)
        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<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 114  bytes 11679 (11.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 114  bytes 11679 (11.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  • ip: A more powerful alternative to ifconfig. It provides detailed information about network interfaces and routing tables.
ubuntu@ip-172-31-117-6:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc fq_codel state UP group default qlen 1000
    link/ether 16:ea:f3:f8:f9:f3 brd ff:ff:ff:ff:ff:ff
    inet 172.31.117.6/16 metric 100 brd 172.31.255.255 scope global dynamic eth0
       valid_lft 2622sec preferred_lft 2622sec
    inet6 fe80::14ea:f3ff:fef8:f9f3/64 scope link
       valid_lft forever preferred_lft forever

  • ping: Check the connectivity to a specific host or IP address.
ubuntu@ip-172-31-117-6:~$ ping google.com
PING google.com (142.251.163.139) 56(84) bytes of data.
64 bytes from wv-in-f139.1e100.net (142.251.163.139): icmp_seq=1 ttl=96 time=16.3 ms
64 bytes from wv-in-f139.1e100.net (142.251.163.139): icmp_seq=2 ttl=96 time=16.2 ms
64 bytes from wv-in-f139.1e100.net (142.251.163.139): icmp_seq=3 ttl=96 time=16.2 ms
64 bytes from wv-in-f139.1e100.net (142.251.163.139): icmp_seq=4 ttl=96 time=16.2 ms
64 bytes from wv-in-f139.1e100.net (142.251.163.139): icmp_seq=5 ttl=96 time=16.2 ms


Network Connectivity and Diagnostics: 🌐

  • nslookup: Perform DNS (Domain Name System) queries to get information about domain names and IP addresses.
ubuntu@ip-172-31-117-6:~$ nslookup trainwithshubham.com
Server:         127.0.0.53
Address:        127.0.0.53#53
Non-authoritative answer:
Name:   trainwithshubham.com
Address: 3.33.152.147
Name:   trainwithshubham.com
Address: 15.197.142.173

  • dig Another tool for DNS queries, providing more detailed information and options.
ubuntu@ip-172-31-117-6:~$ dig trainwithshubham.com

; <<>> DiG 9.18.12-0ubuntu0.22.04.1-Ubuntu <<>> trainwithshubham.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18037
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;trainwithshubham.com.          IN      A
;; ANSWER SECTION:
trainwithshubham.com.   192     IN      A       3.33.152.147
trainwithshubham.com.   192     IN      A       15.197.142.173
;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Wed Jul 19 15:59:24 UTC 2023
;; MSG SIZE  rcvd: 81


Configuring Network Interfaces: 🌐

  • sudo ifconfig <interface_name> up/down: Enable or disable a specific network interface.
ubuntu@ip-172-31-117-6:~$ sudo ifconfig eth0 down
client_loop: send disconnect: Connection reset

my ec2 ubuntu is not able to connect now I need to reboot my instance from the AWS portal. Connected again as below shown snapshot and command code.

ξ‚Ά HemantPatle ξ‚°ξ‚° ξͺƒ ~ ξ‚°  ξ‚°ξ‚°  ξ‚΄ ssh -i "LinuxVmKeyPair.pem" ubuntu@ec2-3-239-95-224.compute-1.amazonaws.com                     in pwsh at 21:36:04
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.19.0-1025-aws x86_64)

  • sudo ip addr add <ip_address>/<subnet_mask> dev <interface_name>: Assign an IP address to a network interface.

Will add advanced commands to configure network interfaces in the Advanced Ubuntu command Blog. 🧠


Mastering these network commands you need to troubleshoot network issues, configure connections, and maintain a secure and efficient network environment in your Ubuntu System before touching the production-level environment.

Happy networking! πŸŒŸπŸŒπŸ’»

Happy Linuxing! πŸ§πŸ’»


Thank You !!

More from this blog

Git & GitHub Essentials for DevOps Engineers

πŸ™πŸ•’πŸ’πŸŒπŸ”πŸ–₯οΈπŸ§πŸ”„πŸš€πŸ“ΈπŸ“πŸŽ―πŸ”–πŸŒΏπŸ“πŸ€πŸ•΅οΈβ€β™‚οΈπŸ“„πŸ™πŸ•’πŸ’πŸŒπŸ”πŸ–₯οΈπŸ§πŸ”„πŸš€πŸ“ΈπŸ“πŸŽ―πŸ”–πŸŒΏπŸ“πŸ€πŸ•΅οΈβ€β™‚οΈπŸ“„πŸ™πŸ•’πŸ’πŸŒπŸ”πŸ–₯οΈπŸ§πŸ”„πŸš€πŸ“ΈπŸ“πŸŽ―πŸ•’πŸ’πŸŒπŸ”

Aug 5, 202310 min read
Git & GitHub Essentials for DevOps Engineers

Untitled Publication

9 posts