Basic Linux Commands

Basic Linux Commands

Day 3 : Basic Linux Commands

Table of contents

No heading

No headings in the article.

  1. To view what's written in a file.

     [ec2-user@masternode react_django_demo_app]$ ls
     api         docker-compose.yaml  frontend   README.md         tests
     db.sqlite3  Dockerfile           manage.py  requirements.txt  todo_drf
     [ec2-user@masternode react_django_demo_app]$ cat requirements.txt
     asgiref==3.2.3
     Django==3.0.3
     django-cors-headers==3.2.1
     djangorestframework==3.11.0
     pytz==2019.3
     sqlparse==0.3.0
     [ec2-user@masternode react_django_demo_app]$
    
  2. To change the access permissions of files.

     [ec2-user@masternode react_django_demo_app]$ ls -al
     total 168
     drwxr-xr-x. 7 root     root       4096 May  3 18:12 .
     drwx------. 5 ec2-user ec2-user    154 May  3 18:59 ..
     drwxr-xr-x. 4 root     root        179 May  3 18:12 api
     -rw-r--r--. 1 root     root     143360 May  3 18:12 db.sqlite3
     -rw-r--r--. 1 root     root         77 May  3 18:12 docker-compose.yaml
     -rw-r--r--. 1 root     root        144 May  3 18:12 Dockerfile
     drwxr-xr-x. 5 root     root        124 May  3 18:12 frontend
     drwxr-xr-x. 8 root     root        163 May  3 18:12 .git
     -rw-r--r--. 1 root     root          4 May  3 18:12 .gitignore
     -rw-r--r--. 1 root     root        628 May  3 18:12 manage.py
     -rw-r--r--. 1 root     root        109 May  3 18:12 README.md
     -rw-r--r--. 1 root     root        113 May  3 18:12 requirements.txt
     drwxr-xr-x. 3 root     root         44 May  3 18:12 tests
     drwxr-xr-x. 3 root     root        108 May  3 18:12 todo_drf
     [ec2-user@masternode react_django_demo_app]$ sudo chmod 777 requirements.txt
     [ec2-user@masternode react_django_demo_app]$ ls -al
     total 168
     drwxr-xr-x. 7 root     root       4096 May  3 18:12 .
     drwx------. 5 ec2-user ec2-user    154 May  3 18:59 ..
     drwxr-xr-x. 4 root     root        179 May  3 18:12 api
     -rw-r--r--. 1 root     root     143360 May  3 18:12 db.sqlite3
     -rw-r--r--. 1 root     root         77 May  3 18:12 docker-compose.yaml
     -rw-r--r--. 1 root     root        144 May  3 18:12 Dockerfile
     drwxr-xr-x. 5 root     root        124 May  3 18:12 frontend
     drwxr-xr-x. 8 root     root        163 May  3 18:12 .git
     -rw-r--r--. 1 root     root          4 May  3 18:12 .gitignore
     -rw-r--r--. 1 root     root        628 May  3 18:12 manage.py
     -rw-r--r--. 1 root     root        109 May  3 18:12 README.md
     -rwxrwxrwx. 1 root     root        113 May  3 18:12 requirements.txt
     drwxr-xr-x. 3 root     root         44 May  3 18:12 tests
     drwxr-xr-x. 3 root     root        108 May  3 18:12 todo_drf
     [ec2-user@masternode react_django_demo_app]$
    
  3. To check which commands you have run till now.

     [ec2-user@masternode ~]$ history
         1  whoami
         2  users
         3  useradd master
         4  sudo useradd master
         5  users
         6  cat /etc/passwd
         7  usermod -l master masternode
         8  usermod -l masternode master
         9  sudo usermod -l masternode master
        10  cat /etc/passwd
        11  userdel master
        12  userdel masternode
        13  sudo userdel masternode
        14  ls -ld /home/master/
        15  rm -rf /home/master/
    
  4. To remove a directory/ Folder.

     [ec2-user@masternode ~]$ ls
     react_django_demo_app  testdir
     [ec2-user@masternode ~]$ rm -rf testdir/
     [ec2-user@masternode ~]$ ls
     react_django_demo_app
     [ec2-user@masternode ~]$
    
  5. To create a fruits.txt file and to view the content.

     [ec2-user@masternode testdir]$ touch fruits.txt
     [ec2-user@masternode testdir]$ ls
     fruits.txt
     [ec2-user@masternode testdir]$ cat fruits.txt
     [ec2-user@masternode testdir]$
    
  6. Add content in devops.txt (One in each line) - Git, GitHub, Jenkins, Maven, Docker, Kubernetes, Linux, Terraform.

     [ec2-user@masternode testdir]$ vi devops.txt
    

    To edit the file click i key to insert and add the content to the file then to save click ESC+ :wq

  7. To Show only the top three lines from the file.

     [ec2-user@masternode testdir]$ head -3 devops.txt
     Git
     GitHub
     Jenkins
     [ec2-user@masternode testdir]$
    
  8. To Show only bottom three lines from the file.

     [ec2-user@masternode testdir]$ tail -n 3 devops.txt
     Kubernetes
     Linux
     Terraform
     [ec2-user@masternode testdir]$
    
  9. To create another file Colors.txt and to view the content.

     [ec2-user@masternode testdir]$ touch Colors.txt
     [ec2-user@masternode testdir]$ cat Colors.txt
    
  10. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.

    [ec2-user@masternode testdir]$ vi Colors.txt
    

    To edit the file click i key to insert and add the content to the file then to save click ESC+ :wq

  11. To find the difference between fruits.txt and Colors.txt file.

    [ec2-user@masternode testdir]$ diff devops.txt Colors.txt
    1,8c1,8
    < Git
    < GitHub
    < Jenkins
    < Maven
    < Docker
    < Kubernetes
    < Linux
    < Terraform
    ---
    > Red
    > Pink
    > White
    > Black
    > Blue
    > Orange
    > Purple
    > Grey
    [ec2-user@masternode testdir]$
    

Stay tuned for such content !!

Thank you for reading.