Blog

Blog

Linux Commands in DevOps: Must Know For Every DevOps Professional

Linux Commands in DevOps: Must Know For Every DevOps Professional

Linux Commands in DevOps

What is Linux?

Linux is an open-source and community-developed operating system for computers, servers, mainframes, mobile devices, and embedded devices. It has support on almost every major computer platform including x86, ARM, etc, making it one of the most widely supported operating systems.

The design of Linux is similar to UNIX but it has evolved to run on a wide variety of hardware from phones to supercomputers. Every Linux-based OS contains the Linux Kernel—which manages hardware resources—and a set of software packages that make up the rest of the operating system.

.linux-linuxcommands in devops-Edureka

Linux basics are one of the most basic abilities of a DevOps expert. The greater part of the organizations have their current circumstance on Linux, likewise, numerous CM instruments like Chef, Puppet, and Ansible have their main hubs on Linux.

In a world overflowing with new apparatuses and different advancement conditions, there is a requirement to get familiar with some essential sysadmins commands. Explicit commands can aid engineers to sort out, investigate, and upgrade their applications and give important emergency data to administrators and sysadmins. The given fundamental sysadmins commands can aid you to comprehend applications. It assists you with portraying issues to sysadmins investigating why an application may work locally yet not on a distant host. Commands apply to Linux advancement conditions, virtual machines (VMs), and containers. In this tutorial,

Linux fundamentals and Scripting are one of the most essential skills of a DevOps Professional. Most companies have their environment on Linux, also many CM tools like – Puppet, Chef and Ansible have their master nodes on Linux. command line part which is an essential part of the Professional Certificate in DevOps.

Why Linux is popular?

Linux is different from the rest of the operating systems in many important aspects. Some of them are as follows.

1. Free – First, and perhaps most importantly, Linux is free. You do not have to spend any amount to download and use it, unlike windows.

2. Open Source – Linux is open-source software. The code used to create Linux is free and available to the public to view, edit, and—for users with the appropriate skills—contribute to.

3. Secure – Once you have Linux installed on your system, there is no need to use an antivirus! Linux is a highly secure system. Moreover, there is a global development community constantly looking at ways to enhance its security. Each upgrade makes the OS becomes more secure and robust.

4. Stability and Performance – Linux provides very high stability i.e. it does not need a reboot after a short period of time. Your Linux system rarely slows down or freezes. You can work without any disturbance on your Linux systems. Linux provides remarkably high performance on various networks and workstations.

Linux Commands in DevOps:

As a DevOps professional, it is important to have a strong understanding of the command line interface (CLI) and the various tools and utilities that are commonly used in a Linux environment. Here is a list of some essential Linux commands that every DevOps professional should know:

  1. ls: Lists the files and directories in a directory
  2. cd: Changes the current working directory
  3. mkdir: Creates a new directory
  4. touch: Creates a new file
  5. cp: Copies files and directories
  6. mv: Moves or renames files and directories
  7. rm: Deletes files and directories
  8. rmdir: Deletes an empty directory
  9. cat: Displays the contents of a file
  10. less: Displays the contents of a file one page at a time
  11. head: Displays the first few lines of a file
  12. tail: Displays the last few lines of a file
  13. grep: Searches for a specific pattern in a file or multiple files
  14. find: Searches for files based on various criteria (e.g., name, size, modification time)
  15. sort: Sorts the lines of a file
  16. uniq: Removes duplicate lines from a file
  17. tar: Creates or extracts files from a tar archive
  18. gzip: Compresses or decompresses files
  19. chmod: Changes the permissions of a file
  20. chown: Changes the owner of a file

This is just a small sample of the many Linux commands that are available. As a DevOps professional, it is important to continue learning and expanding your knowledge of the CLI and the various tools and utilities that are used in a Linux environment.

Here are some commonly used Linux commands that are useful for DevOps professionals:

ls – This command is used to list the files and directories in a directory.

ls -l

This command is showing the files and directories in the current directory, along with additional information such as file permissions and timestamps.

cd – This command is used to change the current working directory.

cd /etc

This command changes the current working directory to the /etc directory.

mkdir – This command is used to create a new directory.

mkdir devops_dir

This command creates a new directory called devops_dir in the current working directory.

touch – This command is used to create a new empty file.

touch devops_file.txt

This command creates a new empty file called devops_file.txt in the current working directory.

rm – This command is used to remove files and directories.

rm devops_file.txt

This command removes the file devops_file.txt in the current working directory.

rm -rf devops_dir

This command removes the directory devops_dir along with all of its contents in the current working directory.

cp – This command is used to copy files and directories.

cp devops_file.txt devops_file_copy.txt

This command copies the file devops_file.txt and creates a new file called devops_file_copy.txt in the current working directory.

cp -r devops_dir devops_dir_copy

This command copies the directory devops_dir and creates a new directory called devops_dir_copy in the current working directory.

mv – This command is used to move or rename files and directories.

mv devops_file.txt devops_file_new.txt

