# Cp -n command

**URL:** <https://community.unix.com/t/cp-n-command/372899>\
**Category:** UNIX for Beginners Q & A\
**Created:** [June 24, 2018, 11:05pm UTC](https://community.unix.com/t/cp-n-command/372899 "2018-06-24T23:05:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zam](https://community.unix.com/letter_avatar/zam/32/6_22734026db12803ebb3e059622ac3534.png) [@zam](https://community.unix.com/u/zam)\
**Post date:** [June 24, 2018, 11:05pm UTC](https://community.unix.com/t/cp-n-command/372899/1 "2018-06-24T23:05:10Z")

</div>

I would like to find a substitute cp -n command in HP-UX

```nohighlight
cp -n 
-n, --no-clobber

```

```
          do not overwrite an existing file \(overrides a previous -i option\)

```

Thanks

---------- Post updated at 12:35 PM ---------- Previous update was at 11:54 AM ----------

I could not find this info in man pages and yes I can write a function to do this but thought to ask in case I missed something

---

<div class="post-metadata">

**Author:** ![rbatte1](https://community.unix.com/letter_avatar/rbatte1/32/6_22734026db12803ebb3e059622ac3534.png) [@rbatte1](https://community.unix.com/u/rbatte1)\
**Post date:** [June 25, 2018, 3:45am UTC](https://community.unix.com/t/cp-n-command/372899/2 "2018-06-25T03:45:11Z")

</div>

Would you like to switch on `-n` by default or prevent it working at all? I'm not sure which way round you mean.

Perhaps you have scripts that use it, but it doesn't work on HP-UX and you want your scripts to be portable. Is that what you are saying?

Sorry for being confused.  
Robin

---

<div class="post-metadata">

**Author:** ![zam](https://community.unix.com/letter_avatar/zam/32/6_22734026db12803ebb3e059622ac3534.png) [@zam](https://community.unix.com/u/zam)\
**Post date:** [June 25, 2018, 5:12am UTC](https://community.unix.com/t/cp-n-command/372899/3 "2018-06-25T05:12:16Z")

</div>

Hi, thanks to reply, I meant that I would prefer to use cp -n option or similar switch on HP-UX if there is one as I did it on Linux. But I could not find it on HP-UX. I thought maybe there is something similar that I am just don't know of.  
I am just saying that if there is nothing like that on HP-UX I will write a small script for that. And it's not a an issue.

Thanks again  
Cheers

---

<div class="post-metadata">

**Author:** ![achenle](https://community.unix.com/letter_avatar/achenle/32/6_22734026db12803ebb3e059622ac3534.png) [@achenle](https://community.unix.com/u/achenle)\
**Post date:** [June 25, 2018, 8:14am UTC](https://community.unix.com/t/cp-n-command/372899/4 "2018-06-25T08:14:43Z")

</div>

"cp -n" is a GNU extension to the [POSIX standard "cp" utility](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cp.html).

As it's a platform-specific, non-standard extension, it's not necessarily going to be available on other, non-GNU platforms.

---

<div class="post-metadata">

**Author:** ![MadeInGermany](https://community.unix.com/letter_avatar/madeingermany/32/6_22734026db12803ebb3e059622ac3534.png) [@MadeInGermany](https://community.unix.com/u/MadeInGermany)\
**Post date:** [June 25, 2018, 1:22pm UTC](https://community.unix.com/t/cp-n-command/372899/5 "2018-06-25T13:22:08Z")

</div>

You can try the trick

```nohighlight
cp -i ... < /dev/null

```

---

<div class="post-metadata">

**Author:** ![wbport](https://community.unix.com/letter_avatar/wbport/32/6_22734026db12803ebb3e059622ac3534.png) [@wbport](https://community.unix.com/u/wbport)\
**Post date:** [June 25, 2018, 2:05pm UTC](https://community.unix.com/t/cp-n-command/372899/6 "2018-06-25T14:05:23Z")

</div>

If the output file doesn't exist, you are good to go. \*  
If the output is a directory, check it for the presence of your input file. \*

- Possible extra check: do you have execute and write permissions in the current or target directory?

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_22734026db12803ebb3e059622ac3534.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [June 25, 2018, 2:35pm UTC](https://community.unix.com/t/cp-n-command/372899/7 "2018-06-25T14:35:46Z")

</div>

> [@madeingermany](#):
>
> You can try the trick
> 
> ```plaintext
> cp -i ... < /dev/null
> 
> ```

Very nifty trick! You might want to suppress the confirmation question as well:

```plaintext
cp -i . . . </dev/null 2>/dev/null

```

EDIT: or even `cp -i . . . </dev/null 2>&0` ?

---

<div class="post-metadata">

**Author:** ![zam](https://community.unix.com/letter_avatar/zam/32/6_22734026db12803ebb3e059622ac3534.png) [@zam](https://community.unix.com/u/zam)\
**Post date:** [June 26, 2018, 3:38am UTC](https://community.unix.com/t/cp-n-command/372899/8 "2018-06-26T03:38:52Z")

</div>

Thank everyone you for your replies, yes it works!

---------- Post updated at 05:08 PM ---------- Previous update was at 05:07 PM ----------

I used this one as it suppresses all output cp -i . . . \</dev/null 2\>&0
