Linux Filesystem & Essential Linux Commands

KALPESH MOHANTAKALPESH MOHANTA
4 min read

Linux Directory Structure

  • /: The root (base) directory.

  • /root: The home directory for the root user.

  • /home: The directory containing user home directories.

  • /lib: Contains essential system libraries required to run commands and tools, used by /bin and /sbin.

  • /bin: Contains binary executables. Essential command binaries are stored here.

  • /sbin: Contains system binaries. These are commands that can typically only be accessed by the root user.

  • /usr/bin: Contains non-essential binaries. Software installed via the package manager typically places its executables here.

  • /usr/local/bin:

    • This directory is intended for locally installed software and scripts that are not managed by the system package manager.

    • You will find user-installed software and custom scripts that are intended to be accessible system-wide.

    • Software and scripts manually placed in /usr/local/bin are typically not overwritten by system updates.

  • /var: Contains variable files such as logs, databases, and spool files.

  • /proc: A virtual filesystem providing information about processes and system information.

  • /boot: Contains boot loader files required by the OS. It is generally not modified by users.

  • /dev: Contains device files (hardware interface).

  • /mnt: Directory for mounting external devices.

  • /media: Contains mount points for removable devices.

  • /etc: Contains editable text configuration files. It contains details about the configuration of tools.

  • /sys: A virtual filesystem containing information about hardware and the kernel.

The PATH Variable

The PATH variable in Linux is an environment variable that specifies a list of directories where executable programs are located. When you run a command in the terminal, the system searches through these directories to find the executable file corresponding to that command.

Format of the PATH Variable

The PATH variable consists of a colon (:) separated list of directories. Here's an example:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Example of Setting the PATH Variable

To include a new directory, such as where you have installed Terraform, you can modify the PATH variable as follows:

export PATH=$PATH:/usr/local/terraform

After editing the file, you can apply the changes immediately by sourcing the file:

source ~/.bashrc

Linux Commands

Gaining Root User Access

sudo su -
logout

Finding path

which

Piping Commands

# Use the output of the first command as input for the second
|

Debugging Commands

# Print command in debug mode
set -x

Error Handling in Scripts

# Exit the script when there is an error
set -e

# Exit the script when there is a pipe failure
set -o pipefail

Disk and Memory Usage

# Disk usage in human-readable format
df -h

# Memory usage
free

# Number of processing units
nproc

Real-Time Performance Monitoring

# Monitor performance in real-time
top

# All processes running in the background
ps -ef

Filtering Output

# Basic filtering command
grep

# Powerful filtering and text processing
awk

Retrieving and Downloading Information from the Internet

# Retrieve information from the internet
curl

# Download files from the internet
wget

Searching for Files

# Search for the location of a file
find / -name test.sh

Trapping Signals in Linux

trap

Working with Processes

# List all processes
ps -ef

# Print errors from remote logs
curl ... | grep ...

String Manipulation

# Write number of occurrences of 's' in the word 'missi'
x=missi
grep -o "s" <<<"$x" | wc -l

Scheduling Tasks with Crontab

# Crontab in Linux
Alarm

Editing Files

# Open a file in read-only mode
vim -r test.txt
  • Acts as a shortcut reference to the original file

  • The link can be broken if the original file is deleted or moved

  • Acts as a copy

  • Deleting the original file does not affect the hard link

Network Troubleshooting Utilities

Traceroute
Tracepath

Managing Large Log Files

Logrotate

Filtering JSON Data

# Filter data from JSON
jq

Filtering YAML Data

# Filter data from YAML
yq

Feel free to share and spread the knowledge! ๐ŸŒŸ๐Ÿ˜Š Enjoy Learning! ๐Ÿ˜Š

0
Subscribe to my newsletter

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

Written by

KALPESH MOHANTA
KALPESH MOHANTA

๐Ÿ‘‹ Hi there! Welcome to my DevOps adventure! ๐Ÿš€ I'm Kalpesh, a DevOps Engineer, and I'm thrilled to share my journey in the dynamic world of DevOps and Cloud Technologies. ๐ŸŒ ๐Ÿ”ง Tech Arsenal: CI/CD Automation: Streamlining workflows for seamless deployments. Containers & Orchestration: Docker & Kubernetes. Cloud Platforms: Azure, AWS. Version Control: Git. Configuration Management: YAML, Linux commands. ๐Ÿš€ My Journey: I've had the privilege to work on diverse projects, including a notable deployment for PepsiCo. My expertise spans CI/CD automation, containerization, cloud services, and scripting to enhance system performance and reliability. ๐Ÿ’ก Why Follow Me? Join me as I delve into: Cutting-edge DevOps practices. Automation techniques. Cloud innovations. Tips & tricks for aspiring DevOps professionals. ๐Ÿค Connect & Collaborate: Let's build, learn, and innovate together. Whether you're a fellow tech enthusiast, a professional looking to share insights, or someone eager to learn, let's connect and grow in this vibrant community. ๐Ÿ“ข Follow my LinkedIn & Hashnode blog for insights, tutorials, and updates. Together, we'll embrace the ever-evolving DevOps landscape!