This command renames the file devops_file.txt to devops_file_new.txt in the current working directory.

mv devops_dir devops_dir_new

This command renames the directory devops_dir to devops_dir_new in the current working directory.

cat – This command is used to display the contents of a file.

cat devops_file.txt

This command displays the contents of the file devops_file.txt in the current working directory.

grep – This command is used to search for a specific string of text within a file or set of files.

grep "devops" devops_file.txt

This command searches for the string “devops” in the file devops_file.txt in the current working directory.

find – This command is used to search for files and directories in a specified location.

find / -name "devops_file.txt"

This command searches for the file devops_file.txt in the root directory ( ) and all of its subdirectories.

ps – This command is used to display information about the currently running processes.

ps aux

This command displays information about all running processes, including the user that started the process and the process’s ID.

kill – This command is used to send a signal to a process to terminate it.

kill -9 <pid>

This command sends the SIGKILL signal to the process with the specified process ID (pid) to terminate it immediately.

cron – This command is used to schedule recurring tasks. This is very useful in scheduling regular backups, running scripts, and more.

crontab -e

This command opens the crontab file for the current user, where you can schedule tasks using a specific syntax.

* * * * * /path/to/script.sh

This example crontab entry will execute the script /path/to/script.sh every minute.

tail – This command is used to display the last few lines of a file. It’s useful to see logs and debug in real-time.

tail -f /var/log/syslog

This command displays the last few lines of the syslog file and continues to watch it for changes, it is useful for monitoring log files in real-time.

These are just a few examples of the many Linux commands that are useful for DevOps professionals. It is important to note that the list is not exhaustive, and there are many other commands and tools that are useful in different situations. It’s important to practice and be familiar with them as much as possible as you work with Linux systems in a DevOps role.

Sure, here are some additional Linux commands that may be useful for DevOps professionals:

apt-get (or yum on Fedora or CentOS) – This command is used to manage packages on a Debian-based or RPM-based Linux distribution. It is commonly used to install, update, or remove software packages.

apt-get update

This command updates the package list and can be run before installing or updating a package to ensure that the latest version is installed.

apt-get install <package_name>

This command installs the specified package.

apt-get remove <package_name>

This command removes the specified package.

systemctl – This command is used to manage system services. It is commonly used to start, stop, restart, or check the status of a service.

systemctl start <service_name>

This command starts the specified service.

systemctl stop <service_name>

This command stops the specified service.

systemctl restart <service_name>

This command restarts the specified service.

systemctl status <service_name>

This command shows the current status of the specified service.

chmod – This command is used to change file permissions. It is commonly used to give or take away access to files and directories.

chmod 755 <file_name>

This command gives the owner of the file full permissions, and gives read and execute permissions to others.

chmod +x <file_name>

This command adds execute permissions to the specified file.

chmod -R 755 <directory_name>

This command gives the owner of the directory full permissions and gives read and execute permissions to others recursively for all files and directories inside the specified directory.

top – This command is used to display real-time performance metrics for the system such as CPU usage, memory usage, and process statistics.

top

This command will open a real-time view of the currently running processes and their resource usage, it’s useful to monitor the health of the system.

wget – This command is used to download files over HTTP, HTTPS, and FTP. It’s useful for automatically downloading files, such as software updates or backups.

wget http://example.com/file.tar.gz

This command will download the file.tar.gz from example.com.

tarThis command is used to create, extract, or list the contents of a tar archive. Tar is a common file format for archives in Linux, it’s useful for compression, backup, or just grouping multiple files into one.

tar -cf archive.tar file1 file2 file3

This command creates a new archive named archive.tar that contains the files file1, file2, and file3.

tar -xf archive.tar

This command extracts the files from the archive archive.tar

These commands provide a brief overview of some of the many Linux commands that are useful for DevOps professionals. It’s essential to practice and gain familiarity with them as much as possible in order to effectively manage Linux systems in a DevOps role.

Shell Scripting

What is Shell?

An Operating system contains many components, but its two prime components are the Kernel and the Shell.

You can consider a Kernel as a nucleus of a computer. It makes communication between the hardware and software possible. The Kernel is the innermost part of an operating system whereas a shell is the outermost one.

A shell in a Linux operating system takes input from the user in the form of commands, processes it, and then gives an output. It acts as an interface through which a user works on programs, commands, and scripts. A terminal accesses the shell and also runs the commands.

When the terminal is run, the Shell issues a command prompt(usually $)where it is possible to type your input, after which the terminal executes it when you hit the Enter key. The terminal then displays the output of your commands.

The Shell wraps as a covering around the delicate interior of an Operating system protecting it from accidental damage. Hence the name is Shell.

There are two main shells in Linux:

  1. The Bourne Shell: The prompt for this shell is $ and its derivatives are as follows:
  • POSIX shell also is known as sh
  • Korn Shell also known as sh
  • Bourne Again SHell is also known as bash (most popular)

