Linux系统中install含义,详解linux中install命令和cp命令的区别

基本上,在Makefile里会用到install,其他地方会用cp命令。

它们完成同样的任务——拷贝文件,它们之间的区别主要如下:

、最重要的一点,如果目标文件存在,cp会先清空文件后往里写入新文件,而install则会先删除掉原先的文件然后写入新文件。这是因为往正在 使用的文件中写入内容可能会导致一些问题,比如说写入正在执行的文件可能会失败,比如说往已经在持续写入的文件句柄中写入新文件会产生错误的文件。而使用 install先删除后写入(会生成新的文件句柄)的方式去安装就能避免这些问题了;

、install命令会恰当地处理文件权限的问题。比如说,install -c会把目标文件的权限设置为rwxr-xr-x;

、install命令可以打印出更多更合适的debug信息,还会自动处理SElinux上下文的问题。

转:http://blog.csdn.net/stevenliyong/article/details/4663583

install - copy files and set attributes

install 在做拷贝的同时,设置attributes.

因此Makefile 中尽量使用install 命令。

例如

@install -d /usr/bin

@install -p -D -m targets /usr/bin

相当于

@mkdir -p /usr/bin

@cp targets /usr/bin

@chmod /usr/bin/targets

@touch /usr/bin/tagets

install 命令好强大啊。

另外@前缀的意思是不在控制台输出结果。

转载:http://www.cnblogs.com/wwwsinagogogo/archive/2011/08/15/2139124.html

【概述】

Install和cp类似,都可以将文件/目录拷贝到指定的地点。但是,install允许你控制目标文件的属性。install通常用于程序的makefile,使用它来将程序拷贝到目标(安装)目录。

【语法】

install [OPTION]... [-T] SOURCE DEST

install [OPTION]... SOURCE... DIRECTORY

install [OPTION]... -t DIRECTORY SOURCE...

install [OPTION]... -d DIRECTORY...

*如果指定了两个文件名, `install' 将第一个文件拷贝到第二个

* 如果使用了 `--target-directory' (`-t') 选项,或者如果最后一个文件是一个目录并且没有使用`--no-target-directory' (`-T')选项, `install'将每一个源文件拷贝到指定的目录,目标文件名与SOURCE文件名相同。

* 如果使用了 `--directory' (`-d') 选项, `install' 将逐级创建缺失的目标目录

【常用选项】

-s:对待拷贝的可执行文件进行strip操作,取出文件中的符号表。(一般在做成nand rom时去除符号表,NFS时为了调试方便,一般不会使用此选项)

-d(--directory):创建制定的目录结构(逐级创建)。如,指定安装位置为/usr/local/aaa/bbb,/usr/loacal已存在,install会帮助我们创建aaa和bbb目录,并把程序安装到指定位置

If we hand write a Makefile, we should always stick to install instead of using cp for the installation commands. Not only is it more convenient, but it does things right (cp does things wrong).

For example, if we attempt to update /bin/bash, which is currently running, with “cp ... /bin/bash”, we get a “text busy” error. If we attempt to update /lib/libc.so. with “cp ... /lib/libc.so.”, then we either get “text busy” (in ancient versions of Linux) or breaks each and every running program within a fraction of a second (in recent versions of Linux). install does the thing right in both situations.

The reason why cp fails is that it simply attempts to open the destination file in write-only mode and write the new contents. This causes problem because Linux (and all contemporary Unices as well as Microsoft Windows) uses memory mapping (mmap) to load executables and dynamic libraries.

The contents of an executable or dynamic library are mmap’d into the linear address space of relevant processes. Therefore, any change in the underlying file affects the mmap’d memory regions and can potentially break programs. (MAP_PRIVATE guarantees changes by processes to those memory regions are handled by COWwithout affecting the underlying file. On the contrary, POSIX leaves to implementations whether COW should be used if the underlying file is modified. In fact, for purpose of efficiency, in Linux, such modifications are visible to processes even though MAP_PRIVATE may have be used.)

There is an option MAP_DENWRITE which disallows any modification to the underlying file, designed to avoid situations described above. Executables and dynamic libraries are all mmap’d with this option. Unfortunately, it turned out MAP_DENYWRITE became a source of DoS attacks, forcing Linux to ignore this option in recent versions.

Executables are mmap’d by the kernel (in the execve syscall). For kernel codes, MAP_DENYWRITE still works, and therefore we get “text busy” errors if we attempt to modify the executable.

On the other hand, dynamic libraries are mmap’d by userspace codes (for example, by loaders like /lib/ld-linux.so). These codes still pass MAP_DENYWRITE to the kernel, but newer kernels silently ignores this option. The bad consequence is that you can break the whole system if you think you’re only upgrading the C runtime library.

Then, how does install solve this problem? Very simple – unlinking the file before writing the new one. Then the old file (no longer present in directory entries but still in disk until the last program referring to it exits) and the new file have different inodes. Programs started before the upgrading (continuing using the old file) and those after the upgrading (using the new version) will both be happy.

记得在大学的时候在编译LFS 的时候, 一直搞不懂 install 的命令 和 cp 以及和 chmod, chgrp 的区别?

工作之后才明白一个Running 的进程不能随便进行 cp , 经常会提示 "text busy", 运维部的前辈们给的建议是采用mv 来替代 cp , 今天看起来前辈好像不知道install 这个命令啊.

今天就简单介绍一下 install 命令.

install copy 文件列表且同时能够设置文件的属性(包括 owner, group) , 通常用在 Makefiles 中 用来copy 程序到指定的目录.

常见的用法有以下3中形式:

