[Shell] to obtain multi-level directory file and rename

Suppose / home / a contained under / data / directory multilevel subdirectories, and there are no empty directory; script by renaming the file, directory levels it becomes part of the filename, directory different levels _ interval (Ignore the same name problem).
    Such as: change:
        /home/a/data/aaa/a.txt /home/a/data/aaa_a.txt
        /home/a/data/aaa/b.txt /home/a/data/aaa_b.txt
        / Home / A / Data / AAA / CCC / C.txt /home/a/data/aaa_ccc_c.txt
        /home/a/data/bbb/bb.txt /home/a/data/bbb_bb.txt
        / Home / A / data / bbb.txt /home/a/data/bbb.txt

answer:

#!/bin/bash

for e in `find /home/a/data`
do
  mv -f $e /home/a/data/`echo ${e#/home/a/data/}|sed 's/\//_/g'`
done

 

Guess you like

Origin blog.csdn.net/zkq_1986/article/details/92078749