# Is there a way to make julia aware of ~ as the home directory on linux

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550>\
**Category:** General Usage\
**Tags:** filesystem\
**Created:** [March 5, 2021, 1:00pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550 "2021-03-05T13:00:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonasjonker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasjonker/32/22535_2.png) [@jonasjonker](https://discourse.julialang.org/u/jonasjonker)\
**Post date:** [March 5, 2021, 1:00pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550/1 "2021-03-05T13:00:03Z")

</div>

I work on a Linux system, meaning that in my mind `~` means home directory.

Sometimes I like to refer to a config file relative to a home folder in any (Linux) system. Which means that writing `~/.config/file.cfg` would be very useful to me.

However Julia/`ispath()` doesn’t seem top recognize this alias. So the following always fails.

```julia
julia> ispath("~/a_file_in_my_home_dir.txt")
false

```

Is there an elegant way for me to solve this? Or do I have to resort to (pointless) things like this:

```julia
julia> ~ = homedir()
julia> isfile("$(~)/a_file_in_my_home_dir.txt")

julia> ispath(joinpath(~, "a_file_in_my_home_dir.txt"))
true

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 5, 2021, 1:05pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550/2 "2021-03-05T13:05:01Z")

</div>

You can do

```julia
ispath(expanduser("~/a_file_in_my_home_dir.txt"))

```

---

<div class="post-metadata">

**Author:** ![jonasjonker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasjonker/32/22535_2.png) [@jonasjonker](https://discourse.julialang.org/u/jonasjonker)\
**Post date:** [March 5, 2021, 1:05pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550/3 "2021-03-05T13:05:52Z")

</div>

Oeh, nice.

Thanks!

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 5, 2021, 1:11pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550/4 "2021-03-05T13:11:40Z")

</div>

> [@jonasjonker](#):
>
> I work on a Linux system, meaning that in my mind `~` means home directory.

I think it is useful to perceive `~` means home to `bash`/`sh`/etc…, most applications or languages do not treat `~` specially, they just appear to do because the `~` expansion happens (in the terminal) before passing the arguments to a custom command. Therefore, Julia is not alone here, on the choice of ignoring `~` leaving it to be expanded by a terminal if it called from a terminal.

Also, Julia tries to be portable, it would be bad practice to have `~` (that appears sometimes in special windows files) always expanding to the home directory.

---

<div class="post-metadata">

**Author:** ![jonasjonker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasjonker/32/22535_2.png) [@jonasjonker](https://discourse.julialang.org/u/jonasjonker)\
**Post date:** [March 5, 2021, 1:27pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550/5 "2021-03-05T13:27:48Z")

</div>

Hoi Henrique,

Thank you for your comment. I’m aware of the fact that bash expands tildes (and a bunch of other brackets and parameters) before passing them on. I do not expect Julia to implement this because I know this is not universally shared across all software and operating systems.

However, it is something I like to use so I was wondering if there was a way for me to still use it.

Just out of curiosity: is the meaning of `..` shared across all/most software? Because this does work in Julia:

```julia
julia> isfile("../a_file.txt")
true

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 5, 2021, 1:43pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550/6 "2021-03-05T13:43:44Z")

</div>

I think in Linux at least this should always work: each process has a “current directory”. When a process asks to open `../a_file.txt`, the kernel will look for `..` in this current directory. And every directory contains an entry `..` which links to the parent directory. So supporting this has nothing to do with the application, it’s part of the filesystem design.

---

<div class="post-metadata">

**Author:** ![jonasjonker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasjonker/32/22535_2.png) [@jonasjonker](https://discourse.julialang.org/u/jonasjonker)\
**Post date:** [March 5, 2021, 1:50pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550/7 "2021-03-05T13:50:51Z")

</div>

Ah, true.

But that means it won’t necessarily work on other operating systems. Good to keep in mind.

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [March 5, 2021, 2:00pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-julia-aware-of-as-the-home-directory-on-linux/56550/8 "2021-03-05T14:00:25Z")

</div>

`../a_file.txt` also works in Windows (10), even though directory separator is `\` in Windows.  
In theory, the portable / better way to write it would be `joinpath("..", "a_file.txt")`, but at least I had no problems with first way so far.
