Gentoo Archives: gentoo-user

From: Michael Mol <mikemol@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Recreating a directory structure and indicating a files presence
Date: Thu, 20 Sep 2012 16:07:14
Message-Id: CA+czFiDqRQM-5eqwVLxVA5eKq4XK=8uqbN4U6wNLwk8UrHpnVQ@mail.gmail.com
In Reply to: Re: [gentoo-user] Recreating a directory structure and indicating a files presence by Pandu Poluan
1 On Thu, Sep 20, 2012 at 11:54 AM, Pandu Poluan <pandu@××××××.info> wrote:
2 >
3 > On Sep 20, 2012 10:04 PM, "Michael Mol" <mikemol@×××××.com> wrote:
4 >>
5 >> On Thu, Sep 20, 2012 at 10:48 AM, Neil Bothwick <neil@××××××××××.uk>
6 >> wrote:
7 >> > On Thu, 20 Sep 2012 16:13:08 +0200, Alan McKinnon wrote:
8 >> >
9 >> >> On the archive:
10 >> >>
11 >> >> find /root/of/dir/structure -type d > dirs.txt
12 >> >> find /root/of/dir/structure -type f > files.txt
13 >> >
14 >> > This will add '/root/of/dir/structure' to the start of each path. would
15 >> > it be better to do?
16 >> >
17 >> > cd /root/of/dir/structure
18 >> > find -type d > ../dirs.txt
19 >> > find -type f > ../files.txt
20 >>
21 >> I see your path correction, and raise you:
22 >> * whitespace-safe folders
23 >> * Automatic copy to remote system.
24 >> * Automatic new file and folder creation
25 >> * Using those pretty xargs parameters.
26 >>
27 >> cd /root/of/dir/structure
28 >> find . -type d -print0 > ~/dirs.txt
29 >> find . -type d -print0 > ~/files.txt
30 >>
31 >> scp dirs.txt files.txt remote.system:
32 >>
33 >> ssh remote.system <<ENDSSH
34 >> cd /root/of/new/structure
35 >> cat ~/dirs.txt|xargs -0 mkdir -p
36 >> cat ~/files.txt|xargs -0 touch
37 >> ENDSSH
38 >>
39 >>
40 >
41 > Cool... except that your raise is invalid (should've used -type f in the 3rd
42 > line)...
43 >
44 > ;-)
45 >
46
47 Heh. It's also performing a bunch of unnecessary mkdir commands. I
48 mean, "find -type d" isn't going to return a subpath of a folder until
49 it's first returned the folder, so -p is unnecessary. For a better
50 speed gain, you'd want to keep -p, but filter out any folder which has
51 a subfolder, to reduce the number of mkdir commands issued. It's
52 possible mkdir performs this optimization internally, though. And I
53 don't know how to quickly do that filter on the command line.
54
55 --
56 :wq

Replies