Re: Learning Bash Questions: the MV command



On Tue, 2006-02-28 at 09:26 +0200, Dotan Cohen wrote:
I am trying to learn as I go with bash on a FC4 install. I need to do
two things that are confounding me:

1) I need to move all the photos from a huge, complex tree to one big
directory. Easy:
$ find . -name "*.jpg" -exec mv '{}' /home/dotancohen/big_directory \;
However, there are a few photos that have duplicate file names in
different directories. In this case, it overwrites. That is bad! I
tried adding the -i flag to prompt me, but it takes the next 'mv' as a
response to the prompt, and the next 'mv' fails. Is there a way to
have it not fail the next mv, yet not overwrite? Or better yet, in the
case of duplicate file names, to append something to the end of the
file name, so that it will not be duplicate? Of course, if _that_ file
name is taken, it should append something else, etc. Is this too
complex for Bash?

find . -name "*.jpg" -exec mv --backup=numbered \
'{}' /home/dotancohen/big_directory \;

2) I will then be left with a huge tree with mostly empty directories.
I need to remove the empty directories, but leave those in place that
do contain files. Is there a way to check if a directory is populated
before 'rm'ing it? If the directory contains another directory that
_is_ empty, then of course they should both be deleted. Er, is this
possible?

find . -depth -mindepth 1 -type d \
-exec rmdir --ignore-fail-on-non-empty '{}' \;

Paul.

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list



Relevant Pages

  • Re: Learning Bash Questions: the MV command
    ... I need to move all the photos from a huge, complex tree to one big ... case of duplicate file names, to append something to the end of the ... in this case it overwrites! ...
    (Fedora)
  • Re: GUI limitations - bulk renaming of files
    ... is to name photos with their exif data. ... I don't know of any cameras that do this, ... a great way to never have duplicate file names for photos (unless ... pictures were taken from different cameras at the same second) and the ...
    (comp.sys.mac.advocacy)
  • Quickly Renaming Pictures
    ... I have a bunch of photos that have duplicate file names. ... I want to store ... Is there an auto-renaming function in XP? ...
    (microsoft.public.windowsxp.general)