# Write() done but not writing the content in existing file

**URL:** <https://discourse.julialang.org/t/write-done-but-not-writing-the-content-in-existing-file/39412>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 13, 2020, 3:41pm UTC](https://discourse.julialang.org/t/write-done-but-not-writing-the-content-in-existing-file/39412 "2020-05-13T15:41:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [May 13, 2020, 3:41pm UTC](https://discourse.julialang.org/t/write-done-but-not-writing-the-content-in-existing-file/39412/1 "2020-05-13T15:41:50Z")

</div>

Hi, I’d like to write to an existing file.

> touch cmds #ran in linux to creat an empty file

then in Julia I did:

```julia
cmds=open("cmds", "w")
for i in 1:5
    cmd= "echo hello
echo byebye"
    println(cmd)
    #write(cmds, join(cmd,"\t","\n"))
    write(cmds, cmd)

end
close(cmds) #tick appears but the existing file is still empty

```

Could anyone give a hint for what’s wrong?

---

<div class="post-metadata">

**Author:** ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)\
**Post date:** [May 13, 2020, 3:57pm UTC](https://discourse.julialang.org/t/write-done-but-not-writing-the-content-in-existing-file/39412/2 "2020-05-13T15:57:09Z")

</div>

Your code snippet works for me. My guess is that the file you created with `touch` is not in your julia working directory. Note that `open("filename", "w")` will overwrite the contents of “filename” or create that file if it doesn’t exist. So if your julia working directory is not the directory where you ran `touch cmds`, then when you run `cmds = open(“cmds”, “w”) in julia it’s actually creating a new file called cmds.

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [May 13, 2020, 5:27pm UTC](https://discourse.julialang.org/t/write-done-but-not-writing-the-content-in-existing-file/39412/3 "2020-05-13T17:27:06Z")

</div>

Thank you, so I checked with `readdir()` and `pwd()` before running the codes.

> [@Pbellive](#):
>
> create that file if it doesn’t exist.

In this case, after running the codes are still empty when I checked in linux(Ubuntu).

However, this problem is solved after `ls` in linux. The empty file started being written. (though have no idea why–can `ls` refresh linux subtly?)
