日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

怎样cp文件夹时忽略指定的文件夹和文件

發布時間:2025/3/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 怎样cp文件夹时忽略指定的文件夹和文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

   在備份ltedecoder程序時,須要把此文件夾拷由到bak文件夾下。但decoder文件夾下有個大文件,不須要備份,還有日志問題,也不須要備份,怎樣實現呢??

方法: ?

   cd /source-dir
??????  find . -name .snapshot-prune-o-print0 | cpio -pmd0 /dest-dir
解釋:?This command copies the contents of /source-dir to /dest-dir, but omits files and directories? named? .snapshot (and? anything in them).? The construct-prune -o -print0  is quite common.?The idea here is? that? the? expression? before? -prune ?matches? things? which? are? to be pruned.? However, the -prune action itself returns true, so the following -o ?ensures that the right hand side is evaluated only for those directories which didn't get pruned (the? contents ?of the pruned directories are not even visited, so their contents are irrelevant).? The expression on the right ?hand side of the -o is in parentheses only for clarity.? It emphasises that the -print0 action takes place only for? things? that? didn't have -prune applied to them.? Because the default `and' condition between tests binds more tightly than -o, this is the default anyway, but the parentheses help to show what is going on.

此段的意思是:當找到name為.snapshot時,prune就會返回真。-o是或的意思,“或”的使用技巧是當左邊的表達式為“真”時。則不會運算右邊的表達式。當左邊的表達式為假。則運算右邊的表達式,即,當左邊name不為.snapshot。則進行右邊的表達式,右邊的表達式意思是print文件名稱(包含路徑的);當找到name為.snapshot時,則不打印文件名稱。這樣就實現了把非.snampshot為命名的文件打印出來并交給cpio進行處理。cpio則把這些文件拷則的dest-dir中,實現忽略.snampshot文件的拷備(注:文件指目錄或file名)。

???????? 拓展:

-prune -o ... -print0

“... -print0”

這里能夠使用find的查找文件的參數。如-name,-size等。

find . -name Persistence -prune -o ! -name '*log*' ! -size +100M -print0 | cpio -pmd0 /root/do_bak/ltedecoder

上面則不僅忽略Persistence文件夾,還會忽略包涵log的文件或文件夾,還會忽略大于100M的文件。

注意: 你一定注意到了find 后面是“.”,代表當前文件夾,即此命令必須是pwd是你要拷則的文件夾里面,如你把sour-dir的文件進行拷則,則須要先cd $sour-dir。

轉載于:https://www.cnblogs.com/llguanli/p/7189783.html

總結

以上是生活随笔為你收集整理的怎样cp文件夹时忽略指定的文件夹和文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。