From a command to start:
find ~ -depth -print0 |cpio --null -ov -F /tmp/tree1.cpio
(1)find ~ -depth
find ~ -depth What does it mean?
[root@localhost test]# man find -depth Process each directory's contents before the directory itself. The -delete action also implies -depth.
Before processing the contents of sub-directory under the directory is processed first.
That is when without -depth, the process procedure is to first deal with the directory itself, and then processing sub-content directory. Plus without -depth parameter affects the output order of the output structure.
In fact, just check out the different order.
[root@localhost ~]# mkdir -p test/test1/test2/test3 [root@localhost ~]# find test -depth test/test1/test2/test3 test/test1/test2 test/test1 test
[root@localhost ~]# find test
test
test/test1
test/test1/test2
test/test1/test2/test3
So when we file in archive home directory, use find ~ -depth expressed archive start subdirectory Find archived until the top-level directory.
expand:
In addition to the depth and mindepth there maxdepth
[root@localhost ~]# find test -depth test/test1/test2/test3 test/test1/test2 test/test1 test [root@localhost ~]# find test -maxdepth 2 test test/test1 test/test1/test2 [root@localhost ~]# find test -mindepth 2 test/test1/test2 test/test1/test2/test3
Thus maxdepth mun (digital) layer represents the maximum number of directory lookup, mindepth num (digital) represents the minimum number of layers to find the directory; we say, find a file, look for in order to save time, we can set the depth of such a lookup directory.
(2)find ~ -depth -print0
-print0 What does it mean?
[root@localhost ~]# find test -depth test/test1/test2/test3 test/test1/test2 test/test1 test [root@localhost ~]# find test -depth -print0 test/test1/test2/test3test/test1/test2test/test1test[root@localhost ~]#
We can see that the use of -print0 will find the contents of the presentation of numbers to form a whole line, so why do it?
In case of default, find the default behind each result add a "\ n" (new line), the resulting output is line by line, but if there are spaces in the file name or line breaks, content find output will two lines, affecting the accuracy of the archive. To prevent this from happening, we need to use -print0 parameters, and then in conjunction with cpio resolution null character "--null" parameters to ensure the consistency of the archived data.
For example: We create a file " File 1 .txt", which is a file, the file name spaces [root @ localhost the Test] # Touch " File 1.txt " [root @ localhost the Test] # LS File 1 .txt test1 use find locate this file and delete [root @ localhost the Test] # find the -depth -name. file * | xargs RM RM : Can not delete " ./file " : no such file or directory RM : Can not delete " 1.txt " : no such file or directory
I made a discovery, "file 1.txt" file is identified became 1.txt file and two files. Archiving is the same reason, if you encounter a file name that has spaces, will be connected to the archive documents, undermining the consistency of the archive.