How to set up a working directory in Julia

Julia's ecosystem comes with a built-in package called File.jl that provides a wide range of methods that allow us to manage and handle operations with the filesystem. Julia provides a full-featured, integrated, and interactive shell read-eval-print loop (REPL) for running these methods. Also, Julia includes Unix-like functionsInclude functions like: cd, pwd, mkdir, rm, etc. for directory navigation and supports pipeliningIn a pipeline, processes are chained together by their standard streams for passing output from each (stdout) directly as input to the next (stdin). as shown in the following examples:

Commands

Purpose

Descriptions


run(ls |> “output.txt”)



Redirecting

The ls command lists all files in the current directory and then redirects its standard output using |> to a text file called output.txt.

run(pipeline(echo 'celeste' & echo 'bassem', sort))


Pipelining

Julia pipes the output from both of the echo commands to the sort program.

Let's explore the commands available to set a working directory in Julia:

  • pwd: Return the current working directory in string format.
    The syntax of this command is pwd().

  • cd: Also known as the current directory, this is used to set the current working directory. If invoked without arguments, it defaults to the home directory.
    This command has two methods of invocation, which are:

    • cd(dir): In this, dir represents the path of the targeted directory.

    • cd(func,dir): With this advanced mode, the current working directory will be temporarily replaced with dir, then the function func will be applied, and finally, the original directory will be restored.

Now, let's explore the detailed process of setting up a working directory in Julia.

Steps

Step 1: Type the julia command in order to start it in command-line REPL mode.

Launch Julia
Launch Julia

Step 2: Run the command pwd() to obtain Julia's current working directory as shown below:

Execute pwd() to get Julia's current working directory
Execute pwd() to get Julia's current working directory

The screenshot above shows that Julia's current working directory is the root folder.

Step 3: Run the mkdir command to create a directory called "Julia_Projects" reserved for our Julia workspace:

Execute mkdir to create a directory
Execute mkdir to create a directory

Step 4: Run the cd command to change Julia's working directory to the one previously created, as shown below:

Execute cd to change Julia's working directory
Execute cd to change Julia's working directory

Step 5: Verify the move to the new directory by running the pwd() command again as displayed below:

Verify the move to the new directory
Verify the move to the new directory

Let's run all the aforementioned commands in the given terminal below.

Terminal 1
Terminal
Loading...

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved