Cloud Knowledge

Your Go-To Hub for Cloud Solutions & Insights

Advertisement

Essential Linux Commands and Concepts Every User Should Know

Essential Linux Commands and Concepts Every User Should Know

If you’re delving into Linux, understanding its directory structure and key commands is critical for system configuration and management. This blog covers some of the most important aspects, focusing on high-utility directories, user management, permissions, and resource monitoring—all optimized with relevant keywords for Linux enthusiasts.

Understanding the /etc Directory

The /etc directory contains system-wide configuration files essential for managing Linux systems. It houses settings for services, applications, and networking.

Key files in /etc include:

  • /etc/passwd: User account information.

  • /etc/shadow: Encrypted passwords.

  • /etc/hosts: Maps hostnames to IP addresses.

  • /etc/resolv.conf: DNS configuration.

  • /etc/fstab: Filesystem mount points.

  • /etc/ssh/sshd_config: SSH server settings.

What Is the /bin Directory?

The /bin directory contains essential binary executables used by all users. These programs are critical for basic system functionality, including:

  • /bin/ls: List files in a directory.

  • /bin/cp: Copy files.

  • /bin/mv: Move or rename files.

  • /bin/rm: Remove files.

  • /bin/cat: View file contents.

  • /bin/bash: Default shell.

Difference Between /bin and /sbin:

  • /bin: Commands accessible to all users (e.g., ls, cp).

  • /sbin: Commands intended for system administrators (e.g., fdisk, reboot).

User and Permission Management

How to Create a User and Manage Permissions

Create a New User Using adduser (recommended):

sudo adduser username

This creates a user with a home directory and prompts for a password.

Using useradd (manual setup):

sudo useradd -m -s /bin/bash username
sudo passwd username
  • -m: Creates a home directory.

  • -s /bin/bash: Sets the default shell.

Add a User to a Group Groups simplify permission management for multiple users.

sudo usermod -aG groupname username

Example: Grant sudo privileges:

sudo usermod -aG sudo username

Verify group membership:

groups username
File and Directory Permissions

Linux permissions include:

  • Read (r): View file contents.

  • Write (w): Modify files.

  • Execute (x): Run scripts or executables.

View permissions:

ls -l filename

Example output:

-rwxr--r-- 1 user group 1234 Jan 1 12:00 file.txt
  • rwx: Owner permissions.

  • r--: Group permissions.

  • r--: Others’ permissions.

Change permissions:

chmod 755 file.txt
  • 7: Owner (rwx).

  • 5: Group (r-x).

  • 5: Others (r-x).

Change ownership:

sudo chown username:groupname file.txt

Recursive ownership change for directories:

sudo chown -R username:groupname /path/to/directory

Process Management in Linux

A process is any running instance of a program. Efficient process management ensures optimal system performance.

Viewing Processes

  • Check running processes:

    ps aux
  • Real-time monitoring:

top htop # Enhanced UI


**Controlling Processes**
- Kill a process by PID:
```bash
kill PID
  • Force kill:

    kill -9 PID
  • Pause a process:

    kill -STOP PID
  • Resume a paused process:

    kill -CONT PID

Adjusting Process Priorities

  • Start a process with lower priority:

    nice -n 10 command
  • Change priority of a running process:

    renice -n priority -p PID

Disk and Memory Management

Check Disk Space Usage

Use df to check disk space:

df -h

Output example:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       100G   40G   60G  40% /

Check directory sizes with du:

du -sh /path/to/directory

Find largest files:

du -ah / | sort -rh | head -10
Check Memory Usage

Use the free command:

free -h

Real-time monitoring:

top
htop

Conclusion

Mastering Linux commands and directory structures is essential for managing systems effectively. This guide covers everything from user management to resource monitoring, ensuring you’re equipped to handle Linux environments confidently.

Leave a Reply

Your email address will not be published. Required fields are marked *