20 Basic Linux Commands for DevOps: A Beginner’s Guide

Are you interested in mastering the Linux command line for DevOps purposes? Learn the essential Basic Linux Commands for DevOps in this comprehensive beginner’s guide.

Master the fundamental commands to enhance your DevOps skills

This comprehensive beginner’s guide will walk you through 20 basic Linux commands that every DevOps enthusiast should know.

Whether you’re a beginner or have some experience with Linux, this guide will help you enhance your skills and improve your efficiency.

So, let’s dive into the world of Linux command line!

Introduction

Linux commands play a vital role in the DevOps ecosystem.

They allow developers and system administrators to interact with the operating system efficiently and perform a variety of tasks.

Whether you’re managing servers, deploying applications, or automating processes, having a solid understanding of basic Linux commands is essential.

In this guide, we will cover 20 fundamental Linux commands for DevOps beginners.

1.To Know the OS Type

To determine the type of operating system you are using, use the following command in your terminal:

$ uname -o

This command displays the type of your operating system. For example, if you’re using a Linux-based operating system, it will show “GNU/Linux.

Example Output:

GNU/Linux

2.To Know the CPU Architecture

If you want to find out the CPU architecture of your system, use the following command:

$ uname -m

Executing this command will reveal the CPU architecture, such as “x86_64” for 64-bit systems or “armv7l” for ARM-based systems.

Example Output:

Copy codex86_64

3.To Check the Kernel Version

To check the version of the Linux kernel running on your system, enter the following command:

$ uname -r

Running this command will provide you with the kernel version number, which is crucial for understanding the features and compatibility of your Linux system.

Example Output:

Copy code4.15.0-46-generic

4.To Get the OS Name, Release, Version

To retrieve detailed information about the OS name, release, and version, execute the following command:

$ cat /etc/os-release

This command retrieves the contents of the “/etc/os-release” file, which contains details about your operating system,

such as the name (e.g., “Ubuntu”), release version (e.g., “20.04”), and other pertinent information.

Example Output:

makefileCopy codeNAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"

5.To List the System Hardware

If you want to obtain a comprehensive list of the hardware components in your system, use the following command:

$ lshw

Running this command provides a detailed summary of your system’s hardware configuration, including information about the CPU, memory, storage devices, network adapters, and more.

Example Output:

yamlCopy code*-cpu
    description: CPU
    product: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
    vendor: Intel Corp.
    ...

6.To Get the CPU Details

To retrieve detailed information about your system’s CPU, enter the following command:

$ lscpu

Executing this command will display comprehensive information about your CPU, such as the number of cores, CPU speed, cache sizes, architecture, and other relevant details.

Example Output:

vbnetCopy codeArchitecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
...

7.To Check System Memory

To check the memory usage on your system, you can use the free command with the -h or -m option:

-h - Displays memory in human-readable format (e.g., GB, MB)

-m - Displays memory in megabytes

$ free -h   
or
$ free -m   

Both of these commands provide information about your system’s memory usage, including the total memory, used memory, free memory, and memory used by buffers and cache.

Example Output:

vbnetCopy code              total        used        free      shared  buff/cache   available
Mem:           7.7G        2.9G        3.5G        257M        1.2G        4.0G
Swap:          2.0G          0B        2.0G

8.To Check Virtual Memory Stats

To obtain statistics about the virtual memory usage, you can use the vmstat command with the -S m option:

$ vmstat -S m

This command provides a snapshot of your system’s virtual memory usage, including information about active, inactive, and free memory, as well as swap usage.

Example Output:

cssCopy codeprocs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs  us  sy  id  wa  st
 0  0      0   3612    282   1289    0    0     4    13   22   13   0   0 100   0   0

9.Free Memory Cache, Dentries, and Inodes (with Root Access)

To free up memory cache, dentries, and inodes, you can use the following command:

$ echo 3 > /proc/sys/vm/drop_caches

Executing this command clears the memory cache, dentries, and inodes, which can help improve system performance and free up memory resources.

