• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            在linux中install命令和cp命令的區別

            Posted on 2018-11-28 17:03 Prayer 閱讀(303) 評論(0)  編輯 收藏 引用 所屬分類: C/C++LINUX/UNIX/AIXmakefile
            https://blog.csdn.net/bugouyonggan/article/details/11962201

            轉:http://blog.yikuyiku.com/?p=2659

             

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

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

            1、最重要的一點,如果目標文件存在,cp會先清空文件后往里寫入新文件,而install則會先刪除掉原先的文件然后寫入新文件。這是因為往正在 使用的文件中寫入內容可能會導致一些問題,比如說寫入正在執行的文件可能會失敗,比如說往已經在持續寫入的文件句柄中寫入新文件會產生錯誤的文件。而使用 install先刪除后寫入(會生成新的文件句柄)的方式去安裝就能避免這些問題了;

            2、install命令會恰當地處理文件權限的問題。比如說,install -c會把目標文件的權限設置為rwxr-xr-x;

            3、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 0755 targets /usr/bin

             

            相當于

            @mkdir -p /usr/bin

            @cp targets /usr/bin

            @chmod 755 /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.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.



            記得在大學的時候在編譯LFS 6 的時候, 一直搞不懂 install 的命令 和 cp 以及和 chmod, chgrp 的區別? 


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

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



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

            常見的用法有以下3中形式: 
            1:  install  -d [option]   DIRECTORY [DIRECTORY...]  支持多個. 類似 mkdir -p  支持遞歸. 
            例如:  install -d a/b/c e/f  結果和 mkdir -p  a/b/c  e/f 一樣.  
            2: 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  
            3: 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.  

            少妇人妻88久久中文字幕| 国产成人精品久久综合 | 久久精品国产亚洲AV无码麻豆| 热久久视久久精品18| 99久久这里只精品国产免费| 久久精品国产日本波多野结衣| 精品人妻久久久久久888| 一本色道久久88加勒比—综合| 久久久久国产精品嫩草影院 | 精品久久久久久中文字幕| 国产成人精品久久综合| 色综合久久综合中文综合网| 国产精品99久久不卡| 亚洲精品乱码久久久久久| 91久久香蕉国产熟女线看| 亚洲国产欧美国产综合久久| 久久精品国产亚洲5555| 韩国免费A级毛片久久| 欧美亚洲国产精品久久| 99久久国产主播综合精品 | 久久精品水蜜桃av综合天堂| 久久精品中文字幕一区| 久久国产成人精品麻豆| 天天躁日日躁狠狠久久| 久久婷婷五月综合色奶水99啪| 日韩欧美亚洲综合久久影院d3| 精品亚洲综合久久中文字幕| 7777久久久国产精品消防器材| 久久无码一区二区三区少妇 | 日本WV一本一道久久香蕉| 伊人久久综合热线大杳蕉下载| 精品综合久久久久久888蜜芽| 久久婷婷色综合一区二区| 亚洲欧美国产精品专区久久| 久久久久99精品成人片牛牛影视| 久久99精品久久久久久秒播| 中文精品久久久久国产网址| 国产精品VIDEOSSEX久久发布| 久久er热视频在这里精品| 一本久久a久久精品综合夜夜| 国产精品成人99久久久久|