2. The C shell: % denotes the prompt for this shell and its subcategories are as follows:

  • C shell also is known as csh
  • Tops C shell is also known as tcsh

What is Shell Scripting?

Shell scripting is a technique in which a programmer writes a series of commands for a Unix-based shell to execute. These commands are typically used for tasks such as file manipulation, program execution, and user interaction. Shell scripts are often used in DevOps as a way to automate common tasks and procedures, such as setting up and maintaining servers, deploying code, and monitoring system performance. They can also be used to automate the process of building, testing, and deploying software.

Shell scripting is writing a series of commands for the shell that can be executed. It can combine both lengthy and repetitive sequences of commands into a single and simple script. You can store this script and execute it whenever you want. This significantly reduces the effort required by the end user.

Here are some common shell scripting commands that are commonly used in DevOps:

  1. ls: Lists the files and directories in a directory.
  2. cd: Changes the current working directory.
  3. mkdir: Creates a new directory.
  4. rmdir: Deletes an empty directory.
  5. touch: Creates a new file.
  6. rm: Deletes a file.
  7. cp: Copies a file or directory.
  8. mv: Moves or renames a file or directory.
  9. grep: Searches for a pattern in a file or a stream of text.
  10. sed: A stream editor for modifying text.
  11. awk: A tool for text processing and pattern matching.
  12. find: Search for files in a directory hierarchy.
  13. chmod: Changes the permissions of a file or directory.
  14. chown: Changes the ownership of a file or directory.
  15. tar: Creates and extracts archive files.
  16. ssh: Secure shell, allows remote login to another computer.
  17. scp: Secure copy, which allows copying files over a network securely.
  18. git: Version control system, used to manage code repositories.
  19. ansible: Automation tool, used to configure and manage servers.
  20. docker: Containerization platform, used to package and deploy applications.

It’s important to note that, this is not a comprehensive list of shell commands, but a general idea of what commands are commonly used in DevOps. Each of these commands has many options that can be used to customize their behavior. And also depending on the specific use case and the environment, a different set of commands and tools may be needed.

Git Commands

What is Git?

Git is a distributed version control system that is widely used in software development and DevOps. It allows multiple developers to work on the same codebase simultaneously and track changes made to the code over time. This enables collaboration and makes it easy for developers to revert to previous versions of the code if needed.

Git also provides a number of powerful tools for managing and merging code changes, such as branching and merging. This allows developers to work on multiple features or bug fixes at the same time without affecting the main codebase. This can help streamline the development process and make it easier for teams to work together.

It’s a vital tool for the DevOps team as it enables them to keep track of versions of their applications, services, and infrastructure they are managing, roll back changes, and collaborate with other teams.

Git architecture-Linux Commands in DevOps-Edureka

Git is a free, open-source distributed version control system. This tool handles everything from small to very large projects with speed and efficiency. Linus Torvalds created it in 2005 to develop the Linux Kernel. Git has the functionality, performance, security, and flexibility that most teams and individual developers need.

Git And Git Work Flows -Linux Commands in DevOps - Edureka

Tools like Git enable communication between the development and the operations team. When you are developing a large project with a huge number of collaborators, it is very important to have communication between the collaborators while making changes to the project. Commit messages in Git plays a very important role in communicating among the team. The bits and pieces that we all deploy lie in the Version Control system like Git. To succeed in DevOps, you need to have all of the communication in Version Control. Hence, Git plays a vital role in succeeding at DevOps.

Git Commands

Here are some common Git commands that are commonly used in a DevOps workflow:

  1. git clone: This command is used to create a local copy of a remote repository. It is typically used when starting to work on a new project or when making changes to an existing one.
  2. git status: This command shows the current status of the local repository, including which files have been modified, added, or deleted.
  3. git diff: This command shows the differences between the current state of the local repository and the last committed version.
  4. git add: This command stages changes for the next commit.
  5. git commit: This command records changes to the local repository. Each commit should have a descriptive message to make it clear what changes were made.
  6. git push: This command sends the committed changes to a remote repository.
  7. git pull: This command is used to synchronize the local repository with the remote repository, by pulling in the changes that were made by other people.
  8. git branch: This command shows the branches available in the repository and the current active branch
  9. git merge: This command merges changes from one branch into another. It’s used to combine the changes made in separate branches, often by different developers, into a single codebase.
  10. git log: This command shows the commit history and can be used to view the details of previous commits, including the author, date, and commit message.

These are just some basic commands, there are many more Git commands which can be used to achieve different tasks, but these commands cover most of the requirements of a DevOps team.

Conclusion:

This blog Linux Commands for DevOps will definitely help you kick-start your journey with DevOps. Now that you have understood what the Linux commands in DevOps are, and know about what is DevOps and gain expertise in various DevOps processes and tools such as Puppet, Jenkins, Nagios, Ansible, Chef, Saltstack, and GIT for automating multiple steps in SDLC.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare

Subscribe to Newsletter

Stay ahead of the rapidly evolving world of technology with our news letters. Subscribe now!