Day 2 and Day 3 : Basic Linux commands

Day 2 and Day 3 : Basic Linux commands

Day 2 of #90 Days of DevOps :

Linux is an open-source operating system that was developed by Linus Torvalds.

What is the Linux command to

  1. Check your present working directory

    pwd

  2. List all the files or directories including hidden files

    ls -a

  3. Create a nested directory A/B/C/D/E

    mkdir -p test1/test2/test3/est4

  4. Create a new file, touch is used when you want to create a file but it will not open in text editor mode

    touch file1

  5. To view what's written in a file

    cat file1

    Linux Permissions

    Linux has 3 types of permissions: read, write and execute

    read: to set read permission (r=4)

    write: to set write permission (w=2)

    execute: to set execute permission (x=1)

    These permissions can be applied to user(u), group(g) and others(o).

  6. To change the access permissions of files

    chmod 777 file1

  7. To check which commands you have run till now

    history

  8. To remove a directory/ Folder

    rmdir test1

  9. To create a fruits.txt file and to view the content

    vim fruits.txt

    cat fruits.txt

    vim is used when the file needs to be created as well as opened as a text editor

    Mostly used modes in VIM:

    • Normal mode: This is the default mode in which vim starts. In normal mode, you can use various commands to navigate and edit the text.

    • Insert mode: In insert mode, you can type text into the file. To enter insert mode, press the "i" key. To exit insert mode and return to normal mode, press the "Esc" key.

    • Command mode: In command mode, you can enter commands to perform various actions, such as saving the file or quitting vim. To enter command mode, press the ":" key.

Day 3 of #90 Days of DevOps:

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

    vim devops.txt

    cat devops.txt

  2. To show only the top three fruits from the file

    head -3 devops.txt

    This command prints the first N number of data of the given input. By default, it prints 10 lines.

  3. To show only the bottom three fruits from the file

    tail -3 devops.txt

    This command prints the last N number of data of the given input. By default, it prints 10 lines.

  4. To find the difference between fruits.txt and devops.txt file

    diff fruits.txt devops.txt

  5. To search for a particular string/ word in a text file

    grep This file1

  6. To sort the results of the search either alphabetically or numerically

    sort devops.txt - It also sorts files and directories

    sort -r: The flag returns the results in reverse order.

    sort -f: The flag does case-insensitive sorting.

    sort -n: The flag returns the results as per numerical order.

  7. To extract specific fields or columns from a file or standard input

    cut -column number-number of characters filename

    cut -c1-3 devops.txt

  8. To perform basic text transformations on an input file. It stands for "stream editor"

    sed options [script] [inputfile]

    sed 's/Apple/Fruit/' devops.txt

  9. To find files and directories and perform subsequent operations on them

    In the below command, It will search in the present working directory and its subdirectories, and print the name of the file that has a “.txt” file extension.

    find . -name "*.txt"

  10. free: This command displays the total amount of free space available along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel

  11. nslookup: This stands for “Name server Lookup”. This is a tool for checking DNS hostname to IP or IP to Hostname. This is very helpful while troubleshooting