Note: This command requires root access.

10.To Print Process-Specific Memory Utilizations

If you want to view the memory usage of processes running on your system, use the following command:

$ ps aux --sort=-%mem

This command lists all running processes along with their memory utilization, sorted in descending order. It provides insights into which processes consume the most memory resources.

Example Output:

sqlCopy codeUSER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
john     1672  0.0  5.3 2213304 87620 tty2    Sl+  Jun23   0:19 chrome
...

Must Read: Top 50 Linux Commands Basic To Advance

11.To Search Packages for Installation

To search for packages available for installation, you can use the apt search command followed by the package name:

$ apt search <package name>

This command searches the package repository for packages matching the specified keyword. It helps you find relevant packages that can be installed on your Linux system.

Example:

$ apt search python-boto

12.To Install a Package

To install a package using apt-get, run the following command:

$ sudo apt-get install <package name>

Running this command installs the specified package on your system. Make sure to replace <package name> with the actual name of the package you want to install.

Example:

$ sudo apt-get install python-boto

13.To Uninstall a Package

If you want to remove a previously installed package, use the following command:

$ sudo apt-get remove <package name>

Executing this command removes the specified package from your system, freeing up disk space and ensuring that any associated configurations are also removed.

Example:

$ sudo apt-get remove python-boto

14.To List the Mounted Disk Drives

To view a list of currently mounted disk drives on your system, enter the following command:

$ df -kh

This command displays information about the disk space usage of all mounted file systems, including details such as the total size, used space, available space, and mount point.

Example Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G  4.5G   15G  24% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
...

15.To Mount a Volume

To mount a volume, you need to create a directory first and then use the mount command:

$ mkdir -p <directory path> #Create the DIR to mount the volume
$ sudo mount <src path> <above created dir path>

This command creates a directory to serve as the mount point and then mounts the specified volume or device to that directory.

Example:

$ mkdir -p /mount-vol
$ sudo mount /dev/sdb1 /mount-vol

16.To List the Biggest Files from a Directory

To list the biggest files in a directory, you can use the du, sort, and head commands together:

$ sudo du -a /dir/ | sort -n -r | head -n 5

Running this command calculates the disk usage of each file in the specified directory, sorts them in descending order, and shows the top 5 files with the largest sizes.

Example Output:

56360116    /dir/large_file1.txt
32490343    /dir/large_file2.txt
21785075    /dir/large_file3.txt
...

17. To Find a File in a Directory

If you need to search for a specific file in a directory, use the find command:

$ find <dir path> -name <filename> -print

This command searches the specified directory and its subdirectories for a file with the specified name and displays its path if found.

Example:

$ find /var -name app.log -print

18. To Search for a Text String in a Directory

To search for a specific text string within files in a directory and print the filenames containing that string, use the following command:

$ find /var -type f -print | xargs grep <search text>

Executing this command searches all files in the specified directory and its subdirectories for occurrences of the specified text string and displays the filenames along with the matching lines.

Example:

$ find /var -type f -print | xargs grep "error"

19. To Find Text String from a Given Directory

To find a text string within files from a given directory, you can use the grep command:

$ grep -rIn <search text> <directory path>

This command recursively searches for the specified text string in all files within the specified directory, displaying the filenames and line numbers of the matching lines.

Example:

$ grep -rIn "Hello, World!" /home/user

20. To Remove a Directory

If you want to delete a directory and its contents, use the following command:

$ rm -r <directory path>

This command recursively searches for the specified text string in all files within the specified directory and its subdirectories, displaying the filenames and line numbers of the matching lines.

Example:

$ rm -r /home/user/mydirectory

With these 20 basic Linux commands, you are equipped with essential tools for navigating and managing your Linux system. Experiment with them, and you’ll become more comfortable and proficient in the world of Linux and DevOps!

Remember, practice makes perfect, and mastering these commands will enhance your productivity as a developer or system administrator. Enjoy your Linux journey!

Leave a Comment

1 × two =