Linux cp 实现强行覆盖

原文:http://blog.chinaunix.net/uid-223060-id-2215407.html

发现在Fedora 10 /ubutun 里面用cp -fr src dest,即使加了-f也是不能强行覆盖的,这时怎么回事的呢?一两个文件还好说,就输几个yes吧,但是要是n多文件怎么办?下面提供三种解决办法。

方法一

我们输入alias命令,看看系统给cp起了一个什么别名。

[root@localhost ~]# alias
alias cp=’cp -i’
alias l.=’ls -d .* –color=auto’
alias ll=’ls -l –color=auto’
alias ls=’ls –color=auto’
alias mv=’mv -i’
alias rm=’rm -i’
alias which=’alias | /usr/bin/which –tty-only –read-alias –show-dot –show-tilde’

然后[root@localhost ~]# man cp
看看-i什么意思
-i, –interactive   prompt before overwrite
原来在覆盖之前会提示,那我们的解决办法也出来了,用unalias cp来解除cp的别名,还原纯净的cp。
[root@localhost ~]#unaslias cp   (这只是临时取消cp的别名,不是永久的)
[root@localhost ~]#cp -fr src dest       这下就行了,就不会提示覆盖了。

方法二

输入\cp命令,作用也是取消cp的别名。
[root@localhost ~]#\cp -fr src dest

方法三

输入yes|cp -fr src dest,使用管道自动输入yes。
[root@localhost ~]#yes | cp cp -fr src dest   让管道自动输入一大堆得yes,就可以完成了强行复制了。
那有人会问dos的copy命令怎么实现强行复制的呢?答案是
用来 xcopy /y src dest 来实现强行复制。

centos7下编译安装libiconv-1.14 error: ‘gets’ undeclared here (not in a function)

centos7下编译安装libiconv-1.14报错,信息如下:

In file included from progname.c:26:0:
./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
 ^
make[1]: *** [progname.o] Error 1
make[1]: Leaving directory `/root/lnmp1.2/source/libiconv-1.14/srclib'
make: *** [all] Error 2

解决方法:
编辑 libiconv-1.14/srclib/stdio.h 文件,这个文件在make之后才会生成,源码中是没有的。

1007 /* It is very rare that the developer ever has full control of stdin,
1008 so any use of gets warrants an unconditional warning. Assume it is
1009 always declared, since it is required by C89. */
1010 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

第1010行,把 _GL_WARN_ON_USE (gets, “gets is a security hole – use fgets instead”); 删掉
改为:

#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif

变成如下:

继续make && make install 通过