Day 3: Basic Linux Commands - Part 2

Day 3: Basic Linux Commands - Part 2

Day 3 of 90daysofdevops What is the linux command to

Table of contents

No heading

No headings in the article.

  1. How to view what's written in a file?

    In Linux, if we want to see content in the file then we need to use the cat command.

    Syntax: cat <options> <filename>

    e.g. cat test1.txt

    if we use cat -n it will show output with line numbers.

    eg. cat -n test1.txt

    the cat command is also used for concatenation purposes. if we want to copy data from one file to another then, we can use the cat command.

    eg. cat test1.txt > test2.txt

  2. How to change the access permissions of files in Linux?

    chmod command is used to change the permission of files and directories.

    chmod means change mode. To see file or directory permission in Linux, we need to type ls -l command.

    -rw- rw- r-- This represents file permission.

    r=Read

    w=Write

    x=Execute

    To change file permissions we need to use chmod command.

    eg. chmod 777 colors.txt

  3. How to check which commands you have run till now?

    To know which commands we have used till now need to use the history command.

  4. How to remove a directory/ Folder in Linux?

    If we want to remove an empty directory we can use rmdir <directory name>.

    if the directory is not empty then we should use the rm command. It can be used like this: rm -rf <directory name>

    -r means recursive.

    -f means forcefully.

  5. How to create a fruits.txt file and view the content?

    To create an empty file we need to use the touch command and to view the content of the file we have to use cat command.

    eg. touch fruits.txt

    cat fruits.txt

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

    To add content to the file we can use Vim editor or we can use the echo command to add content in lines one by one.

    eg. type vim devops.txt then press Enter

    and press the I button to insert content.

    press ESC button then : and wq to exit from Vim editor

    OR

    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

  7. How to view only the top three fruits from the file?

    To view the top 3 lines we need to use the head command with option -3 and filename. By default, the head command shows the top 10 lines.

  8. Show only the bottom three fruits from the file.

    To view the bottom 3 lines we need to use the tail command with option -3 and filename. By default, the tail command shows the bottom 10 lines.

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

    Use touch command for creating a file and to see the the content of a file use cat command.

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

    echo "Red" >> Colors.txt

    echo "Pink" >> Colors.txt

    echo "White" >> Colors.txt

    echo "Black" >> Colors.txt

    echo "Blue" >> Colors.txt

    echo "Orange" >> Colors.txt

    echo "Purple" >> Colors.txt

    echo "Grey" >> Colors.txt

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

    diff command is used to see the difference between the two files.

    eg. diff <file1> <file2>

Thank You for reading this blog

Parimal Pradhan

You can follow me on LinkedIn for my daily updates:- https://www.linkedin.com/in/parimal-pradhan-b62021168/

Great initiative by the #trainwithshubham community. Thank you Shubham Londhe

#devops #90daysofdevops

Did you find this article valuable?

Support Parimal Pradhan by becoming a sponsor. Any amount is appreciated!