Re: Learning Bash Questions: the MV command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux