> ## Documentation Index
> Fetch the complete documentation index at: https://wiki.latch.bio/llms.txt
> Use this file to discover all available pages before exploring further.

# Command Line Interface Data Upload/Download

For more advanced users, a quick way to interact with Latch Data files is through the command line.

### Setup

<Steps>
  <Step title="Install the Latch CLI:">
    ```bash theme={null}
    python3 -m pip install latch
    ```

    <Note>
      The Latch CLI requires Python >=3.8 and \< 3.11.
    </Note>
  </Step>

  <Step title="Next, authenticate your account. This can be done one of two ways:">
    <Tabs>
      <Tab title="On a machine with a browser">
        If you're on a computer where you're logged into console.latch.bio, simply enter `latch login` which will authenticate you through the browser that you're logged into.
      </Tab>

      <Tab title="On a machine without a browser">
        If you are SSH-ing into a computer where you only have command line access, you
        can authenticate by typing `latch login` and pasting in your Latch developer key.

        ### To do this:

        1. First, type `latch login`. You should see the following message in the terminal:

        ```bash theme={null}
        [ec2-user@ip-172-31-85-121 ~]$ latch login
        Go to `https://console.latch.bio/settings/developer`, generate a Personal API Token (or Workspace API Token if you only need to access a single workspace from this machine), and paste it here:


        ```

        1. Navigate to the workspace that you want to work with on [console.latch.bio](https://console.latch.bio). You can do this by clicking on your profile picture on the top left corner, and select your workspace of interest.

                   <img src="https://mintcdn.com/latchbio/rBOhi8AJn1gA0vrv/images/data/cli-1.png?fit=max&auto=format&n=rBOhi8AJn1gA0vrv&q=85&s=7286eb3bd4c465237f6b97ce6cadcd5c" alt="" width="1000" height="296" data-path="images/data/cli-1.png" />

        2. Then go down to account settings on the bottom of the avatar menu.

                   <img src="https://mintcdn.com/latchbio/rBOhi8AJn1gA0vrv/images/data/cli-2.png?fit=max&auto=format&n=rBOhi8AJn1gA0vrv&q=85&s=08049ddacb70af70a28695ea9cb43e37" alt="" width="983" height="387" data-path="images/data/cli-2.png" />

        3. Then go to **[Developer > Access Tokens](https://console.latch.bio/settings/developer)**, generate a Workspace API Token, and copy the value shown (it is only displayed once).

        <img src="https://mintcdn.com/latchbio/OoouYxBmAnXUQpEy/images/data/cli-3.png?fit=max&auto=format&n=OoouYxBmAnXUQpEy&q=85&s=bc0380a419632c245b036319ae179213" className="h-56 border-slate-100 border rounded-md" width="1200" height="619" data-path="images/data/cli-3.png" />

        4. Then on your local computer's terminal, paste in the API token you just copied.
      </Tab>
    </Tabs>
  </Step>

  <Step title="By default, LatchCLI references your personal workspace. To switch workspaces, use the command:">
    ```bash theme={null}
    latch workspace
    ```
  </Step>

  <Step title="Verifiy the authentication works">
    Verify that the authentication works and that you are in the desired workspace by typing:

    ```bash theme={null}
    latch ls
    ```

    Check that the content displayed in the terminal matches your files and folders on [https://console.latch.bio](https://console.latch.bio)
  </Step>
</Steps>

### Copying Data

<Steps>
  <Step title="Upload files from local machine to Latch Data:">
    ```bash theme={null}
    latch cp file.txt latch:///welcome/
    ```

    This uploads `file.txt` and puts it into `welcome/` on Latch.
  </Step>

  <Step title="Download files from Latch Data to local machine:">
    ```bash theme={null}
    latch cp latch:///welcome local_folder/
    ```

    This downloads the contents of `/welcome` on Latch and puts them into `local_folder` on your local computer.
  </Step>

  <Step title="Copy files between two Latch Data paths in the same workspace:">
    ```bash theme={null}
    latch cp latch:///dir1/ latch:///dir2/
    ```

    This copies the contents of `/dir1` on Latch and puts them into `/dir2` on Latch.
  </Step>

  <Step title="Copy Latch Data files between two different workspace:">
    ```bash theme={null}
    latch cp latch://123.account/dir1/ latch://456.account/dir2/
    ```

    This copies the contents of `/dir1` in workspace 123 and puts them into `/dir2` in workspace 456.

    <Tip>You can find the remote path of the file you want to copy in the sidebar of the Latch Console</Tip>

    <img src="https://mintcdn.com/latchbio/rSliEwubl8sq_Ts8/images/data/mount-gcp/path-copy.png?fit=max&auto=format&n=rSliEwubl8sq_Ts8&q=85&s=12ffe56ddca5ae2adcf9ad1b6294da59" className="h-56 border-slate-100 border rounded-md" width="1728" height="1080" data-path="images/data/mount-gcp/path-copy.png" />
  </Step>
</Steps>

### Moving Data

You can also move data between two Latch directories.
For example, the following command will create `file.txt` in `dir2` and remove it from `dir1` in your current workspace.

```bash theme={null}
latch mv latch:///dir1/file.txt latch:///dir2/
```

### Syncing Data

The Latch CLI provides a simple way to sync data from a local directory to a Latch Data directory.
For example, the following command will update the contents of `dir1` in Latch Data with the contents of `local_folder` on your local computer.

```bash theme={null}
latch sync local_folder latch:///dir1
```

If you add files to `local_folder` and rerun the above command, the changes will be reflected in `dir1` in Latch Data. The `sync` command will only upload files when:

1. The file does not exist in the remote directory.
2. The last modified time of the file in the remote directory is older than the last modified time of the file in the local directory.

Note that, by default, the `sync` command will not remove files from the remote directory if they are removed from `local_folder` on your local computer. To allow files to be deleted from the remote directory, use the `--delete` flag:

```bash theme={null}
latch sync --delete local_folder latch:///dir1
```

### Other Commands

* List files in `dir1`:
  ```bash theme={null}
  latch ls latch:///dir1
  ```
* Create directory `dir3`, creating parent directories `dir1` and `dir2` if they do not exist:
  ```bash theme={null}
  latch mkdirp latch:///dir1/dir2/dir3/
  ```
* Recursively remove `dir2` in Latch Data:
  ```bash theme={null}
  latch rmr latch:///dir1/dir2
  ```

### Behavior

<Note>All of the above commands follow the same behavior as their corresponding UNIX command.</Note>

* Using wildcards (\*):
  ```bash theme={null}
  latch cp local_directory/* latch:///latch_folder
  ```
  This copies all content within `local_directory` to `latch_folder`:
  ```
  >>> latch ls latch:///latch_folder
  Size Date Modified Name
    12 29 Feb 00:43  A.txt
    12 29 Feb 00:43  B.txt
  ```

* Using trailing slashes:
  ```bash theme={null}
  latch cp local_directory/ latch:///latch_folder
  ```
  This copies the directory itself and uploads it to `latch_folder`:
  ```
  >>> latch ls latch:///latch_folder
  Size Date Modified Name
      - -             local_directory/
  ```

* Omitting the trailing slash:
  ```bash theme={null}
  latch cp local_directory latch:///latch_folder
  ```
  This has the same behavior as `latch cp local_directory/ latch:///latch_folder`.

### DEPRECATED

The following commands have been deprecated and will not be available for Latch SDK version >= 2.39.2.
To check which version of latch you are using, run `latch --version`.

1. `latch rm` - Use `latch rmr` instead
2. `latch mkdir` - Use `latch mkdirp` instead
3. `latch touch` - No longer supported
4. `latch open` - No longer supported
