Linux Commands

Linux Commands

"Linux commands" refer to the instructions you can input into a Linux terminal to perform specific tasks or operations. Commands are used to instruct the computer. we have to write commands on the shell (terminal). Shell forwards these commands to the kernel and the kernel forwards them to the hardware.

Some Basic Commands

  1. View File Contents

    • Command: cat filename.txt

    • Description: The cat command stands for "concatenate and display." It's primarily used to display the content of files.

  2. Change File Permissions

    • Command: chmod permissions filename

    • Description: chmod (change mode) is used to set or modify the permissions of a file or directory. Permissions determine who can read, write, or execute a file.

  3. View Command History

    • Command: history

    • Description: The history command displays the commands you've entered in your terminal session, allowing you to revisit or reuse previous commands.

  4. Remove Directory

    • Command: rmdir directoryname

    • Description: rmdir removes empty directories. If a directory has content, you would use rm -r directoryname.

  5. Create and View a File

    • Command:

        bashCopy codetouch fruits.txt
        cat fruits.txt
      

      Description: touch creates an empty file. Following this with cat allows you to view its contents, which would be empty in this case.

  6. Add Content to a File

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

    • Description: The echo command is used for outputting text. With the -e flag, it interprets escaped characters like \n for a new line. The > operator writes this output to a file.

  7. Display Top Lines of a File

    • Command: head -3 devops.txt

    • Description: head displays the top lines of a file. The -3 option specifies that only the top three lines should be shown.

  8. Display Bottom Lines of a File

    • Command: tail -3 devops.txt

    • Description: Conversely, tail shows the bottom lines of a file, and the -3 option ensures only the last three lines are shown.

  9. Add Content to Another File

  • Command: echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt

  • Description: This uses the same echo technique as before to add content to a new file.

Some short notes:

Some notes:

  • The cat command is used for viewing the content of files.

  • The chmod command is for changing file permissions.

  • history displays a list of commands that you've previously entered.

  • rmdir removes an empty directory.

  • touch creates a new, empty file.

  • echo outputs the specified text, and with the redirection > operator, you can write that output to a file. The -e flag allows the interpretation of escaped characters like \n (newline).

  • head and tail are used to display the top or bottom lines of a file, respectively.

  • The diff command compares the contents of two files and displays the differences between them.