🔹Linux Basic Commands

refer:- https://gopalgtm.hashnode.dev/what-is-linux

Day 3 Task: Basic Linux Commands

Task: What is the linux command to

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

     cat file_name
    

  2. To change the access permissions of files.

    To change the access permissions of files in Linux, you can use the chmod command. Access permissions determine the level of access and control that different users or groups have over a file. The permissions are represented by three sets of three characters: User, Group, and Other.

    Each set consists of three permission types:

    • r (read): Allows reading or viewing the file.

    • w (write): Allows modifying or editing the file.

    • x (execute): Allows executing or running the file if it is a script or program.

Here's how the permissions are represented and what they mean:

  • rwx: Indicates full permissions (read, write, and execute).

  • -: Indicates that a specific permission is not granted.

The numbers 0-7 are used to represent different permission combinations. Each permission type has an associated number value:

  • r (read) = 4

  • w (write) = 2

  • x (execute) = 1

To set permissions, you can assign the appropriate number value to each permission type and sum them up. Here are some examples:

  • 777 means full permissions for all users (read, write, and execute).

  • 755 means the owner has full permissions, while the group and others have read and execute permissions.

  • 644 means the owner has read and write permissions, while the group and others have only read permissions.

To apply permissions using the chmod command, you need to specify the permission set followed by the file or directory you want to modify. Here are a few examples:

Grant full permissions (read, write, and execute) to all users:

    chmod permissions filename
    chmod 777 myfile.txt

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

     history
    

  2. To remove a directory/ Folder.

     rm -r myfolder
    
  3. To create a fruits.txt file and to view the content.

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

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

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

     head -n 3 fruits.txt
    
  6. To Show only bottom three fruits from the file.

     tail -n 3 fruits.txt
    
  7. To create another file Colors.txt and to view the content.

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

    echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" >> Colors.txt
    cat Colors.txt
    
  9. To find the difference between fruits.txt and Colors.txt file.

    diff fruits.txt Colors.txt