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


Groups > alt.os.linux > #54404

Re: Move file with directory structure

From Java Jive <java@evij.com.invalid>
Newsgroups alt.os.linux
Subject Re: Move file with directory structure
Date 2019-03-13 14:43 +0000
Organization Aioe.org NNTP Server
Message-ID <q6b4v6$1dic$1@gioia.aioe.org> (permalink)
References <a6ab8a1c-1d99-4ca1-8993-ac9bbccfe5af@googlegroups.com>

Show all headers | View raw


On 13/03/2019 12:53, Leslie Rhorer wrote:
> I have a little issue, and I am hoping someone here has a simple and elegant solution.  I want to be able to run a BASH script which will prune specific files out of an arbitrary directory by moving the files out of the directory into a holding directory reproducing the entire source directory tree.
> 
> So, for example, say I have a file:
> 
> /Dir1/Dir2/Dir3.../DirN/File to be moved
> 
> There are a number of other files in /Dir1/Dir2/Dir3.../DirN/, but I only want to move the "File to be moved" file, not the entire directory.
> 
> I have a directory in place named /Scrutiny/.  I want to move "File to be moved" to /Scrutiny/Dir1/Dir2/Dir3.../DirN/, but in general /Scrutiny/Dir1/Dir2/Dir3.../DirN/ may not exist.  If I issue a command like
> 
> mv "/Dir1/Dir2/Dir3.../DirN/File to be moved" /Scrutiny/
> 
> Then the file wil just be dumped into the /Scrutiny directory without the tree structure.  I could parse the filespec for its directory structure, issue a mkdir command, and then move the file to the new structure, but is there a more efficient way?

I can't comment on the other suggestions because I haven't tried them.

You'd've thought that this would be possible with rsync, but I've not 
been able to make it work.

Note the following failed examples were tested on a Zyxel NSA221 NAS, as 
being the only Linux machines that I have powered up at the moment, a 
fuller Linux distro might behave better.

Note also that the -n option means 'show what will happen but don't 
actually do it'  -  naturally you'd remove this once you were satisfied 
that the command is going to do exactly what you want.

Note also that the trailing slash in the source designation is required 
to make an rsync command work properly, by which I mean in the way that 
might be expected, so I put one also at the end of the destination, for 
conformity's sake.

One might have hoped that something like the following should work, but 
it doesn't ...

rsync -an --exclude="*" --include="*.not" $SOURCE/ $DEST/

... the problem being that once the --exclude="*" option has ruled out 
everything, no include option can bring it back in, despite what the 
command-line help implies.  This wouldn't be so bad if the following 
worked, but it doesn't either ...

rsync -an --include="*.not" $SOURCE/ $DEST/

... which just copies everything, not just the *.not files, so is 
exactly the same as not giving an include option at all, making one 
wonder:  "WTF is the point of the include option, when it doesn't seem 
to do anything?!"

The only way I've been able to make this sort of thing work with rsync 
is to write a filter file excluding every goddamned thing I don't want 
to copy, which is an extraordinary chore to have to perform for such a 
*simple* requirement.

Tch!

Back to alt.os.linux | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 05:53 -0700
  Re: Move file with directory structure gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-13 13:33 +0000
  Re: Move file with directory structure Joe Beanfish <joebeanfish@nospam.duh> - 2019-03-13 13:47 +0000
  Re: Move file with directory structure Fenris <fenris@invalid.invalid> - 2019-03-13 15:02 +0100
  Re: Move file with directory structure marrgol <marrgol@address.invalid> - 2019-03-13 15:18 +0100
    Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 08:33 -0700
  Re: Move file with directory structure Java Jive <java@evij.com.invalid> - 2019-03-13 14:43 +0000
    Re: Move file with directory structure Chris Elvidge <chris@mshome.net> - 2019-03-13 15:19 +0000
      Re: Move file with directory structure Java Jive <java@evij.com.invalid> - 2019-03-13 16:18 +0000
  Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 08:27 -0700
    Re: Move file with directory structure gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-13 16:12 +0000
    Re: Move file with directory structure William Unruh <unruh@invalid.ca> - 2019-03-13 21:05 +0000
      Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 19:29 -0700
        Re: Move file with directory structure "Carlos E.R." <robin_listas@es.invalid> - 2019-03-14 14:12 +0100
          Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-14 08:34 -0700
    Re: Move file with directory structure "Carlos E.R." <robin_listas@es.invalid> - 2019-03-14 18:22 +0100
  Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 08:37 -0700
    Re: Move file with directory structure William Unruh <unruh@invalid.ca> - 2019-03-13 21:10 +0000
      Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 19:07 -0700

csiph-web