Absolute vs Relative Paths
Part of the Fundamentals section of Coddy's Terminal journey — lesson 7 of 82.
When navigating the filesystem, you can refer to a location in two ways: using an absolute path or a relative path.
Absolute Path — starts from the root of the filesystem (/). It always points to the same location no matter where you currently are:
cd /home/documentsAn absolute path always begins with /.
Relative Path — starts from your current directory. It depends on where you are right now:
cd documentsIf you are currently in /home, this will take you to /home/documents.
Comparing the two:
- If you are in
/homeand want to go to/home/documents:
Absolute:cd /home/documents
Relative:cd documents
- If you are in
/home/documentsand want to go up one level:
Absolute:cd /home
Relative:cd ..
Special relative path symbols:
.— refers to your current directory
..— refers to the parent directory (one level up)
cd ./documents # same as: cd documents
cd .. # go up one levelChallenge
BeginnerNavigate to the documents folder using an Relative Path, then print your current location using pwd.
Cheat sheet
There are two ways to refer to a location in the filesystem:
Absolute Path — starts from the root (/) and always points to the same location:
cd /home/documentsRelative Path — starts from your current directory:
cd documentsSpecial relative path symbols:
.— current directory..— parent directory (one level up)
cd ./documents # same as: cd documents
cd .. # go up one levelTry it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline