在shell脚本中复制和覆盖文件 [英] Copy and overwrite a file in shell script

查看:1749
本文介绍了在shell脚本中复制和覆盖文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将某个文件复制到某个位置,而不考虑目标中是否存在该文件。我试图通过shell脚本复制。但文件没有被复制。我使用以下命令

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 getting copied. I'm using the following command

/ bin / cp -rf / source / file / destination

但不起作用。

推荐答案

,但你可以这样写一个小脚本:

This question has been already discussed, however you can write a little script like this:

#!/bin/bash
if [ ! -d "$2" ]; then
  mkdir -p "$2"
fi
cp -R "$1" "$2"

这篇关于在shell脚本中复制和覆盖文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