🐧 Important Things to Remember in Linux¶
🔑 1. Root Account Role¶
Root = God Mode trong Linux¶
Root Powers:¶
✅ Toàn quyền truy cập tất cả files/folders
✅ Cài đặt/gỡ bỏ software packages
✅ Thay đổi system configurations
✅ Tạo/xóa user accounts
✅ Kiểm soát services và processes
✅ Truy cập hardware trực tiếp
Access Root:¶
1. Switch User (su):
# Chuyển sang root user
su -
# Hoặc
su root
# Chạy 1 command với root privilege
su -c "systemctl restart nginx"
2. Sudo (Recommended):
# Chạy command với root privilege
sudo systemctl restart nginx
# Chuyển sang root shell tạm thời
sudo -i
# hoặc
sudo su -
# Chỉnh sửa file system
sudo nano /etc/hosts
3. Root Login (Không khuyến khích):
Root Safety Best Practices:¶
# ❌ NGUY HIỂM - Chạy mọi thứ as root
sudo su -
rm -rf /* # 💀 NEVER DO THIS!
# ✅ AN TOÀN - Chỉ dùng sudo khi cần
sudo systemctl status nginx
sudo apt update
sudo nano /etc/nginx/nginx.conf
Sudo Configuration:¶
# Xem sudo privileges
sudo -l
# Thêm user vào sudo group
sudo usermod -aG sudo lelongc
# Chỉnh sửa sudoers file
sudo visudo
# Example sudoers entry:
lelongc ALL=(ALL:ALL) ALL
# lelongc có thể chạy tất cả commands as any user
🔤 2. Case Sensitive¶
Linux phân biệt chữ HOA/thường NGHIÊM NGẶT¶
# Đây là 4 files KHÁC NHAU:
touch file.txt
touch File.txt
touch FILE.txt
touch FiLe.TxT
ls -la
# -rw-rw-r-- 1 lelongc lelongc 0 Aug 12 05:57 FILE.txt
# -rw-rw-r-- 1 lelongc lelongc 0 Aug 12 05:57 FiLe.TxT
# -rw-rw-r-- 1 lelongc lelongc 0 Aug 12 05:57 File.txt
# -rw-rw-r-- 1 lelongc lelongc 0 Aug 12 05:57 file.txt
Commands cũng Case Sensitive:¶
Directories Case Sensitive:¶
# Đây là các thư mục KHÁC NHAU:
mkdir Documents
mkdir documents
mkdir DOCUMENTS
# Navigate phải chính xác case
cd Documents # ✅
cd documents # ✅ nhưng khác folder
cd Documents # ❌ nếu folder tên là documents
Environment Variables:¶
# Case sensitive
echo $PATH # ✅ Hiển thị system PATH
echo $path # ❌ Không có giá trị (nếu chưa set)
echo $Path # ❌ Không có giá trị
# Set variables
export MyVar="Hello"
echo $MyVar # ✅ "Hello"
echo $myvar # ❌ Empty
echo $MYVAR # ❌ Empty
Case Sensitivity Examples:¶
# File operations
cat file.txt # ✅ Đọc file.txt
cat File.txt # ❌ Nếu chỉ có file.txt
cat FILE.TXT # ❌ Nếu chỉ có file.txt
# User accounts
su lelongc # ✅
su LeLongC # ❌ User không tồn tại
su LELONGC # ❌ User không tồn tại
# Package names
sudo apt install nginx # ✅
sudo apt install NGINX # ❌ Package không tồn tại
sudo apt install Nginx # ❌ Package không tồn tại
📁 3. File Name Standards¶
Allowed Characters:¶
# ✅ SAFE characters:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
. (dot)
- (hyphen)
_ (underscore)
File Naming Best Practices:¶
# ✅ GOOD file names:
config.txt
my_script.sh
backup-2025-08-12.tar.gz
user_data.json
server01.conf
nginx.conf
.bashrc
.ssh/
Avoid These Characters:¶
# ❌ PROBLEMATIC characters:
file name.txt # Space (use _ or -)
file$name.txt # $ (shell variable)
file&name.txt # & (background process)
file|name.txt # | (pipe operator)
file>name.txt # > (redirect)
file<name.txt # < (redirect)
file;name.txt # ; (command separator)
file'name.txt # ' (quote)
file"name.txt # " (quote)
file*name.txt # * (wildcard)
file?name.txt # ? (wildcard)
file[name].txt # [] (pattern matching)
Special Files:¶
# Hidden files (bắt đầu với dot)
.bashrc # Bash configuration
.ssh/ # SSH keys directory
.gitignore # Git ignore rules
.vimrc # Vim configuration
# Backup files
file.txt.bak # Manual backup
file.txt~ # Auto backup (editors)
file.txt.orig # Original file backup
# Temporary files
temp.tmp
cache.cache
/tmp/session123
File Extensions Convention:¶
# Scripts
script.sh # Bash script
script.py # Python script
script.pl # Perl script
script.rb # Ruby script
# Configuration
nginx.conf # Nginx config
app.config # Application config
settings.ini # INI format
# Data
data.json # JSON data
data.xml # XML data
data.csv # CSV data
data.sql # SQL dump
# Archives
backup.tar.gz # Compressed archive
files.zip # ZIP archive
project.tar # TAR archive
Length Limitations:¶
# File name limits:
# - Maximum 255 characters for filename
# - Maximum 4096 characters for full path
# ✅ GOOD:
short_name.txt
# ❌ TOO LONG (example):
this_is_a_very_very_very_long_filename_that_might_cause_problems_in_some_systems_and_applications_especially_when_dealing_with_legacy_systems_or_certain_backup_tools_that_have_filename_length_restrictions.txt
Case Strategy:¶
# ✅ CONSISTENT naming strategies:
# 1. lowercase with underscores
my_config_file.txt
user_data_backup.json
system_status_report.log
# 2. lowercase with hyphens
my-config-file.txt
user-data-backup.json
system-status-report.log
# 3. camelCase (ít dùng)
myConfigFile.txt
userDataBackup.json
systemStatusReport.log
Working with Special Characters:¶
# Nếu file có space hoặc special chars:
# ✅ Quote the filename:
cat "file with spaces.txt"
ls "my file.txt"
# ✅ Escape with backslash:
cat file\ with\ spaces.txt
ls my\ file.txt
# ✅ Use tab completion:
cat my<TAB> # Auto-completes and escapes
🎯 Key Takeaways for lelongc¶
1. Root Account:¶
# Luôn nhớ:
sudo command # Safer than su -
sudo -i # Temporary root shell
exit # Always exit root when done
2. Case Sensitivity:¶
# Luôn check case:
ls -la # Xem exact filename
pwd # Check current directory case
which command # Verify command exists
3. File Naming:¶
# Safe naming pattern:
project_name.extension
backup-YYYY-MM-DD.tar.gz
config_file_v1.conf
script_name.sh
💡 Common Mistakes to Avoid¶
Root Account Mistakes:¶
# ❌ DON'T:
sudo su - # Staying in root too long
rm -rf /important/data # Without backup
chmod 777 /etc/passwd # Dangerous permissions
# ✅ DO:
sudo systemctl restart nginx # Specific task
sudo cp file.conf file.conf.bak # Backup first
sudo chmod 644 /etc/passwd # Appropriate permissions
Case Sensitivity Mistakes:¶
# ❌ Assuming case doesn't matter:
cd /HOME/lelongc # Should be /home/lelongc
export path=$PATH # Should be PATH
cat CONFIG.TXT # Should match exact filename
# ✅ Always match exact case:
cd /home/lelongc # Correct path
export PATH=$PATH:/new/path # Correct variable
cat config.txt # Match exact filename
File Naming Mistakes:¶
# ❌ Problematic names:
"my file.txt" # Spaces need quotes
file$var.txt # $ causes confusion
backup file (1).txt # Spaces and parentheses
# ✅ Better alternatives:
my_file.txt # Underscore instead of space
file_var.txt # No special characters
backup_file_1.txt # Clean and clear
🚀 Quick Reference for lelongc¶
# Root operations
sudo command # Run single command as root
sudo -i # Become root temporarily
exit # Exit root shell
# Case-sensitive operations
ls -la # List with exact case
which command # Find exact command
echo $VARIABLE # Exact variable name
# Safe file naming
touch my_file.txt # Underscore for spaces
mkdir backup-$(date +%Y%m%d) # Date in filename
cp file.txt file.txt.bak # Backup with extension
Remember: Linux không tha thứ! Một ký tự sai có thể làm hỏng cả system. Luôn double-check trước khi chạy commands có quyền root! 🔒