DAY 3 >> Embarking on a DevOps Journey: 90 Days Challenge ๐
Playing with Files in Linux and understanding File system in Linux :
Files in Linux:
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.
๐ ๐ ๐ฅ๏ธ
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).
๐ ๐ ๐ ๐ฅ๏ธ
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:
Root Directory (/):
- Top-level directory containing all other directories and files.
๐
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.
๐๏ธ ๐๏ธ ๐
Special Directories:
/dev: Device files.
/proc: Process information.
/sys: Kernel and device configuration.
๐ ๐ง
Temporary Directory (/tmp):
- Temporary files used by applications and users.
โณ ๐ฎ
Linux File System Security:
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.
๐ ๐ต๏ธโโ๏ธ
User Ownership (
chown
):Change the owner of a file or directory.
Helps control access to sensitive files.
๐ค โ๏ธ ๐ฅ
Root Privileges:
Root user (superuser) has unrestricted access.
Use
sudo
to execute commands with root privileges.
๐ฆธโโ๏ธ ๐ซ
File System Hierarchy Standard (FHS):
Standardizes file and directory names across distributions.
Enhances consistency and predictability.
๐ ๐
Mount Points:
Different filesystems can be mounted at specific directories.
Improves system organization and security.
๐ป ๐
File Auditing:
Some Linux distributions support file auditing.
Tracks file access and modifications for security monitoring.
๐ ๐
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.
Viewing a file's content (
cat
,less
,more
):cat filename
: Displays the entire content of a file.less filename
ormore filename
: Allows you to navigate through large files interactively.
cat fruits.txt
Changing file permissions (
chmod
):chmod permissions filename
: Changes the access permissions of a file.
chmod 755 filename
Checking command history (
history
):history
: Displays a list of recently executed commands.
history
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
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
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
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:
Vim:
vim filename
: Opens the Vim editor for the specified file.Press
i
to enter insert mode, make changes, then pressEsc
and:wq
to save and exit.
vim filename
Nano:
nano filename
: Opens the Nano editor for the specified file.Use arrow keys to navigate, make changes, then press
Ctrl + X
,Y
, andEnter
to save and exit.
nano filename
File Permissions in Linux:
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), andx
(execute).
Changing File Ownership (
chown
):chown new_owner:new_group filename
: Changes the owner and group of a file.
chown user1:group1 fruits.txt
Manipulating File Permissions (
chmod
):chmod +permission
orchmod -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! ๐