DEV Community

Cover image for Linux for DevOps Engineer: 101๐Ÿš€๐ŸŽฏ๐Ÿ”ฅ
Cloudia for DevopsDynamicsHub

Posted on

Linux for DevOps Engineer: 101๐Ÿš€๐ŸŽฏ๐Ÿ”ฅ

Are you a DevOps Engineer looking to streamline your operations and manage your infrastructure more effectively? If so, you might already know that Linux is a crucial tool in your toolkit. But why exactly is Linux so important for DevOps professionals? Letโ€™s explore why mastering Linux commands is essential, a bit of history behind Linux, and how it can make your work life easier.

Why Linux for DevOps Engineers?
Think of Linux as the backbone of many server environments. Itโ€™s like the reliable, sturdy foundation of a house that supports everything built on top. As a DevOps Engineer, youโ€™ll find that many of your tools and environments run on Linux. Hereโ€™s why:

  • Stability and Performance: Linux is known for its stability and performance, making it ideal for running critical applications and services.

  • Open Source: Linux is open-source, meaning you can modify and customize it to fit your specific needs.

  • Command Line Mastery: Many DevOps tasks are performed through the command line, and Linux provides a powerful and flexible environment for these operations.

A Brief History of Linux
Ever wondered how Linux came to be such a dominant force in the world of IT? Hereโ€™s a quick look back:

1991: Linux was created by Linus Torvalds, a Finnish student, who wanted to build a free, open-source alternative to the commercial UNIX operating systems.
Growth: Over the years, Linux has grown from a simple personal project to a robust operating system used in everything from servers and desktops to smartphones and embedded systems.
Curious about how Linux evolved and its impact on modern computing? Check out our blog for a deep dive into Linux commands and how theyโ€™re used in real-time corporate projects.

Linux Commands for DevOps Engineers

In real-time corporate software projects, DevOps Engineers frequently use Linux commands to manage systems, servers, and configurations. Here are more essential Linux commands with examples:

  • System Information:

    • uname -a โ€“ Display system information.
    • Example: uname -a returns the kernel version, system architecture, and hostname.
  • File and Directory Management:

    • ls -la โ€“ List files with detailed information.
    • Example: ls -la lists all files, including hidden files, along with their permissions, owners, and sizes.
    • cp file1 file2 โ€“ Copy files.
    • Example: cp /etc/config.txt /backup/ copies the config.txt file to the backup directory.
    • mv file1 file2 โ€“ Move or rename files.
    • Example: mv test.txt /tmp/ moves test.txt to the /tmp/ directory.
    • rm -rf directory_name โ€“ Remove files or directories.
    • Example: rm -rf /old_files/ removes the old_files directory and its contents.
  • Permissions and Ownership:

    • chmod 755 file.txt โ€“ Change file permissions.
    • Example: chmod 755 script.sh allows the file owner to read, write, and execute the file, while others can only read and execute it.
    • chown user:group file.txt โ€“ Change file ownership.
    • Example: chown devops:admin config.yml changes the owner of the config.yml file to devops and the group to admin.
  • Package Management (Ubuntu):

    • apt-get update โ€“ Update the package list.
    • Example: sudo apt-get update updates the package list to include the latest versions of software available from repositories.
    • apt-get install โ€“ Install packages.
    • Example: sudo apt-get install nginx installs the NGINX web server on the system.
  • Networking:

    • ping www.example.com โ€“ Check network connectivity.
    • Example: ping google.com checks if the system can reach Google's servers.
    • ifconfig โ€“ Display or configure network interfaces.
    • Example: ifconfig eth0 shows the network information for the eth0 interface.
    • netstat -tuln โ€“ Display open ports and active connections.
    • Example: netstat -tuln lists all active listening ports on the system.
  • File Viewing and Monitoring:

    • tail -f /var/log/syslog โ€“ Monitor system logs in real time.
    • Example: tail -f /var/log/nginx/error.log shows real-time updates to the NGINX error logs.
    • dmesg โ€“ Display system messages (kernel ring buffer).
    • Example: dmesg | grep error filters system messages to show only errors.
    • cat file.txt โ€“ View the contents of a file.
    • Example: cat /etc/hosts displays the contents of the hosts file.
  • Process Management:

    • ps aux โ€“ List running processes.
    • Example: ps aux | grep nginx shows all running NGINX processes.
    • kill -9 PID โ€“ Terminate a process by its PID.
    • Example: kill -9 1234 forcefully stops the process with PID 1234.
  • Archiving and Compression:

    • tar -czvf archive.tar.gz /folder/ โ€“ Create a compressed archive.
    • Example: tar -czvf backup.tar.gz /var/www/ creates a compressed archive of the /var/www/ folder.
    • unzip file.zip โ€“ Extract a zip archive.
    • Example: unzip backup.zip extracts the backup.zip file into the current directory.

Text Editors in Linux

Linux offers several powerful text editors for editing files directly from the command line. The most commonly used editors include vi, sed, and cat.

1. vi (Vim) Editor:

  • vi is a versatile and widely-used text editor in Linux with both command and insert modes.

Example:

  • To edit a file, use: vi filename.txt
  • Press i to enter insert mode and start editing the file.
  • Press Esc to exit insert mode, and type :wq to save and exit, or :q! to quit without saving.

2. sed Editor (Stream Editor):

  • sed is a powerful stream editor used for parsing and transforming text in files. It's commonly used for search and replace operations.

Example:

  • To replace "foo" with "bar" in a file: sed -i 's/foo/bar/g' file.txt
  • This command replaces every occurrence of "foo" with "bar" in file.txt.

3. cat (Concatenate) Editor:

  • cat is primarily used to view the contents of a file, but it can also concatenate and create new files.

Example:

  • To view a file: cat filename.txt
  • To create a new file: cat > newfile.txt and then type the content. Press Ctrl+D to save and exit.

File Permissions in Linux

File permissions in Linux control who can read, write, and execute a file or directory. Permissions are set for three types of users:

  • Owner (u)
  • Group (g)
  • Others (o)

Each file or directory has three types of permissions:

  • Read (r) โ€“ Permission to read the contents.
  • Write (w) โ€“ Permission to modify the contents.
  • Execute (x) โ€“ Permission to run the file as a program.

Example:

  • To set permissions where the owner has full access, the group can read and execute, and others can only read: chmod 755 script.sh
    • This means:
    • Owner: read, write, and execute.
    • Group: read and execute.
    • Others: read only.

What is Sudoers File in linux:
The sudoers file in Linux is used to control which users or groups can execute commands with elevated (root) privileges using sudo.

  • Location: /etc/sudoers
  • Editing: You should use visudo to safely edit the sudoers file. This ensures syntax errors are avoided and won't lock you out of the system.

Example:
To allow a user (devops) to run all commands with sudo privileges, you would add the following line to the sudoers file:

devops ALL=(ALL:ALL) ALL

Enter fullscreen mode Exit fullscreen mode

This grants the devops user the ability to run any command as any user or group using sudo.

Feeling more confident about using Linux commands now? These tools and commands are essential for managing and automating your IT infrastructure.

Your Takeaway
As a DevOps Engineer, mastering Linux commands is not just an optionโ€”itโ€™s a necessity. From managing servers and monitoring performance to troubleshooting issues, Linux provides the foundation you need to excel in your role.

Thank you for reading my post!

Be sure to react on post and follow the writer๐Ÿ‘

Top comments (0)