: install -d [option] DIRECTORY [DIRECTORY...] 支持多个. 类似 mkdir -p 支持递归.

例如: install -d a/b/c e/f 结果和 mkdir -p a/b/c e/f 一样.

: install [option] SOURCE DEST

复制 SOURCE 文件(测试不能是目录) 到DEST file(文件) .

install a/e c 结果类似 cp a/e c # 注意c必须是文件.

有用选项 -D

install -D x a/b/c # 效果类似 mkdir -p a/b && cp x a/b/c

: install [option] SOURCE [SOURCE...] DIRECTORY

复制 多个SOURCE 文件到目的目录.

install a/* d 其中 d 是目录.

有用选项

-b :自动备份.

-m : 设置安装文件的权限

-p :保留文件的timestamps. 也就是说文件的timestaamps 和 source 文件一样. 当我们想要利用安装文件的mtime来跟踪文件的build时间而不是 安装时间.

-s : Strip the symbol tables from installed binary executables.

-S : 备份文件的后缀.

install -S .bak new old #old 文件自动被 mv 为 old.bak.

-v: verbose ,打印install 的文件的详细信息.

`-c'

Ignored; for compatibility with old Unix versions of `install'. #用来兼容旧版的unix.

-C: (大写)

安装文件, 但是如果目标文件和源文件一样( 判断方法需要看看代码确认) 就跳过, 这样的好处是 能够保持一样文件的mtime.

linux下sort命令使用详解---linux将文本文件内容加以排序命令

转载自:http://www.cnblogs.com/hitwtx/archive/2011/12/03/2274592.html linux下sort命令使用详解---linux将文本文件内容加以排 ...

(转)详解Linux中SSH远程访问控制

详解Linux中SSH远程访问控制 原文:http://blog.51cto.com/dengqi/1260038 SSH:是一种安全通道协议,主要用来实现字符界面的远程登录,远程复制等功能(使用TC ...

详解linux中的ps命令

Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信 ...

【转】命令行浏览器 curl 命令详解,Linux中访问url地址

CURL --- 命令行浏览器 这东西现在已经是苹果机上内置的命令行工具之一了,可见其魅力之一斑 1)二话不说,先从这里开始吧! curl http://www.yahoo.com 回车之后,www. ...

详解Linux中CentOS6.8下解压安装mysql-5.7.14

原文:http://blog.csdn.net/yangle4695/article/details/52185859 mysql下载地址:http://dev.mysql.com/downloads ...

详解webpack中的hash、chunkhash、contenthash区别

hash.chunkhash.contenthash hash一般是结合CDN缓存来使用,通过webpack构建之后,生成对应文件名自动带上对应的MD5值.如果文件内容改变的话,那么对应文件哈希值也会 ...

详解JS中Number()、parseInt()和parseFloat()的区别

三者的作用: Number(): 可以用于任何数据类型转换成数值: parseInt().parseFloat(): 专门用于把字符串转换成数值: 一.Number( ): (1)如果是Boolean ...

linux中常用的60个命令及作用详解

Linux 必学的 60 个命令 Linux 提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作.文件存取.目录操作.进程管理.文件权限设定等.所以,在 Linux 系统上工作离不开使用系统 ...

【Linux 命令】cp 命令详解

Linux 命令之 cp 命令详解 一.cp 命令简介 cp 命令主要用于复制文件或目录.即用来将一个或多个源文件或者目录复制到指定的目的文件或目录. cp 命令可以将单个源文件复制成一个指定文件名的 ...

随机推荐

c# 读取XML数据

1.首先调用接口,要有一个post数据到指定url并返回数据的函数: protected string PostXmlToUrl(string url, string postData) { stri ...

Let'sencrypt认证的网站Https配置

推荐使用这个脚本,具体说明里面都有 https://github.com/xdtianyu/scripts/tree/master/le-dns 它是通过调用dns服务商的api更新txt记录实现,无 ...

【转载】MySQL5.6.27 Release Note解读(innodb及复制模块)

新功能   问题描述(Bug #18871046, Bug #72811): 主要为了解决一个比较“古老”的MySQL在NUMA架构下的“swap insanity”问题,其表现为尽管为InnoDB ...

PEACHPIE 0.9.11 版本发布,可以上生产了

PeachPie在官方博客(https://www.peachpie.io/2018/10/release-0911-visual-studio.html)发布了PeachPie的0.9.11版本 - ...

Java开发笔记(序)章节目录

现将本博客的Java学习文章整理成以下笔记目录,方便查阅. 第一章 初识JavaJava开发笔记(一)第一个Java程序Java开发笔记(二)Java工程的帝国区划Java开发笔记(三)Java帝国的 ...

CopyPropertis

commons-beanutils.jar PropertyUtils.copyProperties(Object dest, Object orig) spring-beans.jar BeanUt ...

[svc]rsync简单部署

安装rsync服务端-backup服务器 yum install rsync -y useradd rsync -s /sbin/nologin -M chown -R rsync.rsync /da ...

plsql连接远程oracle数据库

1.在oracle安装目录D:\app\Eric\product\11.2.0\dbhome_1\NETWORK\ADMIN找到tnsnames.ora:2.ORCL =(DESCRIPTION = ...

LeetCode——11. Container With Most Water

一.题目链接:https://leetcode.com/problems/container-with-most-water/ 二.题目大意: 给定n个非负整数a1,a2....an:其中每一个整数对 ...

对于ntp.conf的理解

允许与我们的时间源同步时间,但是不允许源查询或修改这个系统上的服务. # Permit time synchronization with our time source, but do not # ...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值