Basic Linux for Beginners

Abhinav PathakAbhinav Pathak
7 min read

Linux, the flexible and secure operating system, is a critical tool for DevOps engineers seeking to streamline workflows, automate tasks, and deploy scalable applications.

It is a free, open-source operating system based on the Linux kernel. It was developed in 1991 by Linus Torvalds and has since become a popular choice for servers, supercomputers, embedded systems, and mobile devices. Linux provides a flexible, customizable environment that is widely used in software development and DevOps.

Why Linux?

Linux is used as a primary operating system for DevOps because it provides a flexible and customizable environment for software development, deployment, and automation. Here are some reasons why Linux is crucial for DevOps:

  1. Open-source nature: Linux is an open-source operating system, which means that its source code is freely available to anyone who wants to modify it. This open-source nature provides DevOps engineers with greater flexibility and customization options.

  2. Command line interface (CLI): Linux's CLI is highly powerful and flexible, which makes it ideal for automation and scripting tasks. The CLI provides DevOps engineers with greater control over the system, enabling them to perform complex tasks with ease.

  3. Package management: Linux provides package management tools such as apt, yum, and pacman, which make it easy to install and manage software packages. This feature enables DevOps engineers to quickly set up and configure their development and deployment environments.

  4. Containerization: Linux supports containerization technologies such as Docker and Kubernetes, which enable DevOps engineers to create, deploy, and manage applications in a portable and scalable manner.

  5. Security: Linux is known for its robust security features, which make it a popular choice for DevOps engineers. With Linux, DevOps engineers can configure and secure their systems to protect against security threats and vulnerabilities.

Overall, Linux's flexibility, customization options, powerful CLI, package management tools, containerization technologies, and security features make it an essential operating system for DevOps engineers.

Now, that we know why Linux is so important for DevOps engineers let's get started with the Linux architecture.

Linux Architecture:

Linux architecture consists of a kernel that interacts with the hardware of a computer and a shell that serves as an interface between the user and the kernel.

The kernel is the core of the Linux operating system, responsible for managing hardware resources such as memory, CPU, and input/output devices. It is the foundation upon which the entire operating system is built.

The shell, on the other hand, is a command-line interface that allows users to interact with the kernel. It receives input from the user and passes it on to the kernel for execution. The shell also displays the output of the executed commands back to the user.

This architecture provides a flexible and modular environment for software development and deployment.

Linux Architecture – TecAdmin

Linux file system hierarchy:

The Linux File System Hierarchy is a standardized directory structure that organizes files and directories on a Linux system.

Linux File System Hierarchy

Below are some key directories:

  • / (root): This is the top-level directory in the file system hierarchy, which contains all other directories and files.

  • /bin: This directory contains essential system binaries that are required for booting and basic system operations.

  • /sbin: This directory contains system binaries that are used for system administration tasks and typically require root-level privileges to run.

  • /etc: This directory contains configuration files for the system and various installed applications.

  • /usr: This directory contains user binaries, libraries, documentation, and other resources that are not essential for system booting and basic operations.

  • /var: This directory contains variable files that change frequently, such as log files, temporary files, and spool directories.

  • /tmp: This directory contains temporary files that are used by applications and can be safely deleted at any time.

  • /home: This directory contains user home directories, which store user-specific files and configurations.

  • /opt: This directory contains optional software packages that are not installed from the system's package manager.

  • /media and /mnt: These directories are used to mount removable media and network shares.

Basic Linux Commands

Here are some basic Linux commands that are commonly used:

  1. cd: Change directory

  2. ls: List files and directories in the current directory

  3. pwd: Print working directory

  4. mkdir: Create a new directory

  5. rm: Remove a file or directory

  6. cp: Copy a file or directory

  7. mv: Move or rename a file or directory

  8. cat: Display the contents of a file

  9. grep: Search for a pattern in a file

  10. top: Display system resource usage and running processes

  11. ps: Display a list of currently running processes

  12. clear: To clear the screen

  13. whoami: Display currently login user name

  14. history: List previously used commands

  15. date: Display time and date

File and Directory:

Create directory:

Command to add directory: mkdir <directory name>

Command to add multiple directories: mkdir <directory name separated by " ">

Command to make a nested directory: mkdir -p <name of parent dir. to child dir. separated by "/">

Create file:

Command to create one file: touch <file name>

Command to create multiple files: touch <file names separated by " ">

Copy or move, files or directories:

Command to copy file or directory: cp <source location> <destination location>

Command to move file or directory: mv <source location> <destination location>

If we move the file to the same location with a different name then the file/directory gets renamed.

Remove file or directory:

Command to remove file: rm <path of the file>

Command to remove directory: rm -r <path of the directory>

here -r stands for recursive. The directory may contain other files of directories, so it is used to remove the recursively.

grep and find:

grep: This command is used to search for a specific pattern or string within a file or multiple files.

Command: grep <pattern> <file/directory>

Below are some common grep commands:

  • grep <pattern> <file/directory>: Search for pattern in file and display matching lines.

  • grep <pattern> <file1> <file2>: Search for pattern in file1 and file2 and display matching lines.

  • grep -r <pattern> <file/directory>: Recursively search for pattern in all files in directory and its subdirectories.

  • grep -i <pattern> <file/directory>: Search for pattern case-insensitively in file.

  • grep -v <pattern> <file/directory>: Search for lines in file that do not contain pattern.

  • grep -c <pattern> <file/directory>: Count the number of lines in file that contain pattern.

  • grep -n <pattern> <file/directory>: Display the line number along with the matching line in file.

  • grep -e <pattern1> -e <pattern2> <file/directory>: Search for lines that contain either pattern1 or pattern2 in file.

find: This command is used to search for files in a directory hierarchy based on various criteria, such as name, size, type, modification time, etc. It can be used to locate files based on a variety of search criteria.

Command: find <path> <option> <expression>

Below are some common find commands:

  • find . -name FILENAME: Search for files with the name filename in the current directory and its subdirectories.

  • find . -type f: Search for regular files in the current directory and its subdirectories.

  • find . -type d: Search for directories in the current directory and its subdirectories.

  • find . -empty: Search for empty files or directories in the current directory and its subdirectories.

  • find . -size +10M: Search for files larger than 10 megabytes in the current directory and its subdirectories.

  • find . -mtime -7: Search for files modified in the last 7 days in the current directory and its subdirectories.

  • find . -user USERNAME: Search for files owned by username in the current directory and its subdirectories.

  • find . -group GROUPNAME: Search for files owned by the group groupname in the current directory and its subdirectories.

Word Count:

The "wc" command is used to count the number of words and lines in a file.

Commands:

wc -l hello.txt (this is used to count the number of lines in the file)

wc -w hello.txt (this is used to count the number of words in the file)

head:

Commands:

head <file path>: Displays the top 10 lines of the file

head -n 15 <file path>: Displays the top specific number of lines of the file

tail <file path>: Displays the bottom 10 lines of the file

tail -n 15 <file path>: Displays the bottom specific number of lines of the file

This is all for this blog see you in the next one.

4
Subscribe to my newsletter

Read articles from Abhinav Pathak directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhinav Pathak
Abhinav Pathak