Linux Basics Part 2

Linux Basics Part 2

#90DaysOfDevops #Day3

Table of contents

No heading

No headings in the article.

We will start the Linux basics part 2. Here are some important commands. Please find as below:

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

    To check what has been written in a file cat command is used.

    The "cat" command in Linux is used to display the contents of a file on the terminal window. You can also use it to combine two or more files together or append the contents of one file to another. It's a simple and versatile command that's useful for working with text files on the command line.

  2. To check what is the current permission of a file ?

    To check the current permissions of a file in Linux, you can use the "ls" command with the "-l" (long format) option. The output of the "ls -l" command includes information about the file, including its permissions.

    Here's an example:

    The permissions are represented by the first 10 characters of the output, starting with the "-" character. The first character indicates the type of file ("-": regular file, "d": directory, "l": symbolic link, etc.), and the next three characters represent the permissions for the owner, followed by the permissions for the group, and then the permissions for others.

    Each set of permissions is represented by three characters, which can be either a "-" (no permission) or one of the following symbols:

    • "r": read permission

    • "w": write permission

    • "x": execute permission

For example, in the output above, the file "filename" has the following permissions:

  • The owner has read and write permissions ("-rw-")

  • The group has read write permission ("rw-")

  • Others have read-only permission ("r--")

  1. To check what is the current permission of a directory?

    To check the permissions of the directory ls -ld command is used.

  2. To change the access permissions of files.

    To change the access permissions of a file in Linux, you can use the "chmod" command. The "chmod" command stands for "change mode", and it is used to change the access permissions of a file or directory.

    In Linux, access permissions refer to the set of rules that determine which users and groups can access a particular file or directory and what actions they can perform on it. The access permissions are associated with each file and directory and define who can read, write or execute the file, and who cannot. These permissions are crucial for security reasons, and they help to prevent unauthorized access, modification, or deletion of files and directories.

    In Linux, three basic access permission types apply to files and directories:

    Read permission: Allows the user to view the contents of the file or directory.

    Write permission: Allows the user to modify the contents of the file or directory.

    Execute permission: Allows the user to run the file as a program or access the contents of a directory.

    Each of these permission types can be set for three categories of users: the owner of the file or directory, members of the group that the file or directory belongs to, and all other users. The combination of these permission types and user categories results in a three-digit code that represents the access permissions for a file or directory. The first digit represents the permissions for the owner, the second digit represents the permissions for the group, and the third digit represents the permissions for all other users.

    The access permissions for a file or directory can be viewed and modified using the "ls" and "chmod" commands in the Linux terminal.

    In Linux, access permissions are represented by a combination of symbols and values that indicate which users and groups have permission to read, write, or execute a file or directory. The values are represented in octal form and correspond to the binary representation of the three permissions: read (r), write (w), and execute (x).

    Here are the octal values for each permission:

    Read permission (r): 4 Write permission (w): 2 Execute permission (x): 1 These values are used to construct a three-digit number that represents the access permissions for a file or directory. Each digit represents the permission for a different user category: owner, group, and others.

    For example, the permission code "755" represents the following access permissions:

    The owner has read, write, and execute permissions (4+2+1=7) The group has read and execute permissions (4+1=5) All other users have read and execute permissions (4+1=5) Here are some other common permission codes and their corresponding access permissions:

    777: All users have read, write, and execute permissions 644: The owner has read and write permissions, and all other users have read permission 600: The owner has read and write permissions, and no other users have any permissions.

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

      The "history" command in Linux is used to display a list of commands that have been executed in the current shell session. When you run a command in the terminal, it is added to the history list, which can be useful for recalling and re-executing previous commands.

      To use the "history" command, simply type "history" at the command prompt and press Enter:

      1. To remove a directory/ Folder?

        To remove a directory (folder) in Linux, you can use the "rmdir" or "rm" command, depending on whether the directory is empty or contains files.

        If the directory is empty, you can use the "rmdir" command followed by the name of the directory:

        This will remove the directory if it is empty.

        If the directory contains files or other subdirectories, you can use the "rm" command with the "-r" (recursive) option to remove the directory and all its contents:

        Note that the "-r" option is dangerous because it will delete all files and subdirectories in the directory, so make sure you specify the correct directory name and confirm the action before proceeding.

        If you want to remove a directory and all its contents without being prompted for confirmation, you can use the "-f" (force) option:

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

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

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

    The "head" command in Linux is used to display the first few lines of a file. By default, it displays the first 10 lines of a file, but you can specify a different number of lines using the "-n" option.

  1. to show only the bottom three fruits from the file.

    The "tail" command in Linux is used to display the last few lines of a file. By default, it displays the last 10 lines of a file, but you can specify a different number of lines using the "-n" option.

  2. To create another file Colors.txt and to view the content and Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, and Grey.

  3. To find the difference between fruits.txt and Colors.txt file?

    The "diff" command in Linux is used to compare the contents of two files and show the differences between them. Here are some key differences between the two files that can be shown using the "diff" command:

    1. Lines added: The "diff" command will show lines that are present in one file but not in the other file.

    2. Lines deleted: The "diff" command will show lines that are present in one file but have been deleted in the other file.

    3. Lines modified: The "diff" command will show lines that are present in both files but have been modified in one of the files.

    4. Lines moved: The "diff" command will show lines that have been moved from one location to another in one of the files.

Here is an example of how to use the "diff" command:

Here are these some of basic commands which I have write here of Linux.