Advanced Linux commands

#90DaysOfDevOps

Advanced Linux commands

Introduction

Linux, an open-source operating system, has become a cornerstone in the world of computing. With its flexibility, Linux is the preferred choice for tech-savvy individuals and professionals. In this blog, we will explore some advanced Linux concepts, including user and group management, essential commands like grep, awk, and find, file permissions with numerical values, and a comprehensive guide to SSH, SCP, and systemctl.

  1. User and Groups Management: In Linux, managing users and groups is fundamental to maintaining a secure and organized system. Let's see how to modify, alter, add, and delete users and groups.
  • Adding a User: To add a new user, use the useradd command followed by the desired username:
bashCopy codesudo useradd username
  • Modifying User Attributes: To modify a user's attributes, use the usermod command:
bashCopy codesudo usermod -c "New User Name" username
  • Creating a Group: To create a new group, use the groupadd command:
bashCopy codesudo groupadd groupname
  • Adding a User to a Group: To add a user to a group, utilize the usermod command with the -aG option:
bashCopy codesudo usermod -aG groupname username
  • Deleting a User and Group: To remove a user and group from the system, use the userdel and groupdel commands:
bashCopy codesudo userdel username
sudo groupdel groupname
  1. Mastering grep, awk, and find: These commands are essential for searching and manipulating text data in Linux.
  • grep: The grep command searches for a specific pattern within files.
bashCopy codegrep 'pattern' file
  • awk: awk is a powerful text processing tool that operates on columns in a file.
bashCopy codeawk '{print $2}' file
  • find: The find command helps locate files and directories based on various criteria.
bashCopy codefind /path/to/search -name "*.txt"
  1. File Permissions in Detail: Understanding and setting file permissions is crucial to control access to files and directories. Linux uses three types of permissions: read (r), write (w), and execute (x), which apply to three user categories: owner, group, and others.
  • Changing File Permissions: To change permissions, use chmod followed by the numerical value of the desired permission:
bashCopy codechmod 755 filename

  • Numeric Representation of Permissions: Each permission has a numerical value: read (4), write (2), and execute (1). To combine permissions, add their values:

    • 7 (read, write, execute)

    • 6 (read, write)

    • 5 (read, execute)

    • 4 (read)

    • 3 (write, execute)

    • 2 (write)

    • 1 (execute)

  1. SSH and SCP : Secure Shell (SSH) is crucial for remote access, while SCP (Secure Copy) enables secure file transfers.
  • SSH: To connect to a remote server via SSH, use the following command:
bashCopy codessh username@remote_host
  • SCP: To copy files securely between local and remote systems, employ the SCP command:
bashCopy codescp /path/to/local/file username@remote_host:/path/to/destination
  1. Understanding systemctl: systemctl is a powerful command to manage services in Linux.
  • Starting a Service: To start a service, use:
bashCopy codesudo systemctl start service_name
  • Stopping a Service: To stop a service, use:
bashCopy codesudo systemctl stop service_name
  • Restarting a Service: To restart a service, use:
bashCopy codesudo systemctl restart service_name
  • Enabling a Service: To enable a service to start at boot, use:
bashCopy codesudo systemctl enable service_name
  • Disabling a Service: To disable a service from starting at boot, use:
bashCopy codesudo systemctl disable service_name

Conclusion

By diving into the world of advanced Linux concepts, you can significantly enhance your productivity and management skills. From user and group administration to mastering powerful commands like grep, awk, and find, and understanding file permissions, SSH, SCP, and systemctl, you are now equipped to handle various Linux tasks efficiently. Embrace the power of Linux and explore its endless possibilities! Happy learning!