How to ignore specified directories and files when cp directory

When backing up the ltedecoder program, you need to copy this directory to the bak directory, but there is a large file in the decoder directory, which does not need to be backed up, and there is a log problem, and no backup is required. How to achieve it? ?

method:  

   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.

The meaning of this paragraph is: when the name is found as .snapshot, prune will return true, -o means or, the technique of "or" is that when the expression on the left is "true", the right side will not be calculated When the expression on the left is false, the expression on the right is calculated, that is, when the name on the left is not .snapshot, the expression on the right is performed, and the expression on the right means the print file name (including the path) ; When the name is found as .snapshot, the file name is not printed, so that the files that are not named .snampshot are printed out and handed over to cpio for processing, and cpio copies these files into the dest-dir of the rule. Ignore the copying of the .snampshot file (note: the file refers to the folder or file name).

         expand:

-prune -o ... -print0

 

“... -print0”

Here you can use find parameters to find files, such as -name, -size, etc.

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

The above not only ignores the Persistence directory, but also ignores files or folders containing log, and also ignores files larger than 100M.

find. -name \ .git -prune -o -print0 | cpio -pmd0 / dest-dir

If the file name contains a. Sign, add a wildcard \

Note: You must have noticed that the "." after find represents the current directory, that is, this command must be pwd in the directory you want to copy. If you copy the files in sour-dir, you need to cd $sour first -dir.

Guess you like

Origin blog.csdn.net/pan0755/article/details/108119576