Moving Files (not as simple as it sounds!)

Moving Files (not as simple as it sounds!)

Post by Robert M » Thu, 03 Jul 2003 12:02:42



I have many files in many dirs.

These dirs live in a single dir.

To wit:

Top Dir

   Dir1a
      File1
      File2

   Dir1b
      File1

   Dir2
      File1
      File2
      File3

And so forth.

What I aspire to do is move only the files, not the embedded dirs, into
a brand new dir. A friend passed this command along but for the life of
me I cannot figure out where the problem is:

find . -type f -exec mv {} full-path-to-target-dir

I'd really appeciate some help; I've got files in excess of 300 dirs I
need to move.

Thanks.

 
 
 

Moving Files (not as simple as it sounds!)

Post by Rouben Rostami » Thu, 03 Jul 2003 11:59:06




>What I aspire to do is move only the files, not the embedded dirs, into
>a brand new dir. A friend passed this command along but for the life of
>me I cannot figure out where the problem is:

>find . -type f -exec mv {} full-path-to-target-dir

The -exec construction needs to be terminated by a semicolor.
So change that to:

    find . -type f -exec mv {} full-path-to-target-dir \;

The backslash is there to protect the semicolon from the shell.

--


 
 
 

Moving Files (not as simple as it sounds!)

Post by Nick Hawtho » Thu, 03 Jul 2003 12:09:18



Quote:>find . -type f -exec mv {} full-path-to-target-dir

You need an escaped semi-colon to end the mv command, thus:

find . -type f -exec mv {} full-path-to-target-dir \;

This is mentioned under exec in the manual for find.

Nick Hawthorn

 
 
 

Moving Files (not as simple as it sounds!)

Post by Tim Hammerquis » Thu, 03 Jul 2003 12:05:48


Robert M. graced us by uttering:

Quote:> I have many files in many dirs.

> These dirs live in a single dir.
[ snippage ]
> What I aspire to do is move only the files, not the embedded
> dirs, into a brand new dir. A friend passed this command along
> but for the life of me I cannot figure out where the problem
> is:

> find . -type f -exec mv {} full-path-to-target-dir

Though you don't mention what the problem you're having is (ie,
what errors, if any, do you get?), I'll just suggest placing
single quotes around the {}s:

find . -type f -exec mv '{}' full-path-to-target-dir

If that doesn't help, try including more info.

HTH,
Tim Hammerquist
--
I have discovered that all human evil comes from this, man's being
unable to sit still in a room.
    -- Blaise Pascal

 
 
 

Moving Files (not as simple as it sounds!)

Post by Robert M » Thu, 03 Jul 2003 12:54:23



> The -exec construction needs to be terminated by a semicolor.
> So change that to:

> find . -type f -exec mv {} full-path-to-target-dir \;

That did it!

Also, thanks to Mr. Hawthorn for offering the solution as well.

 
 
 

1. Programming simple file copy, move, and other file mngmnt routines

I am trying to find out if there is a fairly simple way to
do the impliment the following functions (anywhere you see
file below, realize that it could be a directory as well):

Delete: Delete a given file.
Copy:   Copy a source file or directory to a destination
        directory.
Move:   As above, only moving.  Could be implimented as
        a Copy() then Delete().
Chmod:  Change the attributes on a given file.
Touch:  Update a file's last access time, creating an empty
        file if necessary.
Check:  Find out if a file is a regular file, a directory,
        a symbolic link, etc.

Unfortunately, I don't have access to a UNIX programming book
and I can't find anything regarding this stuff on the
'net.  Regarding Copy(), I look at the GNU sources for 'cp'
and got lost really quickly.  I am hoping for something
closer to the Window's API call CopyFile() if it exists or
a 10-20 line set of code that impliments something like
CopyFile().

If worse comes to worse, I could do a system("cp ...")
call if I had to, but I would rather not create another
process if I can help it (not to mention our debugger
chokes stepping across system() calls).

Pointers and help would be greatly appreciated.  If you
know of a book that can answer my questions, that would
be great, too.  WWW sources are always wonderful.

Thanks.

Travis
--
Travis Jensen

Viewpoint Datalabs International, Inc.            Phone: 801-229-3189
---------------------------------------------------------------------
If you eat a live frog in the morning, nothing worse will happen to
either of you for the rest of the day.

2. Nameservers on colocated Linux servers

3. modules not automatically loaded + only have sound for WAV file (sound problem)

4. Console locking?

5. Can not download mails with attachements... sounds simple?!

6. USB

7. Windows 2000 NOT moving into the household moving business

8. Xconfig for Diamond SpeedSTAR

9. '.forward' moves mail !!!; anything that copies and not MOVE?

10. simple banner printing not so simple

11. Linux will not allow me to move files over via FTP?

12. whereis does not work on moved files

13. Making room, which dirs/files may "not" be moved from /usr ?