DAY 3  >> Embarking on a DevOps Journey: 90 Days Challenge ๐Ÿš€

DAY 3 >> Embarking on a DevOps Journey: 90 Days Challenge ๐Ÿš€

Playing with Files in Linux and understanding File system in Linux :

ยท

4 min read

Files in Linux:

  1. Everything is a File:

    • In Linux, everything is treated as a file, including directories, devices, and even network sockets.

    • This uniformity simplifies interactions with various system components.

๐Ÿ“ ๐Ÿ“„ ๐Ÿ–ฅ๏ธ

  1. File Types:

    • Regular Files: Contain data (text, binary, etc.).

    • Directories: Organize files into a hierarchical structure.

    • Devices: Represent hardware devices (e.g., /dev/sda for the first hard drive).

    • Symbolic Links: Point to other files or directories.

    • Special Files: Represent system resources (e.g., /proc for process information).

๐Ÿ“‚ ๐Ÿ“„ ๐Ÿ”— ๐Ÿ–ฅ๏ธ

  1. File Naming Conventions:

    • Case-sensitive: "File.txt" and "file.txt" are different.

    • Use of special characters: Be cautious with characters like spaces and symbols.

๐Ÿšซ โš ๏ธ

Linux File Structure:

  1. Root Directory (/):

    • Top-level directory containing all other directories and files.

๐Ÿ 

  1. Standard Directories:

    • /bin: Essential binary executables.

    • /etc: Configuration files.

    • /home: User home directories.

    • /var: Variable data (logs, temporary files).

    • /usr: User programs and utilities.

    • /lib: Shared libraries.

๐Ÿ—‚๏ธ ๐Ÿ—ƒ๏ธ ๐Ÿ 

  1. Special Directories:

    • /dev: Device files.

    • /proc: Process information.

    • /sys: Kernel and device configuration.

๐Ÿ”„ ๐Ÿง 

  1. Temporary Directory (/tmp):

    • Temporary files used by applications and users.

โณ ๐Ÿšฎ

Linux File System Security:

  1. File Permissions:

    • Read (r), Write (w), Execute (x):

      • r: View file contents.

      • w: Modify file contents.

      • x: Execute as a program or enter a directory.

    • Permissions for Owner, Group, and Others.

๐Ÿ”’ ๐Ÿ•ต๏ธโ€โ™‚๏ธ

  1. User Ownership (chown):

    • Change the owner of a file or directory.

    • Helps control access to sensitive files.

๐Ÿ‘ค โ†”๏ธ ๐Ÿ‘ฅ

  1. Root Privileges:

    • Root user (superuser) has unrestricted access.

    • Use sudo to execute commands with root privileges.

๐Ÿฆธโ€โ™‚๏ธ ๐Ÿšซ

  1. File System Hierarchy Standard (FHS):

    • Standardizes file and directory names across distributions.

    • Enhances consistency and predictability.

๐Ÿ“œ ๐Ÿ“

  1. Mount Points:

    • Different filesystems can be mounted at specific directories.

    • Improves system organization and security.

๐Ÿ—ป ๐Ÿš—

  1. File Auditing:

    • Some Linux distributions support file auditing.

    • Tracks file access and modifications for security monitoring.

๐Ÿ” ๐Ÿ“

  1. File Encryption:

    • Encryption tools (e.g., LUKS) can secure entire filesystems or individual files.

    • Adds an extra layer of protection for sensitive data.

๐Ÿ” ๐Ÿ“„

The Linux file system, with its uniform treatment of everything as a file and a well-organized structure, contributes to the security and stability of the operating system. Understanding and managing file permissions play a crucial role in securing the Linux environment. ๐Ÿ›ก๏ธ๐Ÿง

Some Useful commands while working with the Linux files.

  1. Viewing a file's content (cat, less, more):

    • cat filename: Displays the entire content of a file.

    • less filename or more filename: Allows you to navigate through large files interactively.

    cat fruits.txt
  1. Changing file permissions (chmod):

    • chmod permissions filename: Changes the access permissions of a file.
    chmod 755 filename
  1. Checking command history (history):

    • history: Displays a list of recently executed commands.
    history
  1. Removing a directory (rmdir, rm -r):

    • rmdir directory_name: Removes an empty directory.

    • rm -r directory_name: Removes a directory and its contents.

    rmdir my_directory
  1. Creating and viewing files (touch, echo, cat):

    • touch filename: Creates an empty file.

    • echo "content" > filename: Adds content to a file.

    • cat filename: Displays the content of a file.

    touch fruits.txt
    echo "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
  1. Displaying top and bottom lines (head, tail):

    • head -n 3 filename: Displays the top three lines of a file.

    • tail -n 3 filename: Displays the bottom three lines of a file.

    head -n 3 fruits.txt
    tail -n 3 fruits.txt
  1. Creating and comparing files (touch, diff):

    • touch filename: Creates an empty file.

    • diff file1 file2: Shows the differences between two files.

    touch Colors.txt
    diff fruits.txt Colors.txt

Text Editors in Linux:

  1. Vim:

    • vim filename: Opens the Vim editor for the specified file.

    • Press i to enter insert mode, make changes, then press Esc and :wq to save and exit.

    vim filename
  1. Nano:

    • nano filename: Opens the Nano editor for the specified file.

    • Use arrow keys to navigate, make changes, then press Ctrl + X, Y, and Enter to save and exit.

    nano filename

File Permissions in Linux:

  1. File Permissions:

    • File permissions in Linux are represented by three sets of characters: owner, group, and others.

    • Each set consists of three characters: r (read), w (write), and x (execute).

  2. Changing File Ownership (chown):

    • chown new_owner:new_group filename: Changes the owner and group of a file.
    chown user1:group1 fruits.txt
  1. Manipulating File Permissions (chmod):

    • chmod +permission or chmod -permission: Adds or removes a specific permission.

    • chmod ugo+rw filename: Gives read and write permissions to owner, group, and others.




    chmod +x script.sh

These commands and concepts form a foundation for working in a Linux environment, especially within the context of your DevOps journey. Feel free to experiment with these commands in your terminal to gain hands-on experience! ๐Ÿš€

ย