On 2020-01-29 16:26, 李亮 wrote:
> Hi,
>
> I executed two commands
>
>
>
> 1
> find /mnt/src -mindepth 3 -maxdepth 3 -type d -exec echo `echo {} | sed
> 's/\/mnt\/src\//&\.\//'` \;
> The output is
> /mnt/src/1001/202001/20200101
> /mnt/src/1001/202001/20200102
> /mnt/src/1001/202001/20200128
>
>
> 2
> find /mnt/src -mindepth 3 -maxdepth 3 -type d -exec echo `echo
> /mnt/src/2001/202001/20200128 | sed 's/\/mnt\/src\//&\.\//'` \;
> The output is
> /mnt/src/./2001/202001/20200128
> /mnt/src/./2001/202001/20200128
> /mnt/src/./2001/202001/20200128
>
>
>
> The second command is the format of the output I want, which I'm not sure is
> a bug or my usage error.
>
> Looking forward to reply.
The problem in example 1 is the use of the backticks `...`: the command between
is executed by the calling shell before 'find' even sees it.
$ echo {} | sed 's/\/mnt\/src\//&\.\//'
{}
This result is then passed as argument to find which then effectively runs like:
$ find /mnt/src -mindepth 3 -maxdepth 3 -type d -exec echo '{}' \;
I'm not 100% sure what you want to achieve with this additional './' (because
it's redundant),
but you probably want something like this?
$ mkdir -pv /mnt/src/1001/202001/20200101 /mnt/src/1001/202001/20200102
/mnt/src/1001/202001/20200128
mkdir: created directory '/mnt/src'
mkdir: created directory '/mnt/src/1001'
mkdir: created directory '/mnt/src/1001/202001'
mkdir: created directory '/mnt/src/1001/202001/20200101'
mkdir: created directory '/mnt/src/1001/202001/20200102'
mkdir: created directory '/mnt/src/1001/202001/20200128'
$ find /mnt/src -mindepth 3 -maxdepth 3 -type d -printf '%H/.%p\n'
/mnt/src/./mnt/src/1001/202001/20200102
/mnt/src/./mnt/src/1001/202001/20200101
/mnt/src/./mnt/src/1001/202001/20200128
Have a nice day,
Berny