FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 03-07-2012, 12:39 PM
Randy Kramer
 
Default Understanding the -depth option of find?

In looking at ways of backing up files and directories, I've found (among lots
of other things), the suggestion to use cpio, often in a manner like:

% find . -print -depth | cpio -ov > tree.cpio

In looking at that, I wondered what the -depth parameter does--at first I
worried that it might limit the depth of recursion that would occur, but it
does not.

I found an answer of sorts from info find (quoted below), but I don't really
understand how "printing the directory entries in a directory before the
directory name itself" "limits the effects of restrictive directory
permissions".

I did some googling of that sentence, but all I've found so far are links to
info find.

Can someone explain, provide some hints, or provide a link to an explanation?

<quote from info find>

The `-depth' option forces `find' to print of the entries in a directory
before printing the directory itself. This limits the effects of restrictive
directory permissions by printing the directory entries in a directory before
the directory name itself.

</quote from info find>

Thanks!
Randy Kramer


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 201203070839.05252.rhkramer@gmail.com">http://lists.debian.org/201203070839.05252.rhkramer@gmail.com
 
Old 03-07-2012, 04:51 PM
Camaleón
 
Default Understanding the -depth option of find?

On Wed, 07 Mar 2012 08:39:05 -0500, Randy Kramer wrote:

> In looking at ways of backing up files and directories, I've found
> (among lots of other things), the suggestion to use cpio, often in a
> manner like:
>
> % find . -print -depth | cpio -ov > tree.cpio
>
> In looking at that, I wondered what the -depth parameter does--at first
> I worried that it might limit the depth of recursion that would occur,
> but it does not.
>
> I found an answer of sorts from info find (quoted below), but I don't
> really understand how "printing the directory entries in a directory
> before the directory name itself" "limits the effects of restrictive
> directory permissions".
>
> I did some googling of that sentence, but all I've found so far are
> links to info find.
>
> Can someone explain, provide some hints, or provide a link to an
> explanation?

(...)

Here is a nice and plain explanation (it's for BSD systems but should be
the same for Linux):

http://onlamp.com/pub/a/bsd/2002/03/14/FreeBSD_Basics.html?page=2

"(...) By default, find lists the files it finds by starting at the point
mentioned in the find command, in my case . or my home directory. That
is, it lists first the directory, and then the contents of that
directory. If it encounters a directory that has read-only permissions,
find will still provide a list of the contents of that directory to the
cpio command, but the cpio command won't have permission to replicate the
files in that subdirectory. It is interesting to note that cpio will
still be able to create the directory, but as it does, it will set the
permissions to read only, so it won't be able to create any files below
that directory.

However, if you remember to use -depth, find will instead start its
search at the lowest level, meaning it will list the contents of
directories before it lists the directories themselves. This means that
the files will already have been replicated by cpio before it sets the
read-only permissions on the parent directory."

THT.

Greetings,

--
Camaleón


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: jj877j$ujn$18@dough.gmane.org">http://lists.debian.org/jj877j$ujn$18@dough.gmane.org
 
Old 03-07-2012, 05:37 PM
Randy Kramer
 
Default Understanding the -depth option of find?

Camaleón,

Thanks!

One followup below...

On Wednesday 07 March 2012 12:51:48 pm Camaleón wrote:
> On Wed, 07 Mar 2012 08:39:05 -0500, Randy Kramer wrote:
> > % find . -print -depth | cpio -ov > tree.cpio

> However, if you remember to use -depth, find will instead start its
> search at the lowest level, meaning it will list the contents of
> directories before it lists the directories themselves. This means that
> the files will already have been replicated by cpio before it sets the
> read-only permissions on the parent directory."

I guess that implies I'd better do something about the permissions on that
read-only subdirectory before the next (and each) time I run that find...cpio
command.

Randy Kramer


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 201203071337.12680.rhkramer@gmail.com">http://lists.debian.org/201203071337.12680.rhkramer@gmail.com
 
Old 03-08-2012, 04:06 PM
Camaleón
 
Default Understanding the -depth option of find?

