Your question, as written, suggests that
you want to search the entire filesystem for Analysis.mzXML files,
even if they appear in /lib/perl5/5.14/Unicode/Collate/Locale,
/proc/sys/net/ipv4/conf/all, /sys/devices/system/cpu/cpu0/cache,
/usr/share/doc/cmake/html/_sources,
or similarly unlikely / inappropriate places —
and that you want to move the files into the root directory,
which also seems unlikely / inappropriate.
I assumed that you are working from some other directory.
Run this command:
find . -mindepth 7 -maxdepth 7 -type f -name Analysis.mzXML -exec sh -c 'for arg do echo mv -i -- "$arg" "$(echo "$arg" | sed -e "s|^\./||" -e "s|/dir6/Analysis\.mzXML|.mzXML|" -e "s|/|_|g")"; done' sh {} +
You can leave out the -mindepth 7 -maxdepth 7
if you’re sure that all the Analysis.mzXML files are at the seventh level.
This command finds all Analysis.mzXML files at the seventh level
and passes them to a mini-shell script.
That takes each pathname, strips off the ./ at the beginning
and the dir6 at the end, along with the Analysis part of the filename,
and changes all the remaining / characters to _.
This should produce an output something like this:
mv -i -- ./dir1/dir2/dir3/dir4/dir5/dir6/Analysis.mzXML dir1_dir2_dir3_dir4_dir5.mzXML
mv -i -- ./the/quick/brown/fox/jumps/dir6/Analysis.mzXML the_quick_brown_fox_jumps.mzXML
mv -i -- ./over/the/lazy/dog/foo bar/dir6/Analysis.mzXML over_the_lazy_dog_foo bar.mzXML
If this looks right, run the command again,
but delete the first echo (i.e., change echo mv to just mv).
Notes:
- This doesn’t verify that
the sixth level directory is actually called
dir6.
If it finds an Analysis.mzXML file
in dir11/dir12/dir13/dir14/dir15/dir16, it will rename that file
to dir11_dir12_dir13_dir14_dir15_dir16_Analysis.mzXML
rather than dir11_dir12_dir13_dir14_dir15.mzXML.
- The
-i will cause mv to ask for confirmation
if it tries to move a file to a name that already exists.
- The
-- should protect you against arguments that begin with -.
This shouldn’t be an issue, since $arg should always begin with ./.
- If you really want to do this from the filesystem root, that should work.
Just
cd / and follow the above instructions.
Afterthought:
This might fail if you have a directory named Analysis.mzXML.
So don’t do that.