• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Prayer

            在一般中尋求卓越
            posts - 1256, comments - 190, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
            https://blog.csdn.net/bugouyonggan/article/details/11962201

            轉(zhuǎn):http://blog.yikuyiku.com/?p=2659

             

            基本上,在Makefile里會(huì)用到install,其他地方會(huì)用cp命令。

            它們完成同樣的任務(wù)——拷貝文件,它們之間的區(qū)別主要如下:

            1、最重要的一點(diǎn),如果目標(biāo)文件存在,cp會(huì)先清空文件后往里寫入新文件,而install則會(huì)先刪除掉原先的文件然后寫入新文件。這是因?yàn)橥?使用的文件中寫入內(nèi)容可能會(huì)導(dǎo)致一些問題,比如說寫入正在執(zhí)行的文件可能會(huì)失敗,比如說往已經(jīng)在持續(xù)寫入的文件句柄中寫入新文件會(huì)產(chǎn)生錯(cuò)誤的文件。而使用 install先刪除后寫入(會(huì)生成新的文件句柄)的方式去安裝就能避免這些問題了;

            2、install命令會(huì)恰當(dāng)?shù)靥幚砦募?quán)限的問題。比如說,install -c會(huì)把目標(biāo)文件的權(quán)限設(shè)置為rwxr-xr-x;

            3、install命令可以打印出更多更合適的debug信息,還會(huì)自動(dòng)處理SElinux上下文的問題。

             

            轉(zhuǎn):http://blog.csdn.net/stevenliyong/article/details/4663583

             

            install  - copy files and set attributes

            install 在做拷貝的同時(shí),設(shè)置attributes.

             

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

             

            例如

            @install -d /usr/bin

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

             

            相當(dāng)于

            @mkdir -p /usr/bin

            @cp targets /usr/bin

            @chmod 755 /usr/bin/targets

            @touch /usr/bin/tagets       <---- 更新文件時(shí)間戳

             

            install 命令好強(qiáng)大啊。

            另外@前綴的意思是不在控制臺(tái)輸出結(jié)果。

             

            轉(zhuǎn)載:http://www.cnblogs.com/wwwsinagogogo/archive/2011/08/15/2139124.html

             

            【概述】

            Install和cp類似,都可以將文件/目錄拷貝到指定的地點(diǎn)。但是,install允許你控制目標(biāo)文件的屬性。install通常用于程序的makefile,使用它來將程序拷貝到目標(biāo)(安裝)目錄。

            【語法】

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

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

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

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

            *如果指定了兩個(gè)文件名, `install' 將第一個(gè)文件拷貝到第二個(gè)

            * 如果使用了 `--target-directory' (`-t') 選項(xiàng),或者如果最后一個(gè)文件是一個(gè)目錄并且沒有使用`--no-target-directory' (`-T')選項(xiàng), `install'將每一個(gè)源文件拷貝到指定的目錄,目標(biāo)文件名與SOURCE文件名相同。

            * 如果使用了 `--directory' (`-d') 選項(xiàng), `install' 將逐級(jí)創(chuàng)建缺失的目標(biāo)目錄

            【常用選項(xiàng)】

            -s:對(duì)待拷貝的可執(zhí)行文件進(jìn)行strip操作,取出文件中的符號(hào)表。(一般在做成nand rom時(shí)去除符號(hào)表,NFS時(shí)為了調(diào)試方便,一般不會(huì)使用此選項(xiàng))

            -d(--directory):創(chuàng)建制定的目錄結(jié)構(gòu)(逐級(jí)創(chuàng)建)。如,指定安裝位置為/usr/local/aaa/bbb,/usr/loacal已存在,install會(huì)幫助我們創(chuàng)建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.6 with “cp ... /lib/libc.so.6”, 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.



            記得在大學(xué)的時(shí)候在編譯LFS 6 的時(shí)候, 一直搞不懂 install 的命令 和 cp 以及和 chmod, chgrp 的區(qū)別? 


            工作之后才明白一個(gè)Running 的進(jìn)程不能隨便進(jìn)行 cp , 經(jīng)常會(huì)提示  "text busy", 運(yùn)維部的前輩們給的建議是采用mv 來替代 cp , 今天看起來前輩好像不知道install 這個(gè)命令啊. 

            今天就簡單介紹一下 install 命令. 



            install copy 文件列表且同時(shí)能夠設(shè)置文件的屬性(包括 owner, group) , 通常用在 Makefiles 中 用來copy 程序到指定的目錄.  

            常見的用法有以下3中形式: 
            1:  install  -d [option]   DIRECTORY [DIRECTORY...]  支持多個(gè). 類似 mkdir -p  支持遞歸. 
            例如:  install -d a/b/c e/f  結(jié)果和 mkdir -p  a/b/c  e/f 一樣.  
            2: install [option]  SOURCE DEST 
            復(fù)制 SOURCE  文件(測試不能是目錄)   到DEST file(文件) . 
            install  a/e   c   結(jié)果類似  cp  a/e  c   # 注意c必須是文件. 
            有用選項(xiàng) -D
            install -D x a/b/c    # 效果類似 mkdir -p a/b  && cp  x a/b/c  
            3: install [option]  SOURCE [SOURCE...] DIRECTORY
            復(fù)制  多個(gè)SOURCE 文件到目的目錄.  
            install a/*  d   其中 d 是目錄. 

            有用選項(xiàng)
             -b :自動(dòng)備份. 
            -m : 設(shè)置安裝文件的權(quán)限
            -p :保留文件的timestamps. 也就是說文件的timestaamps 和 source 文件一樣.  當(dāng)我們想要利用安裝文件的mtime來跟蹤文件的build時(shí)間而不是 安裝時(shí)間. 
            -s : Strip the symbol tables from installed binary executables.
            -S : 備份文件的后綴. 
            install  -S .bak new  old  #old 文件自動(dòng)被 mv 為 old.bak. 
            -v: verbose ,打印install 的文件的詳細(xì)信息. 
            `-c'
                 Ignored; for compatibility with old Unix versions of `install'.  #用來兼容舊版的unix. 

            -C: (大寫) 
            安裝文件, 但是如果目標(biāo)文件和源文件一樣( 判斷方法需要看看代碼確認(rèn)) 就跳過, 這樣的好處是 能夠保持一樣文件的mtime.  

            一级a性色生活片久久无| 精品久久久无码人妻中文字幕| 97精品依人久久久大香线蕉97| 99久久精品免费看国产一区二区三区| 欧美日韩精品久久久免费观看| 免费精品久久天干天干| 男女久久久国产一区二区三区 | 精品熟女少妇AV免费久久| 亚洲精品无码久久久影院相关影片| 亚洲欧美成人综合久久久| 久久久久综合网久久| 久久九色综合九色99伊人| 亚洲综合日韩久久成人AV| 久久久久久久尹人综合网亚洲| 伊人久久精品影院| 久久97精品久久久久久久不卡| 久久伊人精品青青草原日本| 久久精品青青草原伊人| 国产ww久久久久久久久久| 久久久久人妻一区二区三区| 秋霞久久国产精品电影院| 一本久久a久久精品亚洲| 久久天天躁狠狠躁夜夜2020老熟妇 | 青青草原综合久久| 国内精品综合久久久40p| 精品久久久无码中文字幕| 久久精品99久久香蕉国产色戒 | 久久只这里是精品66| 97久久精品人人澡人人爽 | 久久国产精品99精品国产| 老男人久久青草av高清| 性做久久久久久久久久久| 青青草原综合久久大伊人导航| 成人国内精品久久久久一区| 亚洲αv久久久噜噜噜噜噜| 久久影视国产亚洲| 久久99精品久久久久久齐齐 | 91精品国产91热久久久久福利| 久久SE精品一区二区| 久久久亚洲欧洲日产国码是AV| 久久强奷乱码老熟女|