unless you can provide a clear pattern for what you want the files renamed to it will end in tears.
as has already been pointed out by @ondoho your current command moves *everything* named a to the single file, "at your feet" aka $PWD (print working directory) named b
in effect, you have deleted all the matching files apart from the last one that find found.
That was moved to $PWD/b
find's -exec , is handy, I use it quite a bit for basic things
however
Code:
while read file
do
echo \"mv \"${file}\" \"${file%/*}/b\"
done < <(find / -type f -name a)
that will move all files named a to b in the same dir as a was found
it is dumb, It will overwrite existing files
Code:
while read file
do
if [[ ! -e "${file%/*}/b" ]]
then
echo "\"mv \"${file}\" \"${file%/*}/b\""
else
echo "# \"${file%/*}/b\" already exists.. not moving \"${file}\""
fi
done < <(find / -type f -name a)
safer
if b already exists in the same dir as a was found, skip it.
Notice I'm using echo, and I'm escaping some " with \
this is so I can check I will be doing what I want *before* I actually do it
If I were happy with the result I would
sh would then perform the moves
It is easy for me to write those, you may need more experience to write those without error.
I have also not explained what the %/* did
and the little script I have written is redundant
what you probably want is rename
but you are going to need to learn perlexpr
first part of
man rename
Code:
RENAME(1p) User Contributed Perl Documentation RENAME(1p)
NAME
rename - renames multiple files
SYNOPSIS
rename [ -h|-m|-V ] [ -v ] [ -0 ] [ -n ] [ -f ] [ -d ] [ -e|-E perlexpr]*|perlexpr [ files ]
DESCRIPTION
"rename" renames the filenames supplied according to the rule specified as the first argument. The perlexpr
argument is a Perl expression which is expected to modify the $_ string in Perl for at least some of the filenames
specified. If a given filename is not modified by the expression, it will not be renamed. If no filenames are
given on the command line, filenames will be read via standard input.
For example, to rename all files matching "*.bak" to strip the extension, you might say
rename 's/\.bak$//' *.bak
To translate uppercase names to lower, you'd use
rename 'y/A-Z/a-z/' *
tl;dr use rename