简体   繁体   中英

Recursively rename directory in reverse order, Bash script

How do I recursively rename a directory structure? Something like Batch rename directories in reverse order

But a simple one liner??

My attempt to do this went futile, Here is the command I tried anyway.

du . | cut -f 2- | sh -c 'mv "$0" echo `date "+%H%M%S%N"` ' {} \;

Using CentOS 6

You seem to be trying to use find -exec syntax without actually using find . Use find with its -depth option to make it return directories from deepest to closest.

find . -depth -type d ! -name '.' -exec sh -c 'mv "$0" "$0.$(date "+%H%M%S%N")"' {} \;

这个怎么样:

find /path/to/the/directories/location/ -depth -exec mv '{}' $(basename '{}')$(echo $(date "+%H%M%S%N")) \;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM