By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
7th IT7th IT
  • Home Technology
    • Home 2
    • Home 3
    • Home 4
    • Home 5
  • Technology
  • Gadget
  • Posts
    • Post Layouts
      • Standard 1
      • Standard 2
      • Standard 3
      • Standard 4
      • Standard 5
      • Standard 6
      • Standard 7
      • Standard 8
      • No Featured
    • Gallery Layouts
      • Layout 1
      • Layout 2
      • Layout 3
    • Video Layouts
      • Layout 1
      • Layout 2
    • Audio Layouts
      • Layout 1
      • Layout 2
      • Layout 3
    • Post Sidebar
      • Right Sidebar
      • Left Sidear
    • Content Features
      • Inline Mailchimp
      • Highlight Shares
      • Print Post
      • Inline Related
    • Auto Load Next Posts
    • Sponsored Post
  • Pages
    • Search Page
    • 404 Page
Search
  • Contact
  • Blog
  • Complaint
  • Advertise
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
Reading: Relative vs. Absolute Path in Linux: What Is the Difference? – MUO – MakeUseOf
Share
Sign In
Notification Show More
Latest News
How to protect your privacy in Windows 11 – Computerworld
Tech news
Linux Foundation Energy Announces New Events, Projects, and … – PR Newswire
Tech news
After Coolwalk, Google Is Silently Working on Another Android Auto … – autoevolution
Tech news
Scalefusion Introduces Linux Device Management – PR Newswire
Tech news
System76 teases features coming in homegrown Rust-based desktop COSMIC – The Register
Tech news
Aa
7th IT7th IT
Aa
  • Tech news
  • Gadget
  • Technology
  • Mobile
Search
  • Home
    • Home 1
    • Home 2
    • Home 3
    • Home 4
    • Home 5
  • Categories
    • Tech news
    • Gadget
    • Technology
    • Mobile
  • Bookmarks
  • More Foxiz
    • Sitemap
Have an existing account? Sign In
Follow US
  • Contact
  • Blog
  • Complaint
  • Advertise
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
7th IT > Blog > Tech news > Relative vs. Absolute Path in Linux: What Is the Difference? – MUO – MakeUseOf
Tech news

Relative vs. Absolute Path in Linux: What Is the Difference? – MUO – MakeUseOf

bukhalifa
Last updated: 2022/11/21 at 4:09 AM
bukhalifa
Share
SHARE

Confused about whether to use relative or absolute path expressions in your next project? Get started by learning the difference between the two.
Absolute and relative path names are two ways to specify the virtual address of a directory or file on Linux. But what's the difference between these two path types, and which one should you use in your commands? Let's find out.
If you've ever used any argument-based Linux command like cd or ls, you'd know there are multiple ways to specify the path to a directory or file.
You might either prefer sticking to normal path expressions or, if you're an advanced Linux user, employ complex regular expressions to pass a file or directory name to a program. Either way, there are only two ways to specify a directory path on Linux: absolute path and relative path.
An absolute path always starts from the root directory and ends at the actual directory or file you want to point to. While using absolute path expression, you need to type all the sub-directory names present inside the hierarchy that lead up to the final location.
For example, if you want to point to /myfolder/folder2 inside the /var/www directory using absolute path expression, you'd use:
…where the / at the beginning of the expression refers to the root directory on Linux.
Relative path, on the other hand, refers to a path expression that uses another path (usually the present working directory) as its root or base. As the name suggests, it is "relative" to an existing path on your system.
For example, if you're currently inside the /var/www directory and need to point to /myfolder/folder2, you'd use:
…where . denotes the current directory you're in. You can change the present working directory using the cd command.
Apart from a single period (.), relative path expressions also employ double periods (..) to refer to the parent directory.
For instance, consider you're inside the /www folder inside the following directory structure:
In the above-stated path expression, . will denote the /www directory whereas .. will point to the /var directory. If there's another directory /random inside /var that you need to access while you're inside /var/www, you'd use:
Simple as that.
Although path expressions may seem simple and unimportant to you as a desktop user, there are various use cases where using the wrong path name might result in a lot of unsolicited inconveniences. Web servers are a good example.
As a web developer working on a project hosted on a Linux server, you need to access files inside the project directory. Here, using relative path expressions is the standard as any change in the sub-directory names or the domain name of the project can lead to broken links.
You can understand this with a simple example that desktop users might relate to better. The / character denotes the root directory on a Linux system. Imagine if you suddenly change that and make the / character point to the home directory. Many of your commands containing absolute path expressions will fail to work since / has now been reassigned to a different directory.
Another advantage of using relative path expressions is since they're relative to the current working directory, it saves you time that you would otherwise spend typing out unnecessary characters.
The only catch here is the complexity and learning curve associated with relative expressions. But that's also common in absolute path expressions; to become a master at using absolute paths, you need to be well-versed with the Linux directory hierarchy. You can use the tree command to view the entire Linux directory tree and make absolute path expressions easier for yourself.
The Linux directory structure is common to all machines running operating systems based on Linux. You can use a command like ls or tree to learn more about how the files and folders are structured on your computer.
Deepesh has a degree in Computer Applications and has been writing about technology for over five years. When not penning down informational guides on Linux, Windows, or Gaming, you can find him secluded in a corner reading books, playing FPS games, or searching for new hobbies to take up, only to quit and find a new one again.

source

You Might Also Like

How to protect your privacy in Windows 11 – Computerworld

Linux Foundation Energy Announces New Events, Projects, and … – PR Newswire

After Coolwalk, Google Is Silently Working on Another Android Auto … – autoevolution

Scalefusion Introduces Linux Device Management – PR Newswire

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share this Article
Facebook Twitter Copy Link Print
Share
Previous Article Android Auto's long-awaited redesign is nearly here — here's how you can take it for a test drive – Android Police
Next Article New attacks use Windows security bypass zero-day to drop malware – BleepingComputer
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow
banner banner
Create an Amazing Newspaper
Discover thousands of options, easy to customize layouts, one-click to import demo and much more.
Learn More

Latest News

How to protect your privacy in Windows 11 – Computerworld
Linux Foundation Energy Announces New Events, Projects, and … – PR Newswire
After Coolwalk, Google Is Silently Working on Another Android Auto … – autoevolution
Scalefusion Introduces Linux Device Management – PR Newswire
//

We influence 20 million users and is the number one business and technology news network on the planet

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

[mc4wp_form id=”1616″]

7th IT7th IT
Follow US

© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.

Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc..

[mc4wp_form]
Zero spam, Unsubscribe at any time.

Removed from reading list

Undo
Welcome Back!

Sign in to your account

Lost your password?