Advanced Linux Commands {grep/awk}|| Day 5

Advanced Linux Commands {grep/awk}|| Day 5

  1. Commands to create user in linux :

    This command is used to create a user and create a directory for the same user name.

     sudo useradd Abhishek-devops -m
    
  2. This command is used to check if Abhishek-devops user is created.

     sudo cat /etc/passwd
    

  3. Commands to add/create groups

    This command is use to create a group in linux.

     sudo groupadd devops
    
  4. Commands to check group is added

    This command is use to check if a group in linux.

     sudo cat /etc/group
    

  5. Commands to add a user to a devops group

    This command is use to add a single user (Abhishek-devops) to devops group and with below response Abhishek-devops user will be added to devops group.

     sudo gpasswd -a Abhishek-devops devops
    

  6. Commands to check Abhishek-devops user is added to devops group.

    This command is used to check users added to a group. The output is showing that Abhishek-devops is added to devops group.

     sudo cat /etc/group
    
  7. Commands to add multiple users to a signle group.

    This command is used to add multiple users or members in a single group

    Example : commands result is showing jethalal,vijay_qa,vijay_dev users added to devops group.

     sudo gpasswd -M jethalal,vijay_qa,vijay_dev devops
    

8 . Commands to check permissions of a file.

This command is used to check permissions of a file.

Example: commands result is showing permissions of file.

bash ls -l backup.sh

  1. grep command in Linux

    grep stands for global search for regular expression and print out.

    Grep command is used to find or search a regular expression or a string in a text file.

    If you wish to search for a string in your current directory and all other subdirectories, search using the - r flag as shown

     grep -r Hello
    

    "Hello" word searched recursively in directory and sub directory.

  2. This command is used to search "TRACE' word in log.txt file.

     grep TRACE log.txt
    

    Example: Creaate a file with vim log.txt paste some log data and then run this command.

11 . This command is used to write searched output "TRACE' word in trace.txt file.

12 . awk commands :

The awk command is used for text processing in Linux. Although, the sed command is also used for text processing, but it has some limitations, so the awk command becomes a handy option for text processing. It provides powerful control to the data.

Example :

bash awk /INFO/ log.txt

  1. To Print first column from logfile use '{print $1}' in awk command

     awk '/INFO/ {print $1}' log.txt
    

  2. ACL :

    Access control list (ACL) provides an additional, more flexible permission mechanism for file systems. It is designed to assist with UNIX file permissions. ACL allows you to give permissions for any user or group to any disc resource.

    Example ;

  3. This command is used to check the permission of the log.txt file.

     getfacl log.txt
    

    Thanks for reading this blog these were some advance linux command.