Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #176279 > unrolled thread

Duplicating a partition's directory structure - How?

Started byRichard Owlett <rowlett@cloud85.net>
First post2017-01-03 12:20 +0100
Last post2017-01-03 19:30 +0100
Articles 9 — 6 participants

Back to article view | Back to linux.debian.user


Contents

  Duplicating a partition's directory structure - How? Richard Owlett <rowlett@cloud85.net> - 2017-01-03 12:20 +0100
    Re: Duplicating a partition's directory structure - How? Sven Joachim <svenjoac@gmx.de> - 2017-01-03 12:30 +0100
      Re: Duplicating a partition's directory structure - How? Dan Ritter <dsr@randomstring.org> - 2017-01-03 13:00 +0100
      THANK YOU! - was [Re: Duplicating a partition's directory structure -  How?] Richard Owlett <rowlett@cloud85.net> - 2017-01-03 14:10 +0100
    Re: Duplicating a partition's directory structure - How? hdv@gmail <hdv.jadev@gmail.com> - 2017-01-03 14:30 +0100
      Re: Duplicating a partition's directory structure - How? Richard Owlett <rowlett@cloud85.net> - 2017-01-03 14:40 +0100
      Re: Duplicating a partition's directory structure - How? Charlie <ariestao1@ipstarmail.com.au> - 2017-01-03 23:50 +0100
    Re: Duplicating a partition's directory structure - How? hdv@gmail <hdv.jadev@gmail.com> - 2017-01-03 14:30 +0100
    Re: Duplicating a partition's directory structure - How? Jörg-Volker Peetz <jvpeetz@web.de> - 2017-01-03 19:30 +0100

#176279 — Duplicating a partition's directory structure - How?

FromRichard Owlett <rowlett@cloud85.net>
Date2017-01-03 12:20 +0100
SubjectDuplicating a partition's directory structure - How?
Message-ID<sVvii-5p4-9@gated-at.bofh.it>
I wish to duplicate a partition's directory structure without any 
of the existing file contents. The immediate application is a 
heavily customized version of an installation DVD. There are two 
underlying goals. I wish to reuse some existing utilities which 
expect to find data in a particular branch of the directory tree. 
The second is very similar in that a person familiar with a 
structure would assume that certain types of information will be 
in a particular sub-directory.

Also this will be an educational experience as I expect the 
answer will be elegant in its simplicity and point me towards 
chasms in my understanding of Linux.

Thank you.

[toc] | [next] | [standalone]


#176280

FromSven Joachim <svenjoac@gmx.de>
Date2017-01-03 12:30 +0100
Message-ID<sVvrX-5sm-1@gated-at.bofh.it>
In reply to#176279
On 2017-01-03 05:13 -0600, Richard Owlett wrote:

> I wish to duplicate a partition's directory structure without any of
> the existing file contents. The immediate application is a heavily
> customized version of an installation DVD. There are two underlying
> goals. I wish to reuse some existing utilities which expect to find
> data in a particular branch of the directory tree. The second is very
> similar in that a person familiar with a structure would assume that
> certain types of information will be in a particular sub-directory.
>
> Also this will be an educational experience as I expect the answer
> will be elegant in its simplicity and point me towards chasms in my
> understanding of Linux.

Found this solution on [1], it seems to work.

$ rsync -a -f"+ */" -f"- *" source/ destination/

Cheers,
       Sven


1. http://psung.blogspot.com/2008/05/copying-directory-trees-with-rsync.html

[toc] | [prev] | [next] | [standalone]


#176281

FromDan Ritter <dsr@randomstring.org>
Date2017-01-03 13:00 +0100
Message-ID<sVvUZ-5CH-15@gated-at.bofh.it>
In reply to#176280
On Tue, Jan 03, 2017 at 12:28:46PM +0100, Sven Joachim wrote:
> On 2017-01-03 05:13 -0600, Richard Owlett wrote:
> 
> > I wish to duplicate a partition's directory structure without any of
> > the existing file contents. The immediate application is a heavily
> > customized version of an installation DVD. There are two underlying
> > goals. I wish to reuse some existing utilities which expect to find
> > data in a particular branch of the directory tree. The second is very
> > similar in that a person familiar with a structure would assume that
> > certain types of information will be in a particular sub-directory.
> >
> > Also this will be an educational experience as I expect the answer
> > will be elegant in its simplicity and point me towards chasms in my
> > understanding of Linux.
> 
> Found this solution on [1], it seems to work.
> 
> $ rsync -a -f"+ */" -f"- *" source/ destination/

Note:

- a partition doesn't have a directory structure

- a filesystem has a directory structure

- often a filesystem is 1:1 with a partition, but this 
  is not at all guaranteed

- filesystems may span multiple partitions, or have more
  complicated physical representations (LVM, btrfs, zfs, RAID,
  networked filesystems, other systems and combinations thereof)

- the root filesystem has a directory structure which can
  include other mounted filesystems, some of which may not
  represent data from any underlying persistent data storage

In this particular case, you are *likely* to be OK with Sven's solution,
but you will probably want to include other flags to rsync such as -x
(do not cross filesystem mount boundaries) and in other situations
perhaps -D or --specials (handling or ignorance of special file types).

-dsr-

[toc] | [prev] | [next] | [standalone]


#176284 — THANK YOU! - was [Re: Duplicating a partition's directory structure - How?]

FromRichard Owlett <rowlett@cloud85.net>
Date2017-01-03 14:10 +0100
SubjectTHANK YOU! - was [Re: Duplicating a partition's directory structure - How?]
Message-ID<sVx0K-6NW-27@gated-at.bofh.it>
In reply to#176280
On 1/3/2017 5:28 AM, Sven Joachim wrote:
> On 2017-01-03 05:13 -0600, Richard Owlett wrote:
>
>> I wish to duplicate a partition's directory structure without any of
>> the existing file contents. The immediate application is a heavily
>> customized version of an installation DVD. There are two underlying
>> goals. I wish to reuse some existing utilities which expect to find
>> data in a particular branch of the directory tree. The second is very
>> similar in that a person familiar with a structure would assume that
>> certain types of information will be in a particular sub-directory.
>>
>> Also this will be an educational experience as I expect the answer
>> will be elegant in its simplicity and point me towards chasms in my
>> understanding of Linux.
>
> Found this solution on [1], it seems to work.
>
> $ rsync -a -f"+ */" -f"- *" source/ destination/
>
> Cheers,
>         Sven
>
>
> 1. http://psung.blogspot.com/2008/05/copying-directory-trees-with-rsync.html
>

That link was particularly valuable for its description of the 
scope of things that can be accomplished with "filter rules". 
Reading the man page for rsync is more productive for the 
perspective that blog post triggered.

Not only do I have an answer to my specific question but pointers 
to ideas that will simplify achieving my overall goals.

[toc] | [prev] | [next] | [standalone]


#176282

Fromhdv@gmail <hdv.jadev@gmail.com>
Date2017-01-03 14:30 +0100
Message-ID<sVxk6-6WU-23@gated-at.bofh.it>
In reply to#176279
On 2017-01-03 12:13, Richard Owlett wrote:
> I wish to duplicate a partition's directory structure without any of the
> existing file contents. The immediate application is a heavily customized
> version of an installation DVD. There are two underlying goals. I wish to reuse
> some existing utilities which expect to find data in a particular branch of the
> directory tree. The second is very similar in that a person familiar with a
> structure would assume that certain types of information will be in a particular
> sub-directory.
> 
> Also this will be an educational experience as I expect the answer will be
> elegant in its simplicity and point me towards chasms in my understanding of Linux.
> 
> Thank you.

Oops! I just noticed a solution was already given and accepted. Sorry for the noise.

Grx HdV

[toc] | [prev] | [next] | [standalone]


#176285

FromRichard Owlett <rowlett@cloud85.net>
Date2017-01-03 14:40 +0100
Message-ID<sVxtL-70z-5@gated-at.bofh.it>
In reply to#176282
On 1/3/2017 7:22 AM, hdv@gmail wrote:
> On 2017-01-03 12:13, Richard Owlett wrote:
>> I wish to duplicate a partition's directory structure without any of the
>> existing file contents. The immediate application is a heavily customized
>> version of an installation DVD. There are two underlying goals. I wish to reuse
>> some existing utilities which expect to find data in a particular branch of the
>> directory tree. The second is very similar in that a person familiar with a
>> structure would assume that certain types of information will be in a particular
>> sub-directory.
>>
>> Also this will be an educational experience as I expect the answer will be
>> elegant in its simplicity and point me towards chasms in my understanding of Linux.
>>
>> Thank you.
>
> Oops! I just noticed a solution was already given and accepted. Sorry for the noise.
>
> Grx HdV

Not to worry. The script you gave may address another project of 
mine.
Note my stated expectation for "an educational experience" ;}

[toc] | [prev] | [next] | [standalone]


#176293

FromCharlie <ariestao1@ipstarmail.com.au>
Date2017-01-03 23:50 +0100
Message-ID<sVG41-4nb-5@gated-at.bofh.it>
In reply to#176282
On Tue, 3 Jan 2017 14:22:51 +0100 hdv@gmail sent:

> On 2017-01-03 12:13, Richard Owlett wrote:
> > I wish to duplicate a partition's directory structure without any
> > of the existing file contents. The immediate application is a
> > heavily customized version of an installation DVD. There are two
> > underlying goals. I wish to reuse some existing utilities which
> > expect to find data in a particular branch of the directory tree.
> > The second is very similar in that a person familiar with a
> > structure would assume that certain types of information will be in
> > a particular sub-directory.
> > 
> > Also this will be an educational experience as I expect the answer
> > will be elegant in its simplicity and point me towards chasms in my
> > understanding of Linux.
> > 
> > Thank you.  
> 
> Oops! I just noticed a solution was already given and accepted. Sorry
> for the noise.
> 
> Grx HdV


	After contemplation, my reply is:

No noise, but helpfulness.

Thank you,
Charlie

-- 
	Registered Linux User:- 329524
	***********************************************

	I am not afraid of storms, because I am learning to sail my
	ship. --Louise May Alcot.

	***********************************************

	Debian GNU/Linux - Magic indeed.

	-----------------------------------------------------

[toc] | [prev] | [next] | [standalone]


#176283

Fromhdv@gmail <hdv.jadev@gmail.com>
Date2017-01-03 14:30 +0100
Message-ID<sVxk6-6WU-3@gated-at.bofh.it>
In reply to#176279
On 2017-01-03 12:13, Richard Owlett wrote:
> I wish to duplicate a partition's directory structure without any of the
> existing file contents. The immediate application is a heavily customized
> version of an installation DVD. There are two underlying goals. I wish to reuse
> some existing utilities which expect to find data in a particular branch of the
> directory tree. The second is very similar in that a person familiar with a
> structure would assume that certain types of information will be in a particular
> sub-directory.
> 
> Also this will be an educational experience as I expect the answer will be
> elegant in its simplicity and point me towards chasms in my understanding of Linux.
> 
> Thank you.

In cases where I can't use rsync I use this function in bash:

#Make directories based on the contents of a file (one dir per line)
function mkdir_from_file {
  #Verify first argument (source file)
  if [ -z "$1" ]; then
    echo "[ERROR] No file given!"
    return 1
  fi
  if [ ! -f "$1" ]; then
    echo "[ERROR] '$1' is not a file or does not exist!"
    return 1
  fi
  #Read a line from the given file and make a directory using that line as a
  #path. Each line is used "as is". No validity checking is done.
  while read -r LINE; do
    #Skip lines beginning with a hash
    [[ "$LINE" = "\#*" ]] && continue
    #Strip trailing comments and spaces
    LINE="${LINE%%#*}"
    LINE="${LINE%% *}"
    #Skip if no path remains
    [[ "$LINE" == "" ]] && continue
    #Make a dir using the line as a path
    mkdir -p "$LINE"
  done < "$1"
}

You can easily build the input file with find -type d

Sometimes I need to add a new directory structure to systems. In those cases I
just write the wanted dirs to a file and run this script. Maybe you can adjust
it to your needs.

HTH

Grx HdV

[toc] | [prev] | [next] | [standalone]


#176291

FromJörg-Volker Peetz <jvpeetz@web.de>
Date2017-01-03 19:30 +0100
Message-ID<sVC0q-1Og-25@gated-at.bofh.it>
In reply to#176279
In order to separate reading from writing or to store the directory structure
for several writings one can use find and tar:

  find PATH -xdev -type d -print0 \
    | tar cf FILE --no-recursion --null --files-from -

The directories will be stored in the file FILE. It can be extracted with

  tar xpf FILE -C DESTINATION

where directory DESTINATION must already exist.

Regards,
jvp.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web