Read-only rootfs (Was Re: Multiple partition)

Bill's LFS Login lfsbill at wlmcs.com
Thu Sep 18 05:19:26 PDT 2003


On Wed, 17 Sep 2003, Archaic wrote:

> On Wed, Sep 17, 2003 at 09:09:16PM -0400, Bill's LFS Login wrote:
> >
> > So you mean the <whatever>/*? If you'll refresh mu memory about what kind
> > of matches you're looking to make, I'll give it a shot. In this
> > particular example, if <whatever> = testdir, then when a directory named
> > testdir/<something> is encountered, a 'rm -rf testdir/<something> is
> > run. Also, if a file is found, a 'rm -rf <filename>' is run. This takes
> > care of cleaning out any directories found under testdir and any files
>
> /tmp sometimes has hidden files and dirs. Without deleting /tmp itself,
> I want to delete all files and dirs (hidden and unhidden) with one find
> command. The construct of find I can handle. The regex to locate _all_
> files and dirs inside /tmp without trying to delete . and .. is what I
> have a problem with.

Find expressions operate a little differently than the normal bash
pathname expressions. So with find it is actually easer than when you
run some command like 'cp -av <pathname expression>' or 'rm -rf
<pathname expression>'. The below looks like it might do nicely.

Wrapping disabled for this example.

$ find mytest -ls
178496    2 drwxrwxr-x   5 lfsbill  lfsbill      2048 Sep 18 08:09 mytest
178499    2 drwxrwxr-x   2 lfsbill  lfsbill      2048 Sep 18 08:09 mytest/c
178505    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/c/1
178506    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/c/.2
178501    2 drwxrwxr-x   2 lfsbill  lfsbill      2048 Sep 18 08:09 mytest/d
178507    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/d/3
178508    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/d/.4
178502    2 drwxrwxr-x   2 lfsbill  lfsbill      2048 Sep 18 08:09 mytest/.f
178510    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/.f/5
178511    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/.f/.6
178503    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/a
178504    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/b
178509    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/.e

$ find mytest \( -type d -path 'mytest/*' -o -type f \) -exec rm -rf {} \;
find: mytest/c: No such file or directory
find: mytest/d: No such file or directory
find: mytest/.f: No such file or directory
$

$ find mytest -ls
178496    2 drwxrwxr-x   2 lfsbill  lfsbill      2048 Sep 18 08:11 mytest
$

The error messages are a result of the way in which find recurses. They
can be ignored or directed somewhere, of course.

A better solution is to add the -depth to the find command.

$ find mytest -ls
178496    2 drwxrwxr-x   5 lfsbill  lfsbill      2048 Sep 18 08:17 mytest
178499    2 drwxrwxr-x   2 lfsbill  lfsbill      2048 Sep 18 08:17 mytest/c
178501    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/c/1
178502    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/c/.2
178503    2 drwxrwxr-x   2 lfsbill  lfsbill      2048 Sep 18 08:17 mytest/d
178504    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/d/3
178505    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/d/.4
178506    2 drwxrwxr-x   2 lfsbill  lfsbill      2048 Sep 18 08:17 mytest/.f
178507    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/.f/5
178508    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/.f/.6
178509    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/a
178510    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/b
178511    0 -rw-rw-r--   1 lfsbill  lfsbill         0 Sep 18 08:09 mytest/.e

$ find mytest -depth \( -type d -path 'mytest/*' -o -type f \) \
     -exec rm -rf {} \;
$ find mytest -ls
178496    2 drwxrwxr-x   2 lfsbill  lfsbill      2048 Sep 18 08:18 mytest
$

Watcha' think? Does that whup it?

-- 
Bill Maltby
lfsbill at wlmcs.com



More information about the blfs-support mailing list