Copy and overwrite a file in shell script

后端 未结 4 2003
醉梦人生
醉梦人生 2021-02-07 16:29

I want to copy a certain file to a location, irrespective of that file already exists in the destination or not. I\'m trying to copy through shell script.But the file is not get

4条回答
  •  走了就别回头了
    2021-02-07 16:58

    Your problem might be caused by an alias for cp command created in your system by default (you can see al your aliases by typing "alias"). For example, my system has the following alis by default: alias cp='cp -i', where -i overrides -f option, i.e. cp will always prompt for overwriting confirmation.

    What you need in such case (that'll actually work even if you don't have an alias) is to feed "yes" to that confirmation. To do that simply modify your cp command to look like this:

    yes | cp /source/file /destination

提交回复
热议问题