Home Explore Blog CI



nushell

1st chunk of `commands/docs/cp.md`
db21c4df5e9c88c80b3c948106cf253bcca78ebe6d5fd01700000001000008df
---
title: cp
categories: |
  filesystem
version: 0.104.0
filesystem: |
  Copy files using uutils/coreutils cp.
usage: |
  Copy files using uutils/coreutils cp.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `cp` for [filesystem](/commands/categories/filesystem.md)

<div class='command-title'>Copy files using uutils&#x2f;coreutils cp.</div>

## Signature

```> cp {flags} ...rest```

## Flags

 -  `--recursive, -r`: copy directories recursively
 -  `--verbose, -v`: explicitly state what is being done
 -  `--force, -f`: if an existing destination file cannot be opened, remove it and try
                    again (this option is ignored when the -n option is also used).
                    currently not implemented for windows
 -  `--interactive, -i`: ask before overwriting files
 -  `--update, -u`: copy only when the SOURCE file is newer than the destination file or when the destination file is missing
 -  `--progress, -p`: display a progress bar
 -  `--no-clobber, -n`: do not overwrite an existing file
 -  `--preserve {list<string>}`: preserve only the specified attributes (empty list means no attributes preserved)
                    if not specified only mode is preserved
                    possible values: mode, ownership (unix only), timestamps, context, link, links, xattr
 -  `--debug`: explain how a file is copied. Implies -v

## Parameters

 -  `...rest`: Copy SRC file/s to DEST.


## Input/output types:

| input   | output  |
| ------- | ------- |
| nothing | nothing |
## Examples

Copy myfile to dir_b
```nu
> cp myfile dir_b

```

Recursively copy dir_a to dir_b
```nu
> cp -r dir_a dir_b

```

Recursively copy dir_a to dir_b, and print the feedbacks
```nu
> cp -r -v dir_a dir_b

```

Move many files into a directory
```nu
> cp *.txt dir_a

```

Copy only if source file is newer than target file
```nu
> cp -u myfile newfile

```

Copy file preserving mode and timestamps attributes
```nu
> cp --preserve [ mode timestamps ] myfile newfile

```

Copy file erasing all attributes
```nu
> cp --preserve [] myfile newfile

```

Copy file to a directory three levels above its current location
```nu
> cp myfile ....

```

Title: cp Command Summary
Summary
The `cp` command in Nushell is used to copy files and directories. It's based on the uutils/coreutils implementation. It supports flags for recursive copying, verbosity, forcing overwrites, interactive prompts, updating only newer files, displaying progress, preventing overwrites, and preserving file attributes. The command takes source file(s) and a destination as arguments.