On Wed, 07 Mar 2012 13:37:12 -0500, Randy Kramer wrote:

> On Wednesday 07 March 2012 12:51:48 pm Camaleón wrote:
>> On Wed, 07 Mar 2012 08:39:05 -0500, Randy Kramer wrote:
>> > % find . -print -depth | cpio -ov > tree.cpio
>
>> However, if you remember to use -depth, find will instead start its
>> search at the lowest level, meaning it will list the contents of
>> directories before it lists the directories themselves. This means that
>> the files will already have been replicated by cpio before it sets the
>> read-only permissions on the parent directory."
>
> I guess that implies I'd better do something about the permissions on
> that read-only subdirectory before the next (and each) time I run that
> find...cpio command.

Nothing you should care about when using the mentioned parameter (-depth).

Anyway, I make the backup for my /home directory with plain "tar". What
are the benefits/drawbacks of using "cpio" instead? I remember an ancient
discussion about this and IIRC, cpio could perform crc checksums but it
also had its cons.

Greetings,

--
Camaleón


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: jjaove$ek5$11@dough.gmane.org">http://lists.debian.org/jjaove$ek5$11@dough.gmane.org
 
Old 03-08-2012, 06:38 PM
Randy Kramer
 
Default Understanding the -depth option of find?

On Thursday 08 March 2012 12:06:54 pm Camaleón wrote:
> On Wed, 07 Mar 2012 13:37:12 -0500, Randy Kramer wrote:
> > I guess that implies I'd better do something about the permissions on
> > that read-only subdirectory before the next (and each) time I run that
> > find...cpio command.
>
> Nothing you should care about when using the mentioned parameter (-depth).

Ok, thanks for the followup.

> Anyway, I make the backup for my /home directory with plain "tar". What
> are the benefits/drawbacks of using "cpio" instead? I remember an ancient
> discussion about this and IIRC, cpio could perform crc checksums but it
> also had its cons.

I don't know about any benefits to cpio--I've just been exploring / thinking
about modifying my backup procedures.

Probably the biggest reason I dug into that find ... cpio command was because
find has always been sort of my nemesis--I've always found it aggravating to
use (compared to ms-dos equivalents), and I prefer to use locate whenever
possible.

Randy Kramer



--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 201203081438.06436.rhkramer@gmail.com">http://lists.debian.org/201203081438.06436.rhkramer@gmail.com
 
Old 03-08-2012, 08:56 PM
 
Default Understanding the -depth option of find?

>> On Thu, 8 Mar 2012 17:06:54 +0000 (UTC), <noelamac@gmail.com> said:

C> I make the backup for my /home directory with plain "tar". What are the
C> benefits/drawbacks of using "cpio" instead?

Older versions of tar wouldn't read from stdin or any other list of files,
and they also had really short limits on filename length. Some still do.

I like cpio because it accepts output from "find", a list of files, or any
intermediate filter. I prefer pax because in addition, it'll accept cpio,
ustar, or its own internal format. Other advantages include consistent
behavior and command-line options on FreeBSD, Linux, and Solaris.
Doing things like hourly incremental/differential backups is a snap:

root# touch /backup/etc/drive1

[ ...an hour later... ]
root# cd /drive1
root# dest="$(date '+/backup/drive1/%Y/%m%d/%H%M')"
root# mkdir -p $dest
root# find ./userstuff -depth -newer /backup/etc/drive1 -print |
pax -rwd -pe $dest

In this case, the "-depth" option ensures correct timestamps on all
created directories, and "-pe" preserves owner/group/mode/modtime stuff.

--
Karl Vogel I don't speak for the USAF or my company

Heck, if an omniscient psycho ex offered me discounted, in-stock products I
was going to buy anyway, I might just keep them around. That's everything
Amazon tries to be already, anyway.
--slashdot response to Target data-mining for pregnant customers


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20120308215615.05C7BBFBB@kev.msw.wpafb.af.mil">htt p://lists.debian.org/20120308215615.05C7BBFBB@kev.msw.wpafb.af.mil
 

Thread Tools




All times are GMT. The time now is 04:29 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org