Bird
0
0

You want to create a script that always saves logs to a folder named logs inside the current user's home directory, regardless of who runs it. Which path should you use inside the script?

hard📝 Application Q9 of 15
Linux CLI - Navigating the File System
You want to create a script that always saves logs to a folder named logs inside the current user's home directory, regardless of who runs it. Which path should you use inside the script?
A/logs
B/home/logs
C~/logs
D$HOME/logs
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment variables vs shortcuts in scripts

    In scripts, ~ may not always expand correctly, but $HOME reliably points to the current user's home directory.
  2. Step 2: Choose the path that works in scripts

    Using $HOME/logs ensures the logs folder is inside the user's home, regardless of who runs the script.
  3. Final Answer:

    $HOME/logs -> Option D
  4. Quick Check:

    Use $HOME in scripts for home directory paths [OK]
Quick Trick: Use $HOME, not ~, inside scripts for home paths [OK]
Common Mistakes:
  • Using ~ which may not expand in scripts
  • Using absolute paths not user-specific
  • Using root or system folders

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes