On Fri, Oct 28, 2022 at 09:32:00AM +0700, Max Nikulin wrote: > On 28/10/2022 07:07, Mario Marietto wrote: > > > > find . | cpio --create > I rarely use cpio, but recently there was a thread on tar and unwanted hard > links in the created archive. "find" output mixes regular files and > directories. If the archiver recursively walks through received directories > then result may differ from expectations.
cpio was actually *designed* to be used this way, unlike tar. There's no issue with the snippet quoted above. Of course, this cpio command is incomplete (it needs a redirection to an archive file or something), but the part that's shown is fine. unicorn:~$ mkdir /tmp/x && cd "$_" unicorn:/tmp/x$ mkdir dir; touch dir/file{1,2} unicorn:/tmp/x$ find . | cpio --create | cpio -ivt 1 block drwxr-xr-x 3 greg greg 0 Oct 28 10:46 . drwxr-xr-x 2 greg greg 0 Oct 28 10:46 dir -rw-r--r-- 1 greg greg 0 Oct 28 10:46 dir/file2 -rw-r--r-- 1 greg greg 0 Oct 28 10:46 dir/file1 1 block See? No duplicates. Unlike GNU tar, which recurses into the directory in addition to receiving the already-recursed files from find: unicorn:/tmp/x$ find . | tar -cf - --files-from=- | tar tvf - drwxr-xr-x greg/greg 0 2022-10-28 10:46 ./ drwxr-xr-x greg/greg 0 2022-10-28 10:46 ./dir/ -rw-r--r-- greg/greg 0 2022-10-28 10:46 ./dir/file2 -rw-r--r-- greg/greg 0 2022-10-28 10:46 ./dir/file1 drwxr-xr-x greg/greg 0 2022-10-28 10:46 ./dir/ hrw-r--r-- greg/greg 0 2022-10-28 10:46 ./dir/file2 link to ./dir/file2 hrw-r--r-- greg/greg 0 2022-10-28 10:46 ./dir/file1 link to ./dir/file1 hrw-r--r-- greg/greg 0 2022-10-28 10:46 ./dir/file2 link to ./dir/file2 hrw-r--r-- greg/greg 0 2022-10-28 10:46 ./dir/file1 link to ./dir/file1