Verified Jobs Live
Unix / Linux Easy Level ~3 min read

How do absolute and relative paths differ, and why does the working directory matter in scripts?

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

An absolute path starts at the filesystem root, while a relative path is interpreted from the process’s current working directory. A script launched by a scheduler or service may start in a different directory from an interactive shell, making relative paths fail or target the wrong file. Resolve paths deliberately from configuration or a known script location, and quote shell variables containing paths. Avoid assuming a user’s home directory or interactive environment is available. Use explicit checks before writing or deleting anything based on a constructed path.