Skip to main content

Command Palette

Search for a command to run...

Basic Linux Commands

Updated
4 min read

We will see some basic commands as 90DaysChallege then will see most used linux command for Devops.

  1. To view what's written in a file : To view the contents of a file in Linux, you can use the cat command.
cat firstfile.txt
  1. To change the access permissions of files: To change the access permissions of files in Linux, you can use the chmod command. The chmod command allows you to set permissions for the owner of the file, the group that the file belongs to, and all other users.
chmod 700 firstfile.txt

you can refer permission table to give the required permission:

  1. To check which commands you have run till now:

To check the list of commands that you have run previously in the terminal, you can use the history command.

  1. To remove a directory/ Folder :

    To remove a directory or folder in Linux, you can use the rmdir or rm command depending on whether the directory is empty or not.

    If the directory is empty, you can use the rmdir command to remove it. Simply open up a terminal and type the following command, replacing directory_name with the name of the directory that you want to remove:

     rmdir firstfolder
    

    If the directory is not empty, you can use the rm command with the -r option to recursively remove the directory and its contents. This will remove all files and subdirectories within the directory, so use it with caution.

     rm -r firstfolder
    
  2. To create a fruits.txt file and to view the content :

    To create a file named fruits.txt in Linux, you can use a text editor like nano, vim, or gedit. Here's an example of how to create and edit the file using the vim editor.

     vim fruits.txt
    
    1. Once you're in the editor, press the i key to enter Insert mode. This will allow you to start typing and add content to the file.

    2. Type the content you want to add to the file.

    3. Once you've finished adding the content, press the Esc key to exit Insert mode.

    4. To save the changes to the file and exit vim, either you can type :wd or :x

      you can view its contents using the cat command or other text editors or viewers.

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

To add the contents "Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava" in separate lines to a file named devops.txt using the echo command in Linux, you can use the following command:

    echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt

This will add the contents to the devops.txt file in separate lines. Here's a breakdown of the command:

  • echo: This is the command used to print text to the terminal.

  • -e: This option enables the interpretation of backslash escapes in the string. It allows us to use \n to create new lines in the output.

  1. To Show only top three fruits from the file.

To show only the top three fruits from the devops.txt file, you can use the head command in Linux along with the -n option. Here's how to do it:

    head -n 3 devops.txt

The -n option allows you to specify the number of lines you want to display.

  1. 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 in Linux along with the -n option. Here's how to do it:

     tail -n 3 devops.txt
    
  2. To find the difference between Two files(fruits.txt and Colors.txt file).

    To find the difference between the fruits.txt and Colors.txt files in Linux, you can use the diff command. Here's how to do it:

     diff fruits.txt Colors.txt
    

    This command will display the differences between the two files, if any. If the files are identical, there will be no output. If there are differences, the output will show which lines are different.

Now we will see some important and most used commands for DevOps.

  1. ls: List the contents of a directory.

  2. cd: Change the current working directory.

  3. mkdir: Create a new directory.

  4. rm: Remove a file or directory.

  5. cp: Copy files or directories.

  6. mv: Move or rename files or directories.

  7. grep: Search for a pattern in a file.

  8. sed: Stream editor for filtering and transforming text.

  9. awk: Pattern scanning and processing language.

  10. cat: Concatenate and display files.

  11. tail: Display the last lines of a file.

  12. head: Display the first lines of a file.

  13. chmod: Change file permissions.

  14. chown: Change file ownership.

  15. ssh: Securely connect to a remote server.

  16. scp: Securely copy files between hosts.

  17. rsync: Efficiently synchronize files and directories.

  18. tar: Archive files and directories.

  19. curl: Transfer data from or to a server using various protocols.

  20. wget: Retrieve files from the web using various protocols.

This was the challenge for day 3 to learn Linux commands. If you any suggestion please do command.

Happy learning

More from this blog

Ajay Patel

116 posts