Linux test Command Explained: File Checks, Conditions & Scripting Tricks!

Опубликовано: 06 Май 2026
на канале: TechOps Tutorials
62
0

🔹 Want to master the test command in Linux? In this tutorial, we’ll explore how to use test (and [ brackets) for checking file existence, permissions, string comparisons, and more! Perfect for shell scripting and automation! 🚀

✔️ What You’ll Learn:

How to check if a file or directory exists 📁
Testing if a file is readable, writable, or executable ✅
String comparisons and number conditions 🔢
Combining multiple conditions for better scripting ⚙️

📌 Commands Used in This Video:
Check if a directory exists
if [ -d /backup ]; then echo "Exists"; else echo "Not found"; fi

Check if a file exists
if [ -f "/etc/app/config.yaml" ]; then echo "File exists"; else echo "Missing"; fi

Check if a script is executable
if [ -x "/usr/local/bin/deploy.sh" ]; then echo "Can execute"; else echo "Cannot execute"; fi

Check if a string is empty
if [ -z "$username" ]; then echo "Empty"; else echo "Not empty"; fi

Compare numbers
if [ "$num1" -gt "$num2" ]; then echo "Greater"; else echo "Smaller or equal"; fi

Combine conditions (AND example)
if [ -r "/tmp/test_rw_file" -a -w "/tmp/test_rw_file" ]; then echo "Readable & Writable"; else echo "Not both"; fi

🔔 Want more Linux tips?
💬 Comment your favorite Linux command!
📌 Subscribe & hit the bell 🔔 for more Linux tutorials!
#Linux #BashScripting #LinuxCommands #ShellScripting #techtips