Difference between ./ and ~/

Tot Zam picture Tot Zam · Jul 15, 2015 · Viewed 13.7k times · Source

When creating filepaths and URLs, I noticed that many times the path starts with ./ or ~/.

What is the difference between filepaths that start with ./ and ~/?

What do each of them mean?

Answer

David picture David · Jul 15, 2015

./ means "starting from the current directory". . refers to the current working directory, so something like ./foo.bar would be looking for a file called foo.bar in the current directory. (As a side note, .. means refers to the parent directory of the current directory. So ../foo.bar would be looking for that file one directory above.)

~/ means "starting from the home directory". This could have different meanings in different scenarios. For example, in a Unix environment ~/foo.bar would be looking for a file called foo.bar in your home directory, something like /home/totzam/foo.bar. In many web applications, ~/foo.bar would be looking for a file called foo.bar in the web application root, something like /var/http/mywebapp/foo.bar.